public function grouped_distribution() { /* Returns a distribution formed by grouping the distributions of each predicted node. */ $joined_distribution = array(); $distribution_unit = 'counts'; foreach ($this->predictions as $prediction) { $joined_distribution = merge_distributions($joined_distribution, array($prediction['distribution'][0], $prediction['distribution'][1])); uasort($joined_distribution, array($this, "sort_joined_distribution_items")); $distribution = array(); foreach ($joined_distribution as $dis) { array_push($distribution, array($dis)); } if ($distribution_unit == 'counts') { if (count($distribution) > MultiVote::BINS_LIMIT) { $distribution_unit = 'bins'; } else { $distribution_unit = 'counts'; } } $distribution = merge_bins($distribution, MultiVote::BINS_LIMIT); } return array("distribution" => $distribution, "distribution_unit" => $distribution_unit); }
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) { $a = array(); foreach ($this->distribution as $x) { $a[strval($x[0])] = $x[1]; } return array(merge_distributions(array(), $a), $this->min, $this->max, $this); } if (one_branch($this->children, $input_data)) { 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(); 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]; if ($subtree_min != null) { array_push($minimus, $subtree_min); } if ($subtree_max != null) { array_push($maximus, $subtree_max); } $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); } }