Information Gain.
    
    The uncertainty of the starting node, minus the weighted impurity of
    two child nodes.
355365
def info_gain(current_impurity, true_branch, false_branch, criterion):
    

    measure_impurity = gini_impurity if criterion == "gini" else entropy
    p = float(len(true_branch)) / (len(true_branch) + len(false_branch))
    
    return current_impurity - p * measure_impurity(true_branch) - (1 - p) * measure_impurity(false_branch)
768847
def assignment(self, node, children):
        ''
        lvalue, _, expr = children
        self.env[lvalue] = expr
        return expr
316582
def _cmp(self, other):
        """"""
        self_gen  = traverse_frozen_data(self.payload)
        other_gen = traverse_frozen_data(other.payload)
        while True:
            try:
                self_node  = repr(next(self_gen))
            except StopIteration:
                self_node  = None
            try:
                other_node = repr(next(other_gen))
            except StopIteration:
                other_node = None
            if self_node is None or other_node is None:
                # We iterated to the end
                if self_node is not None:
                    return 1
                if other_node is not None:
                    return -1
                return 0
            if self_node != other_node:
                return (
                    self_node > other_node
                ) - (
                    self_node < other_node
                )
112721
private void initializeNetwork()
	{
		this.hiddenLayerSize = this.hiddenLayerOption.getValue();
		this.learningRate = this.learningRateOption.getValue();
		this.threshold = this.thresholdOption.getValue();
		double[][] randomWeightsOne = new double[this.hiddenLayerSize][this.numAttributes];
		double[][] randomWeightsTwo = new double[this.numAttributes][this.hiddenLayerSize];
		
		for(int i = 0 ; i < this.numAttributes ; i++)
		{
			for(int j = 0 ; j < this.hiddenLayerSize ; j++)
			{
				randomWeightsOne[j][i] = this.classifierRandom.nextDouble();
				randomWeightsTwo[i][j] = this.classifierRandom.nextDouble();
			}
		}
		
		this.weightsOne = new Array2DRowRealMatrix(randomWeightsOne);
		this.weightsTwo = new Array2DRowRealMatrix(randomWeightsTwo);
		this.biasOne = this.classifierRandom.nextDouble();
		this.biasTwo = this.classifierRandom.nextDouble();
		
		this.reset = false;
	}
999302
function evaluateCoefficientSum(node) {
  // the node is now always a * node with the left child the coefficent sum
  // e.g. (2 + 4 + 5) and the right node the symbol part e.g. x or y^2
  // so we want to evaluate args[0]
  const coefficientSum = clone(node).args[0];
  const childStatus = evaluateConstantSum(coefficientSum);
  return Node.Status.childChanged(node, childStatus, 0);
}
1262252
function Node(key, value) {
  this.key = key;
  this.value = value;
  this.degree = 0;
  this.parent = undefined;
  this.child = undefined;
  this.sibling = undefined;
}
197986
def smoothEstimate(self, nodeShape, estimatedNodeCount):
        
        weightedEstimate = (1 - self.betaInertia) * estimatedNodeCount + \
                           self.betaInertia * self.previousWeightedEstimate[nodeShape]
        self.previousWeightedEstimate[nodeShape] = weightedEstimate
        return self._round(weightedEstimate)
858043
def uncertainty_pi(self):
        
        if self.information_ is None:
            self._build_information()

        sigma_pi = _ratematrix.sigma_pi(
            self.information_, theta=self.theta_, n=self.n_states_)
        return sigma_pi
606478
def get_gain(self, attr_name):
        
        subset_entropy = 0.0
        for value in iterkeys(self._attr_value_counts[attr_name]):
            value_prob = self.get_value_prob(attr_name, value)
            e = self.get_entropy(attr_name, value)
            subset_entropy += value_prob * e
        return (self.main_entropy - subset_entropy)
397930
private void ensureAvail(int n) {
    if (pos + n >= buf.length) {
      int newSize = Math.max(pos + n, buf.length * 2);
      buf = Arrays.copyOf(buf, newSize);
    }
  }
1015058
function nodeValue(node1, node2) {
    return (node1.dist + heuristic(node1.point)) - (node2.dist + heuristic(node2.point));
  }
456926
function altersingle(alpha, i, b, g, r) {
    network[i][0] -= (alpha * (network[i][0] - b)) / initalpha;
    network[i][1] -= (alpha * (network[i][1] - g)) / initalpha;
    network[i][2] -= (alpha * (network[i][2] - r)) / initalpha;
  }
1183511
function(parentNode) {
        if (parentNode && parentNode.children) {
            for (var i=0, len=parentNode.children.length; i<len ; ++i) {
                if (parentNode.children[i] === this) {
                    return i;
                }
            }
        }

        return -1;
    }
657676
private static void updateSoftEvidenceAuxiliaryNodeCPT(Network bn,
            String targetNodeName, HashMap<String, Double> softEvidence)
            throws ShanksException {

        int targetNode = bn.getNode(targetNodeName);
        int auxNode = bn.getNode(softEvidenceNodePrefix + targetNodeName);

        // Check if new beliefs join 1
        double total = 0;
        for (Entry<String, Double> entry : softEvidence.entrySet()) {
            total += entry.getValue();
        }
        double aux = 1 - total;
        if (aux < (-0.05) || aux > 0.05) {
            throw new ShanksException(
                    "Impossible to set soft-evidence in node: "
                            + targetNodeName
                            + " Target probabilistic distribution is not consistent. All states joint: "
                            + total);
        }

        // Check if believes are consistent
        if (bn.getOutcomeCount(targetNodeName) != softEvidence.size()) {
            throw new ShanksException(
                    "Old belief and new belief are incompatible. Different number of states of hypothesis");
        }

        for (String status : softEvidence.keySet()) {
            boolean found = false;
            String[] outcomes = bn.getOutcomeIds(targetNode);
            for (int i = 0; i < outcomes.length; i++) {
                if (outcomes[i].equals(status)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new ShanksException(
                        "Not valid Belief, exist unconsistent between current and old believes.");
            }
        }

        // Now, when the consistent has been checked
        // Update the belief

        // Reset evidence.
        ShanksAgentBayesianReasoningCapability.clearEvidence(bn,
                bn.getNodeName(auxNode));

        // Obtain required data
        int size = bn.getOutcomeCount(targetNodeName);
        double[] currentProbabilities = new double[size];
        double[] newProbabilities = new double[size];
        String[] states = bn.getOutcomeIds(targetNodeName);
        bn.updateBeliefs();
        double[] values = bn.getNodeValue(targetNodeName);
        for (int i = 0; i < size; i++) {
            for (String status : softEvidence.keySet()) {
                if (states[i].equals(status)) {
                    currentProbabilities[i] = values[i];
                    newProbabilities[i] = softEvidence.get(status);
                    break;
                }
            }
        }

        // Build the new CPT
        double auxNumber = new Float(0.1);
        double[] cptProbabilitiesPrime = new double[currentProbabilities.length];
        for (int i = 0; i < currentProbabilities.length; i++) {
            cptProbabilitiesPrime[i] = 0.5;
            if (currentProbabilities[i] != 0.0) {
                cptProbabilitiesPrime[i] = newProbabilities[i] * auxNumber
                        / currentProbabilities[i];
            } else if (newProbabilities[i] != 0.0) {
                // If there is a full confidence (i.e. 0.0 probability, you must
                // not request a belief
                // It is impossible that a change in a full confidence (100% or
                // 0%)
                // If this occurs, the BN is wrong fixed (CPT's are wrong)
                throw new ShanksException(
                        "Incoherence! Belief does not update. Probability for status: "
                                + targetNodeName + " is ficked as evidence!!");
            }
            if (cptProbabilitiesPrime[i] > 1) {
                // In this case, reduce auxNumber and rebuild CPT probabilities.
                auxNumber = auxNumber / 2;
                i = -1;
            }
        }

        // Update the CPT and the Inference Engine
        // TODO check this
        double[] cpt = new double[bn.getNodeDefinition(auxNode).length];
        for (int i = 0; i < currentProbabilities.length; i++) {
            cpt[2 * i] = cptProbabilitiesPrime[i];
            cpt[1 + (2 * i)] = (1 - cptProbabilitiesPrime[i]);
        }
        bn.setNodeDefinition(softEvidenceNodePrefix + targetNodeName, cpt);

        // Compiling new network
        // Map<String, String> currentEvidences =
        // ShanksAgentBayesianReasoningCapability
        // .getEvidences(bn);
        // ShanksAgentBayesianReasoningCapability.clearEvidences(bn);
        // ShanksAgentBayesianReasoningCapability.addEvidences(bn,
        // currentEvidences);

        // Testing CPT

        // ShanksAgentBayesianReasoningCapability.addEvidence(bn,
        // softEvidenceNodePrefix + targetNodeName, triggerState);
        // double conf =
        // ShanksAgentBayesianReasoningCapability.getHypothesis(bn,
        // softEvidenceNodePrefix + targetNodeName, triggerState);
        // if (Math.abs(conf - 1) > 0.01) {
        // throw new ShanksException(
        // "Error adding finding to soft-evidence node for node: "
        // + targetNodeName
        // + " It should be equals to 1, but it is: " + conf);
        // }
        // ShanksAgentBayesianReasoningCapability.clearEvidence(bn, auxNode);
    }
148802
def PartialDynamicSystem(self, ieq, variable):
        
        if ieq == 0:
            # U1=0
            if variable == self.physical_nodes[0].variable:
                v = Step('Ground', 0)
                return[Gain(v, variable, 1)]
101146
def uncertainty_K(self):
        
        if self.information_ is None:
            self._build_information()

        sigma_K = _ratematrix.sigma_K(
            self.information_, theta=self.theta_, n=self.n_states_)
        return sigma_K
92052
public void addEdge(N a, N b)
    {
        if( !containsBoth(a, b) )
            return;//Cant add nodes to things that doing exist
        nodes.get(a).getOutgoing().add(b);
        nodes.get(b).getIncoming().add(a);
    }