コード例 #1
0
ファイル: FNodeCompactor.cs プロジェクト: pwdlugosz/Horse
        /// <summary>
        /// Binds a leaf node to another node
        /// </summary>
        /// <param name="MainNode">The node containing a pointer node that will be bound</param>
        /// <param name="ParameterNode">The node that will be bound to the MainNode</param>
        /// <param name="PointerNodeName">The name of the pointer the ParameterNode will be replacing</param>
        /// <returns></returns>
        public static FNode Bind(FNode MainNode, FNode ParameterNode, string PointerNodeName)
        {

            // Clone the main node //
            FNode t = MainNode.CloneOfMe();

            // Decompile t //
            List<FNodePointer> refs = FNodeAnalysis.AllPointers(t);

            // Replace the pointer node with the parameter node //
            foreach (FNodePointer x in refs)
            {
                if (x.PointerName == PointerNodeName)
                    FNodeAnalysis.ReplaceNode(x, ParameterNode);
            }

            return t;

        }
コード例 #2
0
ファイル: FNodeGradient.cs プロジェクト: pwdlugosz/Horse
        // F(X) = power(Y, G(X)), F'(X) = LOG(Y) * power(Y, G(X)) * G'(X)
        private static FNode GradientOfPowerUpper(FNode Node, FNodePointer X)
        {

            // Throw an exception if X is decendant of Y, in otherwords F(X) = Power(G(X), H(X))
            if (FNodeAnalysis.IsDecendent(X, Node.Children[1]))
                throw new Exception(string.Format("Cannot differentiate the power function with the form: Power(G(X), H(X)); G(X) cannot have a relation to X"));

            // LOG(Y) //
            FNode log_y = new FNodeResult(null, new CellFuncFVLog());
            log_y.AddChildNode(Node.Children[0]);

            // Get Power(Y, G(X)) * LOG(Y) //
            FNode pow_f_dx = new FNodeResult(Node.ParentNode, new CellBinMult());
            pow_f_dx.AddChildNode(Node.CloneOfMe());
            pow_f_dx.AddChildNode(log_y);

            // Get Power(G(X), N-1) * G'(X) //
            FNode t = new FNodeResult(Node.ParentNode, new CellBinMult());
            t.AddChildNode(pow_f_dx);
            t.AddChildNode(Gradient(Node.Children[1], X));

            return t;

        }
コード例 #3
0
        public static FNode BindNode(FNode Equation, CellVector Bindings, Dictionary<string, int> Map)
        {

            FNode t = Equation.CloneOfMe();
            foreach(KeyValuePair<string,int> kv in Map)
            {
                string name = kv.Key;
                int idx = kv.Value;
                FNode b = new FNodeValue(null, Bindings[idx]);
                t = FNodeCompacter.Bind(t, b, name);
            }

            return t;

        }
コード例 #4
0
ファイル: FNodeGradient.cs プロジェクト: pwdlugosz/Horse
        // F(X) = exp(G(X)), F'(X) = exp(G(X)) * G'(X), or simplified F(X) * G'(X) 
        private static FNode GradientOfExp(FNode Node, FNodePointer X)
        {

            // F(X) * G'(X) //
            FNodeResult t = new FNodeResult(Node.ParentNode, new CellBinMult());
            t.AddChildNode(Node.CloneOfMe());
            t.AddChildNode(Gradient(Node.Children[0], X));

            return t;
        }