(TreeNodeVisitor node, ImpurityScore score, List<DataPointPair<Integer>> data, final double[] features , final double N, final int K)
| 83 | } |
| 84 | |
| 85 | private void visit(TreeNodeVisitor node, ImpurityScore score, List<DataPointPair<Integer>> data, final double[] features , final double N, final int K) |
| 86 | { |
| 87 | if (node == null || node.isLeaf() )//invalid path or no split, so skip |
| 88 | return; |
| 89 | |
| 90 | double curScore = score.getScore(); |
| 91 | double curN = score.getSumOfWeights(); |
| 92 | |
| 93 | //working space to split data up into new subsets |
| 94 | List<List<DataPointPair<Integer>>> splitsData = new ArrayList<List<DataPointPair<Integer>>>(node.childrenCount()); |
| 95 | List<ImpurityScore> splitScores = new ArrayList<ImpurityScore>(node.childrenCount()); |
| 96 | splitsData.add(data); |
| 97 | splitScores.add(score); |
| 98 | for(int i = 0; i < node.childrenCount()-1; i++) |
| 99 | { |
| 100 | splitsData.add(new ArrayList<DataPointPair<Integer>>()); |
| 101 | splitScores.add(new ImpurityScore(K, im)); |
| 102 | } |
| 103 | |
| 104 | //loop through and split up our data |
| 105 | for(ListIterator<DataPointPair<Integer>> iter = data.listIterator(); iter.hasNext();) |
| 106 | { |
| 107 | DataPointPair<Integer> curPoint = iter.next(); |
| 108 | final int tc = curPoint.getPair(); |
| 109 | DataPoint dp = curPoint.getDataPoint(); |
| 110 | int path = node.getPath(dp); |
| 111 | if(path < 0)//NaN will cause -1 |
| 112 | score.removePoint(dp, tc); |
| 113 | else if(path > 0)//0 will be cur data and score obj, else we move to right location |
| 114 | { |
| 115 | score.removePoint(dp, tc); |
| 116 | splitScores.get(path).addPoint(dp, tc); |
| 117 | splitsData.get(path).add(curPoint); |
| 118 | iter.remove(); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | double chageInImp = curScore; |
| 123 | for(ImpurityScore s : splitScores) |
| 124 | chageInImp -= s.getScore()*(s.getSumOfWeights()/(1e-5+curN)); |
| 125 | |
| 126 | |
| 127 | Collection<Integer> featuresUsed = node.featuresUsed(); |
| 128 | for (int feature : featuresUsed) |
| 129 | features[feature] += chageInImp*curN/N; |
| 130 | |
| 131 | //now visit our children |
| 132 | for(int path = 0; path < splitScores.size(); path++) |
| 133 | visit(node.getChild(path), splitScores.get(path), splitsData.get(path), features, N, K); |
| 134 | } |
| 135 | |
| 136 | } |
no test coverage detected