public void UpdateLogProbability()
{
if (this.IsLeaf())
{
this.LogProbability = this.LogKt;
}
else {
double logChildProbability = 0;
foreach (CTWContextTreeNode child in this.Children.Values) {
//note: this is not best way of doing summation of doubles. We will see if this will matter...
// (eg: python has math.fsum)
logChildProbability += child.LogProbability;
}
//for better numerical results (least chance of overflow)
double a = Math.Max(this.LogKt, logChildProbability);
double b = Math.Min(this.LogKt, logChildProbability);
this.LogProbability = this.LogHalf + a + Utils.Log1P(Math.Exp(b - a));
}
}