|
|
|
@ -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),
|
|
|
|
|
"}",
|
|
|
|
|