예제 #1
0
            public void Visit(Compiled.Gp elem)
            {
                GeneralMatrix cur = new GeneralMatrix(1, elem.Terms.Length);

                for (int i = 0; i < elem.Terms.Length; ++i)
                {
                    cur.SetElement(0, i, ValueOf(elem.Terms[i]));
                }
                elem.Value = elem.Gpr.Evaluate(cur).GetElement(0, 0);

                for (int i = 0; i < elem.Inputs.Length; ++i)
                {
                    if (i < elem.dc)
                    {
                        //elem.Inputs[i].Weight = elem.Gpr.PartialDerivative(cur, i);
                        cur.SetElement(0, i, cur.GetElement(0, i) + 0.1);
                        elem.Inputs[i].Weight = (elem.Gpr.Evaluate(cur).GetElement(0, 0) - elem.Value) / 0.1;
                        cur.SetElement(0, i, cur.GetElement(0, i) - 0.1);
                    }
                    else
                    {
                        elem.Inputs[i].Weight = 0;
                    }
                }


                //Here Starts a dirty Hack

                /*double sum=0;
                 * for(int n=0; n<elem.Inputs.Length; n++) {
                 *      sum += elem.Inputs[n].Weight;
                 * }
                 * if(sum < 0.00001) {
                 *      double val = elem.Value;
                 *
                 *      double minDist = Double.MaxValue;
                 *      int iMin=-1;
                 *      double dist = 0, tmp;
                 *      for(int n=0; n<elem.X.RowDimension; n++) {
                 *              if(elem.Gpr.Y.GetElement(0, n) > val) {
                 *                      dist = 0;
                 *                      for(int m=0; m<elem.X.ColumnDimension; m++) {
                 *                              tmp = elem.X.GetElement(n, m) - cur.GetElement(0, m);
                 *                              dist += tmp*tmp;
                 *                      }
                 *                      if(dist < minDist) {
                 *                              minDist = dist;
                 *                              iMin = n;
                 *                      }
                 *              }
                 *      }
                 *      if(iMin>=0) {
                 *              for(int m=0; m<elem.X.ColumnDimension; m++) {
                 *                      elem.Inputs[m].Weight = elem.X.GetElement(m, iMin) - cur.GetElement(0, m);
                 *              }
                 *      }
                 * }*/
            }
            public void Visit(Compiled.Gp elem)
            {
                GeneralMatrix cur = new GeneralMatrix(1, elem.Terms.Length);

                for (int i = 0; i < elem.Terms.Length; ++i)
                {
                    cur.SetElement(0, i, ValueOf(elem.Terms[i]));
                }
                LocalDerivative = elem.Gpr.PartialDerivative(cur, ArgumentIndex);
            }
            public void Visit(Compiled.Gp elem)
            {
                GeneralMatrix cur = new GeneralMatrix(1, elem.Terms.Length);

                for (int i = 0; i < elem.Terms.Length; ++i)
                {
                    cur.SetElement(0, i, ValueOf(elem.Terms[i]));
                }
                elem.Value = elem.Gpr.Evaluate(cur).GetElement(0, 0);
            }
            public int Visit(Gp gp)
            {
                return(Compile(gp, () =>
                {
                    int[] indices = new int[gp.Args.Length];
                    Compiled.InputEdge[] inputs = new Compiled.InputEdge[indices.Length];
                    for (int i = 0; i < indices.Length; i++)
                    {
                        indices[i] = gp.Args[i].Accept(this);
                        inputs[i] = new Compiled.InputEdge {
                            Index = indices[i]
                        };
                    }

                    var element = new Compiled.Gp {
                        Terms = indices,
                        Inputs = inputs,
                        Gpr = gp.Gpr,
                        dc = gp.DivCount,
                    };
                    return element;
                }));
            }