use of org.tribuo.common.tree.SplitNode in project tribuo by oracle.
the class IndependentRegressionTreeModel method getExcuse.
@Override
public Optional<Excuse<Regressor>> getExcuse(Example<Regressor> example) {
SparseVector vec = SparseVector.createSparseVector(example, featureIDMap, false);
if (vec.numActiveElements() == 0) {
return Optional.empty();
}
List<String> list = new ArrayList<>();
List<Prediction<Regressor>> predList = new ArrayList<>();
Map<String, List<Pair<String, Double>>> map = new HashMap<>();
for (Map.Entry<String, Node<Regressor>> e : roots.entrySet()) {
list.clear();
//
// Ensures we handle collisions correctly
Node<Regressor> oldNode = e.getValue();
Node<Regressor> curNode = e.getValue();
while (curNode != null) {
oldNode = curNode;
if (oldNode instanceof SplitNode) {
SplitNode<?> node = (SplitNode<?>) curNode;
list.add(featureIDMap.get(node.getFeatureID()).getName());
}
curNode = oldNode.getNextNode(vec);
}
//
// oldNode must be a LeafNode.
predList.add(((LeafNode<Regressor>) oldNode).getPrediction(vec.numActiveElements(), example));
List<Pair<String, Double>> pairs = new ArrayList<>();
int i = list.size() + 1;
for (String s : list) {
pairs.add(new Pair<>(s, i + 0.0));
i--;
}
map.put(e.getKey(), pairs);
}
Prediction<Regressor> combinedPrediction = combine(predList);
return Optional.of(new Excuse<>(example, combinedPrediction, map));
}
Aggregations