<?php

class {class_name} {{

    public function __construct($lChilds, $rChilds, $thresholds, $indices, $classes) {{
        $this->lChilds = $lChilds;
        $this->rChilds = $rChilds;
        $this->thresholds = $thresholds;
        $this->indices = $indices;
        $this->classes = $classes;
    }}

    private function findMax($nums) {{
        $index = 0;
        for ($i = 0; $i < count($nums); $i++) {{
            $index = $nums[$i] > $nums[$index] ? $i : $index;
        }}
        return $index;
    }}

    public function {method_name}($features) {{
        $node = (func_num_args() > 1) ? func_get_arg(1) : 0;
        if ($this->thresholds[$node] != -2) {{
            if ($features[$this->indices[$node]] <= $this->thresholds[$node]) {{
                return $this->{method_name}($features, $this->lChilds[$node]);
            }} else {{
                return $this->{method_name}($features, $this->rChilds[$node]);
            }}
        }}
        return $this->findMax($this->classes[$node]);
    }}

}}

if ($argc > 1) {{

    // Features:
    array_shift($argv);
    $features = $argv;

    // Parameters:
    {left_childs}
    {right_childs}
    {thresholds}
    {indices}
    {classes}

    // Prediction:
    $clf = new {class_name}($lChilds, $rChilds, $thresholds, $indices, $classes);
    $prediction = $clf->{method_name}($features);
    fwrite(STDOUT, $prediction);

}}