protected void updateTreeOutput(RegressionTree rt) { List<Split> leaves = rt.leaves(); for (int i = 0; i < leaves.size(); i++) { float s1 = 0.0F; Split s = leaves.get(i); int[] idx = s.getSamples(); for (int j = 0; j < idx.length; j++) { int k = idx[j]; s1 += pseudoResponses[k]; } s.setOutput(s1 / idx.length); } }
/** * Each input node @n corersponds to a <split> tag in the model file. * * @param n * @return */ private Split create(Node n) { Split s = null; if (n.getFirstChild().getNodeName().compareToIgnoreCase("feature") == 0) // this is a split { NodeList nl = n.getChildNodes(); int fid = Integer.parseInt( nl.item(0).getFirstChild().getNodeValue().toString().trim()); // <feature> float threshold = Float.parseFloat( nl.item(1).getFirstChild().getNodeValue().toString().trim()); // <threshold> s = new Split(fid, threshold, 0); s.setLeft(create(nl.item(2))); s.setRight(create(nl.item(3))); } else // this is a stump { float output = Float.parseFloat(n.getFirstChild().getFirstChild().getNodeValue().toString().trim()); s = new Split(); s.setOutput(output); } return s; }