// Implementation for cached computation of weighted output // (used by smoothing) public double GetWeightedOutput() { if (!double.IsNaN(_weightedOutput)) { return(_weightedOutput); } if (NodeIndex < 0) { return(Tree.GetOutput(~NodeIndex)); } int lteDocCount = LteNode.GetDocumentCount(); int gtCount = GtNode.GetDocumentCount(); _weightedOutput = (lteDocCount * LteNode.GetWeightedOutput() + gtCount * GtNode.GetWeightedOutput()) / (lteDocCount + gtCount); return(_weightedOutput); }
/// <summary> /// Regularize a regression tree with smoothing paramter alpha. /// </summary> protected virtual void SmoothTree(InternalRegressionTree tree, double smoothing) { if (smoothing == 0.0) { return; } //Create recursive structure of the tree starting from root node var regularizer = new RecursiveRegressionTree(tree, TreeLearner.Partitioning, 0); //Perform bottom-up computation of weighted interior node output double rootNodeOutput = regularizer.GetWeightedOutput(); //followed by top-down propagation of parent's output value regularizer.SmoothLeafOutputs(rootNodeOutput, smoothing); }