Tree - import import import i import;...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
import; import; import; import java.util.Scanner; i class TreeNode{ TreeNode left; TreeNode right; int testedFeature; int positiveExamples; int negativeExamples; i public TreeNode(int npos, int nneg) { testedFeature = -1; positiveExamples = npos; negativeExamples = nneg; } public TreeNode() {} p /* Score for the node as in the writeup */ float score(){ return (float) -Math.sqrt(positiveExamples*negativeExamples); } } class Split{ int testedFeature; int positiveExamplesLeft; int negativeExamplesLeft; int positiveExamplesRight; int negativeExamplesRight; float score; f public Split(int test, int posright, int negright, int posleft, int negleft) { testedFeature = test; positiveExamplesLeft = posleft; negativeExamplesLeft = negleft; positiveExamplesRight = posright; negativeExamplesRight = negright; score = computeScore(); } public Split() {} p /* Score for a feature as in the writeup */ float computeScore(){ return (float) (-Math.sqrt(positiveExamplesLeft*negativeExamplesLeft) - Math.sqrt(positiveExamplesRight*negativeExamplesRight)); } } public class Tree { TreeNode root; boolean[] used; int maxDepth; i public Tree(int depth){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
maxDepth = depth; } public void grow(Dataset d){ /* Initialize "used". We rely on Java's convention of initializing booleans to false */ used = new boolean[d.numberOfFeatures()]; /* Count the number of positive and negative examples */ int pos = 0; int neg = 0; for(int i=0; i<d.numberOfExamples(); i++){ if (d.getTarget(i) > 0.5f) pos+=1; else neg+=1; } root = new TreeNode(pos,neg); growRecursive(root, d, 0);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/05/2011 for the course CS 2110 taught by Professor Francis during the Spring '07 term at Cornell University (Engineering School).

Page1 / 5

Tree - import import import i import;...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online