Log1P() public static method

public static Log1P ( double x ) : double
x double
return double
コード例 #1
0
        public void UpdateLogProbability(int index)
        {
            if (this.IsLeaf(index))
            {
                this.Nodes[index].LogProbability = this.Nodes[index].LogKt;
            }
            else
            {
                double logChildProbability = 0;
                int    lchild = this.Nodes[index].Child1;
                if (lchild != -1)
                {
                    logChildProbability += this.Nodes[lchild].LogProbability;
                }
                int rchild = this.Nodes[index].Child0;
                if (rchild != -1)
                {
                    logChildProbability += this.Nodes[rchild].LogProbability;
                }

                //for better numerical results
                double a = Math.Max(this.Nodes[index].LogKt, logChildProbability);
                double b = Math.Min(this.Nodes[index].LogKt, logChildProbability);

                this.Nodes[index].LogProbability = Math.Log(0.5) + a + Utils.Log1P(Math.Exp(b - a));
                //todo: is it fast enough to compute Math.Log(0.5) every time. Joel has it cached.
            }
        }
コード例 #2
0
        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));
            }
        }