@Override public void onCompletion(CountedCompleter caller) { ScoreBuildHistogram sbh = (ScoreBuildHistogram) caller; // System.out.println(sbh.profString()); final int leafk = _leafs[_k]; int tmax = _tree.len(); // Number of total splits in tree K for (int leaf = leafk; leaf < tmax; leaf++) { // Visit all the new splits (leaves) DTree.UndecidedNode udn = _tree.undecided(leaf); // System.out.println((_st._nclass==1?"Regression":("Class // "+_fr2.vecs()[_st._ncols].domain()[_k]))+",\n Undecided node:"+udn); // Replace the Undecided with the Split decision DTree.DecidedNode dn = _st.makeDecided(udn, sbh._hcs[leaf - leafk]); // System.out.println(dn + // " > Split: " + dn._split + " L/R:" + dn._split._n0+" + // "+dn._split._n1); if (dn._split._col == -1) udn.do_not_split(); else { _did_split = true; DTree.Split s = dn._split; // Accumulate squared error improvements per variable AtomicUtils.FloatArray.add(_improvPerVar, s.col(), (float) (s.pre_split_se() - s.se())); } } _leafs[_k] = tmax; // Setup leafs for next tree level int new_leafs = _tree.len() - tmax; _hcs[_k] = new DHistogram[new_leafs][ /*ncol*/]; for (int nl = tmax; nl < _tree.len(); nl++) _hcs[_k][nl - tmax] = _tree.undecided(nl)._hs; if (_did_split) _tree._depth++; }
// Find the column with the best split (lowest score). Unlike RF, GBM // scores on all columns and selects splits on all columns. @Override public DTree.Split bestCol(UndecidedNode u, DHistogram[] hs) { DTree.Split best = new DTree.Split(-1, -1, false, Double.MAX_VALUE, Double.MAX_VALUE, 0L, 0L, 0, 0); if (hs == null) return best; for (int i = 0; i < hs.length; i++) { if (hs[i] == null || hs[i].nbins() <= 1) continue; DTree.Split s = hs[i].scoreMSE(i); if (s == null) continue; if (best == null || s.se() < best.se()) best = s; if (s.se() <= 0) break; // No point in looking further! } return best; }