private void trackDecisions(DecisionNode root, double[] input, int index)
{
DecisionNode current = root;
while (current != null)
{
subsets[current].Add(index);
if (current.IsLeaf)
{
actual[index] = current.Output.HasValue ? current.Output.Value : -1;
return;
}
int attribute = current.Branches.AttributeIndex;
DecisionNode nextNode = null;
foreach (DecisionNode branch in current.Branches)
{
if (branch.Compute(input[attribute]))
{
nextNode = branch; break;
}
}
current = nextNode;
}
// Normal execution should not reach here.
throw new InvalidOperationException("The tree is degenerated.");
}
}