public void Visit(Compiled.Sigmoid elem)
            {
                Debug.Assert(ArgumentIndex == 0 || ArgumentIndex == 1);
                double e = Math.Exp(elem.Steepness * (ValueOf(elem.Mid) - ValueOf(elem.Arg)));

//Console.WriteLine("e: {0} deriv: {1}",e,elem.Derivative);
                if (Double.IsPositiveInfinity(e) || e == 0)
                {
                    if (ArgumentIndex == 0)
                    {
                        LocalDerivative = elem.Steepness * elem.Adjoint * Epsilon;
                    }
                    else
                    {
                        LocalDerivative = -elem.Steepness * elem.Adjoint * Epsilon;
                    }
                }
                else
                if (ArgumentIndex == 0)
                {
                    LocalDerivative = elem.Steepness * elem.Adjoint * e / ((e + 1) * (e + 1));
                    if (Math.Abs(LocalDerivative) < Math.Abs(elem.Steepness * elem.Adjoint * Epsilon))
                    {
                        LocalDerivative = elem.Steepness * elem.Adjoint * Epsilon;
                    }
                }
                else
                {
                    LocalDerivative = -elem.Steepness * elem.Adjoint * e / ((e + 1) * (e + 1));
                    if (Math.Abs(LocalDerivative) < Math.Abs(elem.Steepness * elem.Adjoint * Epsilon))
                    {
                        LocalDerivative = -elem.Steepness * elem.Adjoint * Epsilon;
                    }
                }
            }
            public int Visit(Sigmoid sigmoid)
            {
                return(Compile(sigmoid, () =>
                {
                    var argIndex = sigmoid.Arg.Accept(this);
                    var midIndex = sigmoid.Mid.Accept(this);

                    var element = new Compiled.Sigmoid
                    {
                        Arg = argIndex,
                        Mid = midIndex,
                        Steepness = sigmoid.Steepness,
                        Inputs = new Compiled.InputEdge[]
                        {
                            new Compiled.InputEdge {
                                Index = argIndex
                            },
                            new Compiled.InputEdge {
                                Index = midIndex
                            },
                        }
                    };
                    return element;
                }));
            }
Exemple #3
0
            public void Visit(Compiled.Sigmoid elem)
            {
                double arg = ValueOf(elem.Arg);
                double mid = ValueOf(elem.Mid);
                double e   = Math.Exp(elem.Steepness * (-arg + mid));

                if (Double.IsPositiveInfinity(e))
                {
                    elem.Value = Term.Epsilon;
                }
                else
                {
                    elem.Value = 1.0 / (1.0 + e);
                }
                if (elem.Value < Term.Epsilon)
                {
                    elem.Value = Term.Epsilon;
                }
                if (e == 0.0 || Double.IsPositiveInfinity(e))
                {
                    elem.Inputs[0].Weight = elem.Steepness * Term.Epsilon;
                    elem.Inputs[1].Weight = -elem.Steepness * Term.Epsilon;
                    return;
                }
                double e2 = elem.Steepness * e / ((e + 1) * (e + 1));

                elem.Inputs[0].Weight = e2;
                elem.Inputs[1].Weight = -e2;
            }
            public void Visit(Compiled.Sigmoid elem)
            {
                double e = Math.Exp(elem.Steepness * (-ValueOf(elem.Arg) + ValueOf(elem.Mid)));

                if (Double.IsPositiveInfinity(e))
                {
                    elem.Value = Term.Epsilon;
                    //Console.WriteLine("FUCKUP {0}",e);
                }
                else
                {
                    elem.Value = 1.0 / (1.0 + e);
                }
                if (elem.Value < Term.Epsilon)
                {
                    elem.Value = Term.Epsilon;
                }
            }
            public int Visit(LinSigmoid sigmoid)
            {
                return(Compile(sigmoid, () =>
                {
                    var argIndex = sigmoid.Arg.Accept(this);

                    var element = new Compiled.Sigmoid
                    {
                        Arg = argIndex,
                        Inputs = new Compiled.InputEdge[]
                        {
                            new Compiled.InputEdge {
                                Index = argIndex
                            },
                        }
                    };
                    return element;
                }));
            }