Exemple #1
0
function one_branch($children, $input_data)
{
    /*
    Check if there's only one branch to be followed
    */
    $missing = array_key_exists(splitChildren($children), $input_data);
    return $missing || missing_branch($children) || null_value($children);
}
Exemple #2
0
 function predict_proportional($input_data, $path = null, $missing_found = false, $median = false)
 {
     /*
        Makes a prediction based on a number of field values averaging
        the predictions of the leaves that fall in a subtree.
     
        Each time a splitting field has no value assigned, we consider
        both branches of the split to be true, merging their predictions.
        The function returns the merged distribution and the
        last node reached by a unique path.
     */
     if ($path == null) {
         $path == array();
     }
     $final_distribution = array();
     if ($this->children == null) {
         $distribution = !$this->weighted ? $this->distribution : $this->weighted_distribution;
         $a = array();
         foreach ($distribution as $x) {
             $a[strval($x[0])] = $x[1];
         }
         return array(merge_distributions(array(), $a), $this->min, $this->max, $this, $this->count);
     }
     if (one_branch($this->children, $input_data) || in_array($this->fields->{splitChildren($this->children)}->optype, array("text", "items"))) {
         foreach ($this->children as $child) {
             $predicate = $child->predicate;
             if ($predicate->apply($input_data, $this->fields)) {
                 $new_rule = $predicate->to_rule($this->fields);
                 if (!in_array($new_rule, $path) && !$missing_found) {
                     array_push($path, $new_rule);
                 }
                 return $child->predict_proportional($input_data, $path, $missing_found, $median);
             }
         }
     } else {
         $missing_found = true;
         $minimus = array();
         $maximus = array();
         $population = 0;
         foreach ($this->children as $child) {
             $predict_pro = $child->predict_proportional($input_data, $path, $missing_found, $median);
             $subtree_distribution = $predict_pro[0];
             $subtree_min = $predict_pro[1];
             $subtree_max = $predict_pro[2];
             $subtree_pop = $predict_pro[4];
             if ($subtree_min != null) {
                 array_push($minimus, $subtree_min);
             }
             if ($subtree_max != null) {
                 array_push($maximus, $subtree_max);
             }
             $population += $subtree_pop;
             $final_distribution = merge_distributions($final_distribution, $subtree_distribution);
         }
         $min_value = null;
         $max_value = null;
         if (!empty($minimus)) {
             $min_value = min($minimus);
         }
         if (!empty($maximus)) {
             $max_value = max($maximus);
         }
         return array($final_distribution, $min_value, $max_value, $this, $population);
     }
 }