Upated tree encoder.

main
Gijs 3 years ago
parent 9ee8b07225
commit e0d77a1182

@ -19,14 +19,17 @@ def encode_branch(branch):
def encode_tree(tree):
lines = [
"print(\"Considering feature {index}, is it smaller than {threshold}?\");".format(index=tree['index'], threshold=tree['value']),
"// timeout code",
"(clearScreen)();",
"(printLine)(\"Considering feature {index}, is it smaller than {threshold}?\");".format(index=tree['index'], threshold=tree['value']),
"(delay)(1500);",
"if (r[{index}] < {threshold}) {{".format(index=tree['index'], threshold=tree['value']),
indent_line("print(\"Yes\");"),
indent_line("(printLine)(\"Yes\");"),
indent_line("(delay)(1500);"),
*encode_branch(tree['left']),
"}",
"else {",
indent_line("print(\"No\");"),
indent_line("(printLine)(\"No\");"),
indent_line("(delay)(1500);"),
*encode_branch(tree['right']),
"}"
]
@ -48,7 +51,7 @@ def make_classifier (tree):
"{",
"public:",
*map(indent_line, [
"char* predict(float *r)",
"char* predict(float *r, void (*printLine)(char *), void (*clearScreen)(), void (*delay)(int))",
"{",
*encode_tree(tree),
"}",

Loading…
Cancel
Save