Computes a score that measures how much a \
        given variable is \"influenced\" by a given list of potential parents.
510400
def local_score(self, variable, parents):
        ""

        var_states = self.state_names[variable]
        var_cardinality = len(var_states)
        state_counts = self.state_counts(variable, parents)
        sample_size = len(self.data)
        num_parents_states = float(len(state_counts.columns))

        score = 0
        for parents_state in state_counts:  # iterate over df columns (only 1 if no parents)
            conditional_sample_size = sum(state_counts[parents_state])

            for state in var_states:
                if state_counts[parents_state][state] > 0:
                    score += state_counts[parents_state][state] * (log(state_counts[parents_state][state]) -
                                                                   log(conditional_sample_size))

        score -= 0.5 * log(sample_size) * num_parents_states * (var_cardinality - 1)

        return score
342073
public double getMetric(int id, int classLabel) {
    try {
      switch (id) {
        case DefaultEvaluationMetrics.EVALUATION_CC:
          return m_Evaluation.correlationCoefficient();
        case DefaultEvaluationMetrics.EVALUATION_MATTHEWS_CC:
          return m_Evaluation.matthewsCorrelationCoefficient(0);
        case DefaultEvaluationMetrics.EVALUATION_RMSE:
          return m_Evaluation.rootMeanSquaredError();
        case DefaultEvaluationMetrics.EVALUATION_RRSE:
          return m_Evaluation.rootRelativeSquaredError();
        case DefaultEvaluationMetrics.EVALUATION_MAE:
          return m_Evaluation.meanAbsoluteError();
        case DefaultEvaluationMetrics.EVALUATION_RAE:
          return m_Evaluation.relativeAbsoluteError();
        case DefaultEvaluationMetrics.EVALUATION_COMBINED:
          return (1 - StrictMath.abs(m_Evaluation.correlationCoefficient()) + m_Evaluation.rootRelativeSquaredError() + m_Evaluation.relativeAbsoluteError());
        case DefaultEvaluationMetrics.EVALUATION_ACC:
          return m_Evaluation.pctCorrect();
        case DefaultEvaluationMetrics.EVALUATION_KAPPA:
          return m_Evaluation.kappa();
        case DefaultEvaluationMetrics.EVALUATION_PRECISION:
          return m_Evaluation.precision(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_WEIGHTED_PRECISION:
          return m_Evaluation.weightedPrecision();
        case DefaultEvaluationMetrics.EVALUATION_RECALL:
          return m_Evaluation.recall(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_WEIGHTED_RECALL:
          return m_Evaluation.weightedRecall();
        case DefaultEvaluationMetrics.EVALUATION_AUC:
          return m_Evaluation.areaUnderROC(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_WEIGHTED_AUC:
          return m_Evaluation.weightedAreaUnderROC();
        case DefaultEvaluationMetrics.EVALUATION_PRC:
          return m_Evaluation.areaUnderPRC(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_WEIGHTED_PRC:
          return m_Evaluation.weightedAreaUnderPRC();
        case DefaultEvaluationMetrics.EVALUATION_FMEASURE:
          return m_Evaluation.fMeasure(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_WEIGHTED_FMEASURE:
          return m_Evaluation.weightedFMeasure();
        case DefaultEvaluationMetrics.EVALUATION_TRUE_POSITIVE_RATE:
          return m_Evaluation.truePositiveRate(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_TRUE_NEGATIVE_RATE:
          return m_Evaluation.trueNegativeRate(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_FALSE_POSITIVE_RATE:
          return m_Evaluation.falsePositiveRate(classLabel);
        case DefaultEvaluationMetrics.EVALUATION_FALSE_NEGATIVE_RATE:
          return m_Evaluation.falseNegativeRate(classLabel);
        default:
          return Double.NaN;
      }
    }
    catch (Exception e) {
      return Double.NaN;
    }
  }
1237280
def calc_pvalue(self, study_count, study_n, pop_count, pop_n):
        """"""
        # http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.stats.fisher_exact.html
        #
        #         Atlantic  Indian                              YES       NO
        # whales     8        2    | 10 whales    study_genes    8 scnt   2    | 10 = study_n
        # sharks     1        5    |  6 sharks    not s_genes    1        5    |  6
        #         --------  ------                            --------   -----
        #            9        7      16 = pop_n     pop_genes    9 pcnt   7      16 = pop_n
        #
        # We use the preceeding table to find the p-value for whales/sharks:
        #
        # >>> import scipy.stats as stats
        # >>> oddsratio, pvalue = stats.fisher_exact([[8, 2], [1, 5]])
        #                                              a  b    c  d
        avar = study_count
        bvar = study_n - study_count
        cvar = pop_count - study_count
        dvar = pop_n - pop_count - bvar
        assert cvar >= 0, self.fmterr.format(
            A=avar, B=bvar, C=cvar, D=dvar, scnt=study_count, stot=study_n, pcnt=pop_count, ptot=pop_n)
        # stats.fisher_exact returns oddsratio, pval_uncorrected
        _, p_uncorrected = self.pval_fnc([[avar, bvar], [cvar, dvar]])
        return p_uncorrected
1049694
def no_missing_parents(data_wrapper):
    '''
    '''
    db = data_wrapper.data_block
    ids = np.setdiff1d(db[:, COLS.P], db[:, COLS.ID])[1:]
    return CheckResult(len(ids) == 0, ids.astype(np.int) + 1)
563659
private void computeIv(long label, long index) {
		long key_id;

		if (keyDerivationRate == 0) {
			key_id = label << 48;
		} else {
			key_id = ((label << 48) | (index / keyDerivationRate));
		}
		for (int i = 0; i < 7; i++) {
			ivStore[i] = masterSalt[i];
		}
		for (int i = 7; i < 14; i++) {
			ivStore[i] = (byte) ((byte) (0xFF & (key_id >> (8 * (13 - i)))) ^ masterSalt[i]);
		}
		ivStore[14] = ivStore[15] = 0;
	}
164569
def get_addition_score(source_counts, prediction_counts, target_counts):
  """"""
  added_to_prediction_counts = prediction_counts - source_counts
  true_positives = sum((added_to_prediction_counts & target_counts).values())
  selected = sum(added_to_prediction_counts.values())
  # Note that in the paper the summation is done over all the ngrams in the
  # output rather than the ngrams in the following set difference. Since the
  # former does not make as much sense we compute the latter, which is also done
  # in the GitHub implementation.
  relevant = sum((target_counts - source_counts).values())
  return _get_fbeta_score(true_positives, selected, relevant)
732840
def _select_parent(action_set):
        """"""
        total_fitness = sum(rule.fitness for rule in action_set)
        selector = random.uniform(0, total_fitness)
        for rule in action_set:
            selector -= rule.fitness
            if selector <= 0:
                return rule
        # If for some reason a case slips through the above loop, perhaps
        # due to floating point error, we fall back on uniform selection.
        return random.choice(list(action_set))
896614
@Override
  public final double[] score0(double[] doubles, double offset, double[] preds) {
    assert(doubles != null) : "doubles are null";
    float[] floats;
    int cats = _catOffsets == null ? 0 : _catOffsets[_cats];
    if (_nums > 0) {
      floats = new float[_nums + cats]; //TODO: use thread-local storage
      GenModel.setInput(doubles, floats, _nums, _cats, _catOffsets, _normMul, _normSub, _useAllFactorLevels, true);
    } else {
      floats = new float[doubles.length];
      for (int i=0; i<floats.length; ++i) {
        floats[i] = (float) doubles[i] - (_meanImageData == null ? 0 : _meanImageData[i]);
      }
    }
    float[] predFloats = _backend.predict(_model, floats);
    assert(_nclasses == predFloats.length) : "nclasses " + _nclasses + " predFloats.length " + predFloats.length;
    if (_nclasses > 1) {
      for (int i = 0; i < predFloats.length; ++i)
        preds[1 + i] = predFloats[i];
      if (_balanceClasses)
        GenModel.correctProbabilities(preds, _priorClassDistrib, _modelClassDistrib);
      preds[0] = GenModel.getPrediction(preds, _priorClassDistrib, doubles, _defaultThreshold);
    } else {
      if (_normRespMul!=null && _normRespSub!=null)
        preds[0] = predFloats[0] * _normRespMul[0] + _normRespSub[0];
      else
        preds[0] = predFloats[0];
    }
    return preds;
  }
906709
def filter(self, scored_list):
        '''
        

        '''
        if len(scored_list) > 0:
            avg = np.mean([s[1] for s in scored_list])
            std = np.std([s[1] for s in scored_list])
        else:
            avg = 0
            std = 0
        limiter = avg + 0.5 * std
        mean_scored = [(sent_idx, score) for (sent_idx, score) in scored_list if score > limiter]
        return mean_scored
1056182
def score_counts(counts)
      if counts.count > 0
        _num = counts.map { |x| x.obp }
        _num.percentile(90)
      else
        0.01
      end
    end
673781
function score(data, candidate) {
    var result = 0;
    /*
        Scoring calculations here
    */

    //Last Name
    if (!data.name.last || !candidate.name.last) {
        result = result + 0;
    } else if (data.name.last.toUpperCase() === candidate.name.last.toUpperCase()) {
        result = result + 9.58;
    } else if (data.name.last.toUpperCase().substring(0, 3) === candidate.name.last.toUpperCase().substring(0, 3)) {
        result = result + 5.18;
    } else if (data.name.last.toUpperCase().substring(0, 3) !== candidate.name.last.toUpperCase().substring(0, 3)) {
        result = result - 3.62;
    }

    //First Name
    if (!data.name.first || !candidate.name.first) {
        result = result + 0;
    } else if (data.name.first.toUpperCase() === candidate.name.first.toUpperCase()) {
        result = result + 6.69;
    } else if (data.name.first.toUpperCase().substring(0, 3) === candidate.name.first.toUpperCase().substring(0, 3)) {
        result = result + 3.37;
    } else if (data.name.first.toUpperCase().substring(0, 3) !== candidate.name.first.toUpperCase().substring(0, 3)) {
        result = result - 3.27;
    }

    //Middle Initial
    if (!data.name.middle || !candidate.name.middle) {
        result = result + 0;
    } else if (data.name.middle.toUpperCase().substring(0, 1) === candidate.name.middle.toUpperCase().substring(0, 1)) {
        result = result + 3.65;
    }

    //DOB
    if (!data.dob || !candidate.dob) {
        result = result + 0;
    } else if (data.dob.substring(0, 10) === candidate.dob.substring(0, 10)) {
        result = result + 6.22;
    }

    //Initials
    result = result + 0;

    return result;
}
1320649
def _scoring(self, net, X_test, y_test):
        """"""
        scorer = check_scoring(net, self.scoring_)
        scores = _score(
            estimator=net,
            X_test=X_test,
            y_test=y_test,
            scorer=scorer,
            is_multimetric=False,
        )
        return scores
467917
def calc_scores_for_node(G, node, depth_limit=22,
                         number_of_recommendations=None, impact_mode=10):
    """"""
    n, w, dep, _ = dfs_edges(G, node, depth_limit, "Record")
    count_total_ways = len(n)
    # print "Number of paths {}".format(len(n))
    if impact_mode == 0:
        impact_div = 12
    elif impact_mode == 1:
        impact_div = 1000
    elif impact_mode == 2:
        impact_div = 100
    elif impact_mode == 10:
        impact_div = count_total_ways
    elif impact_mode == 11:
        impact_div = count_total_ways/2

    d_ = {'Nodes': n, 'Scores': w, 'Depth': dep}
    d = pd.DataFrame(data=d_)
    del n, w, dep, d_
    n, w, dep = None, None, None
    gc.collect()

    nodes = array('I')
    weight_high = array('f')
    weight_new = array('f')
    ways = array('I')
    nodes_with_weight = d.groupby('Nodes')

    del d
    gc.collect()
    # print "Number nodes {}".format(len(nodes_with_weight))
    for node, end_nodes in nodes_with_weight:
        nodes.append(node)
        new_score, highest_score, number_of_paths = \
            calc_weight_of_multiple_paths(end_nodes, impact_div)
        weight_high.append(highest_score)
        weight_new.append(new_score)
        ways.append(number_of_paths)

    new_weights_d = {'Node': nodes, 'Score_Highest': weight_high,
                     'Score': weight_new, 'Paths': ways}
    new_weights = pd.DataFrame(data=new_weights_d)
    del new_weights_d, nodes, weight_high, weight_new, ways
    gc.collect()
    # Numpy sort by score
    new_weights = new_weights.sort_values(by='Score', ascending=False)
    new_weights = new_weights[:number_of_recommendations]

    return new_weights
1136242
def _parent_value(children):
    # type: (...) -> int
    
    covers = np.array([child['cover'] for child in children])
    covers /= np.sum(covers)
    leafs = np.array([child['leaf'] for child in children])
    return np.sum(leafs * covers)
1086993
public double score(List<L> guesses, List<L> trueLabels) {
    clearCounts();
    addGuesses(guesses, trueLabels);
    finalizeCounts();
    return getFMeasure();
  }
895100
private function calculate()
    {
        /**
         * Base score
         */
        $impactSubScore = 0;
        $impactSubScoreBase = 1 - ((1 - $this->vectorLevels['C']) * (1 - $this->vectorLevels['I']) * (1 - $this->vectorLevels['A']));
        switch ($this->vectorInputs['S']) {
            case 'U':
                $impactSubScore = $this->vectorLevels['S'] * $impactSubScoreBase;
                break;
            case 'C':
                $impactSubScore = $this->vectorLevels['S'] * ($impactSubScoreBase - 0.029) - 3.25 * pow(($impactSubScoreBase - 0.02), 15);
                break;
        }

        $exploitabilitySubScore = self::$exploitabilityCoefficient * $this->vectorLevels['AV'] * $this->vectorLevels['AC'] * $this->vectorLevels['PR'] * $this->vectorLevels['UI'];

        if ($impactSubScore <= 0) {
            $this->baseScore = 0;
        }
        else {
            switch ($this->vectorInputs['S']) {
                case 'U':
                    $this->baseScore = self::roundUp(min($impactSubScore + $exploitabilitySubScore, 10));
                    break;
                case 'C':
                    $this->baseScore = self::roundUp(min(self::$scopeCoefficient * ($impactSubScore + $exploitabilitySubScore), 10));
                    break;
            }
        }

        /**
         * Temporal score
         */
        $this->temporalScore = self::roundUp($this->baseScore * $this->vectorLevels['E'] * $this->vectorLevels['RL'] * $this->vectorLevels['RC']);

        /**
         * Environmental score
         */
        $modifiedImpactSubScore = 0;
        $modifiedImpactSubScoreBase = min(1 - ((1 - $this->vectorLevels['MC'] * $this->vectorLevels['CR']) * (1 - $this->vectorLevels['MI'] * $this->vectorLevels['IR']) * (1 - $this->vectorLevels['MA'] * $this->vectorLevels['AR'])), 0.915);
        $modifiedScope = isset($this->vectorInputs['MS']) && $this->vectorInputs['MS'] != 'X' ? $this->vectorInputs['MS'] : $this->vectorInputs['S'];
        switch ($modifiedScope) {
            case 'U':
                $modifiedImpactSubScore = $this->vectorLevels['MS'] * $modifiedImpactSubScoreBase;
                break;
            case 'C':
                $modifiedImpactSubScore = $this->vectorLevels['MS'] * ($modifiedImpactSubScoreBase - 0.029) - 3.25 * pow(($modifiedImpactSubScoreBase - 0.02), 15);
                break;
        }

        $modifiedExploitabilitySubScore = self::$exploitabilityCoefficient * $this->vectorLevels['MAV'] * $this->vectorLevels['MAC'] * $this->vectorLevels['MPR'] * $this->vectorLevels['MUI'];

        if ($modifiedImpactSubScore <= 0) {
            $this->environmentalScore = $this->baseScore;
        }
        else {
            switch ($modifiedScope) {
                case 'U':
                    $this->environmentalScore = self::roundUp(self::roundUp(min($modifiedImpactSubScore + $modifiedExploitabilitySubScore, 10)) * $this->vectorLevels['E'] * $this->vectorLevels['RL'] * $this->vectorLevels['RC']);
                    break;
                case 'C':
                    $this->environmentalScore = self::roundUp(self::roundUp(min(self::$scopeCoefficient * ($modifiedImpactSubScore + $modifiedExploitabilitySubScore), 10)) * $this->vectorLevels['E'] * $this->vectorLevels['RL'] * $this->vectorLevels['RC']);
                    break;
            }
        }
    }
215504
def get_keep_score(source_counts, prediction_counts, target_counts):
  """"""
  source_and_prediction_counts = source_counts & prediction_counts
  source_and_target_counts = source_counts & target_counts
  true_positives = sum((source_and_prediction_counts &
                        source_and_target_counts).values())
  selected = sum(source_and_prediction_counts.values())
  relevant = sum(source_and_target_counts.values())
  return _get_fbeta_score(true_positives, selected, relevant)