示例#1
0
 public function predict($input_data, $path = null, $missing_strategy = Tree::LAST_PREDICTION)
 {
     /*
        Makes a prediction based on a number of field values.
        The input fields must be keyed by Id. There are two possible
          strategies to predict when the value for the splitting field
          is missing:
        0 - LAST_PREDICTION: the last issued prediction is returned.
        1 - PROPORTIONAL: as we cannot choose between the two branches
           in the tree that stem from this split, we consider both. The
           algorithm goes on until the final leaves are reached and
           all their predictions are used to decide the final prediction.
     */
     if ($path == null) {
         $path = array();
     }
     if ($missing_strategy == Tree::PROPORTIONAL) {
         $predict_pro = $this->predict_proportional($input_data, $path);
         $final_distribution = $predict_pro[0];
         $d_min = $predict_pro[1];
         $d_max = $predict_pro[2];
         $last_node = $predict_pro[3];
         $distribution = array();
         if ($this->regression) {
             // singular case
             // when the prediction is the one given in a 1-instance node
             if (count($final_distribution) == 1) {
                 foreach ($final_distribution as $prediction => $instances) {
                     if ($instances == 1) {
                         return new Prediction($last_node->output, $path, $last_node->confidence, $last_node->distribution, $instances, $last_node->distribution_unit, $last_node->median, $last_node->children, $last_node->min, $last_node->max);
                     }
                     break;
                 }
             }
             ksort($final_distribution);
             foreach ($final_distribution as $key => $val) {
                 array_push($distribution, array(floatval($key), $val));
             }
             $distribution_unit = 'counts';
             if (count($distribution) > Tree::BINS_LIMIT) {
                 $distribution_unit = 'bins';
             }
             $distribution = merge_bins($distribution, Tree::BINS_LIMIT);
             $prediction = mean($distribution);
             $total_instances = 0;
             foreach ($distribution as $key => $val) {
                 $total_instances += $val[1];
             }
             $confidence = regression_error(unbiased_sample_variance($distribution, $prediction), $total_instances);
             return new Prediction($prediction, $path, $confidence, $distribution, $total_instances, $distribution_unit, dist_median($distribution, $total_instances), $last_node->children, $d_min, $d_max);
         } else {
             ksort($final_distribution);
             $distribution = array();
             foreach ($final_distribution as $key => $val) {
                 array_push($distribution, array($key, $val));
             }
             return new Prediction($distribution[0][0], $path, ws_confidence($distribution[0][0], $final_distribution), $distribution, get_instances($distribution), 'categorial', null, $last_node->children, null, null);
         }
     } else {
         if ($this->children != null) {
             #&&  array_key_exists(splitChildren($this->children), $input_data) ) {
             foreach ($this->children as $child) {
                 if ($child->predicate->apply($input_data, $this->fields)) {
                     $new_rule = $child->predicate->to_rule($this->fields);
                     array_push($path, $new_rule);
                     return $child->predict($input_data, $path);
                 }
             }
         }
         return new Prediction($this->output, $path, $this->confidence, $this->distribution, get_instances($this->distribution), $this->distribution_unit, $this->regression == null ? null : $this->median, $this->children, $this->regression == null ? null : $this->min, $this->regression == null ? null : $this->max);
     }
 }
示例#2
0
function make_awsstat_summary($preloading = false)
{
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, _('Account name'), _('PoweredOn'), _('PoweredOff'), _('Billing/Month')));
    $script_itemkey = 'push_message.py[{$HYCLOPS_SERVER},{$HYCLOPS_PORT},ec2,{HOST.HOST}]';
    $aws_accounts = get_aws_accounts();
    if (empty($aws_accounts)) {
        return null;
    }
    foreach ($aws_accounts as $host) {
        if (!$preloading) {
            if (is_script_success($host['hostid'], $script_itemkey)) {
                $instances = get_instances($host['hostid']);
                $instances = filter_instances($instances);
                $r = new CRow();
                // Account name
                $col = new CCol($host['host']);
                $r->addItem($col);
                // Poweron (running + pending)
                $poweron_vms = array_merge($instances["running"], $instances["pending"]);
                $poweron_count = new CSpan(count($poweron_vms), 'pointer');
                if (!empty($poweron_vms)) {
                    $poweron_count->setHint(make_ec2_table('ec2_poweron', $poweron_vms));
                }
                $r->addItem(new CCol($poweron_count));
                // Poweroff (stopped + terminated + stopping + shutting-down)
                $poweroff_vms = $instances["stopped"];
                $poweroff_count = new CSpan(count($poweroff_vms), 'pointer');
                if (!empty($poweroff_vms)) {
                    $poweroff_count->setHint(make_ec2_table('ec2_poweroff', $poweroff_vms));
                }
                $r->addItem(new CCol($poweroff_count));
                // AWS Charges
                $item = get_item_by_key('get_aws_charges.py[{$KEY},{$SECRET}]', $host["host"]);
                if (array_key_exists('lastvalue', $item)) {
                    $r->addItem(new CLink($item["lastvalue"], "history.php?action=showgraph&itemid={$item["itemid"]}"));
                } else {
                    $r->addItem(new CCol(_('No data')));
                }
                $table->addRow($r);
                zbx_add_post_js('chkbxRange.pageGoName = "vms";');
            } else {
                $r = new CRow();
                $r->addItem($host['host']);
                $r->addItem(new CCol(_('script failed'), "high"));
                $r->addItem(array("-"));
                $table->addRow($r);
            }
        } else {
            $r = new CRow();
            $r->addItem($host['host']);
            $r->addItem(new CCol(_('loading...')));
            $r->addItem(array("-"));
            $table->addRow($r);
        }
    }
    $script = new CJSScript(get_js("jQuery('#hat_awsstat_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')"));
    return new CDiv(array($table, $script));
}