示例#1
0
        public _3dForm()
        {
            InitializeComponent();
            SetupWorker();

            stat = ((string message) => { m_status.Text = message; });

            CustomBasis GeneticBasis = null;

            Eval = new Evaluator((ref List<int> binaryCoded, ref List<int> bestChromo) =>
            {
                //if(!m_running)

                double error = 0;

                List<double[]> gaPnts = new List<double[]>();

                double[] result = EvalChromosome(ref binaryCoded, ref gaPnts);

                GeneticBasis = new CustomBasis(16.383 / 2.0 - result[0], 16.383 / 2.0 - result[1], 16.383 / 2.0 - result[2], 16.383 / 2.0 - result[3]);

                double[] pnt1, pnt2, dx1, dx2;

                //List<double[]> fitpoints = new List<double[]>(oldRBF.OriginalFitPoints);

                List<double[]> fitpoints = new List<double[]>(gaPnts);

                found = new SurfaceRBF(null, "target", fitpoints, GeneticBasis, targetPoly, 0.0);

                //List<double[]> errorSurfPnts = new List<double[]>();
                double gridCount = GridSize;
                for (double i = 0; i < gridCount; i += 1.0)
                {
                    for (double j = 0; j < gridCount; j += 1.0)
                    {
                        pnt1 = new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 0 };
                        pnt2 = new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 0 };
                        target.Value(ref pnt1);
                        found.Value(ref pnt2);

                        error += 10.0 * Math.Pow(Math.Abs(pnt2[2] - pnt1[2]), 1);
                        //errorSurfPnts.Add(new double[] { i * 20.0, j * 20.0, pnt1[2] - pnt2[2] });
                    }
                }

                gridCount = 10.0;
                for (double i = 0; i < gridCount; i += 1.0)
                {
                    for (double j = 0; j < gridCount; j += 1.0)
                    {
                        pnt1 = new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 0 };
                        pnt2 = new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 0 };
                        target.Value(ref pnt1);
                        found.Value(ref pnt2);

                        error += Math.Pow(Math.Abs(pnt2[2] - pnt1[2]), 1);
                    }
                }

                //int count = 0;

                //double pntError = 1000;

                //gaPnts.ForEach((pnt) =>
                //{
                //     dx1 = new double[2];
                //     dx2 = new double[2];
                //     pnt2 = new double[] { pnt[0], pnt[1] };
                //     GaRBF.First(ref pnt, ref dx1);
                //     oldRBF.First(ref pnt, ref dx2);
                //     error += 2 * Math.Pow(pnt2[1] - pnt[1], 2);
                //     error += 2 * Math.Pow(Math.Pow(dx2[0] - dx1[0], 2) + Math.Pow(dx2[1] - dx1[1], 2), 2);
                //});

                //gaPnts.ForEach((pnt) =>
                //     {
                //          if (oldRBF.OriginalFitPoints.Find((Oldpnt) => { return Oldpnt[0] == pnt[0] && Oldpnt[1] == pnt[1]; }) != null)
                //               count++;
                //          else
                //               error *= 4;
                //     });

                //if (count != 0)
                //    pntError /= ((double)count / 5.0) * 1000.0;

                // error += pntError;

                //GC.Collect();
                return Math.Pow(error, -1);
            });
        }
示例#2
0
        public Form1()
        {
            InitializeComponent();
               SetupWorkers();
               InitializePlots();
               InstatiatePlotData();

               stat = ((string message) => { m_status.Text = message; });

               Eval = new Evaluator((ref List<int> binaryCoded, ref List<int> bestChromo) =>
                    {
                         if (binaryCoded.Count == 0)
                              return 0;

                         double error = 0;

                         List<double[]> gaPnts = new List<double[]>();

                         double[] result = EvalChromosome(ref binaryCoded, ref gaPnts);

                         CustomBasis GeneticBasis = new CustomBasis(16.383 / 2.0 - result[0], 16.383 / 2.0 - result[1], 16.383 / 2.0 - result[2], 16.383 / 2.0 - result[3]);

                         double[] pnt1, pnt2, dx1, dx2;

                         object curve = new object();
                         object plot = new object();

                         for (int j = 0; j < 1; j++)
                         {
                              switch (j + 1)
                              {
                                   case 1:
                                        curve = p1Curve;
                                        plot = plotSurface2D1;
                                        break;
                                   case 2:
                                        curve = p2Curve;
                                        plot = plotSurface2D2;
                                        break;
                                   case 3:
                                        curve = p3Curve;
                                        plot = plotSurface2D3;
                                        break;
                                   case 4:
                                        curve = p4Curve;
                                        plot = plotSurface2D4;
                                        break;
                                   case 5:
                                        curve = p5Curve;
                                        plot = plotSurface2D5;
                                        break;
                                   case 6:
                                        curve = p6Curve;
                                        plot = plotSurface2D6;
                                        break;
                              }

                              RBFCurve oldRBF = curve as RBFCurve;

                              //List<double[]> fitpoints = new List<double[]>(oldRBF.OriginalFitPoints);

                              List<double[]> fitpoints = new List<double[]>(gaPnts);

                              if (RemoveExtraFitPoints)
                              {
                                   fitpoints.RemoveAt(1);
                                   fitpoints.RemoveAt(2);
                              }

                              RBFCurve GaRBF = new RBFCurve(null, "GA RBF", fitpoints, GeneticBasis, new Linear(null), 0.0);

                              for (int i = 0; i < 30; i++)
                              {
                                   dx1 = new double[2];
                                   dx2 = new double[2];
                                   pnt1 = new double[] { (double)i, 0 };
                                   pnt2 = new double[] { (double)i, 0 };
                                   GaRBF.First(ref pnt1, ref dx1);
                                   oldRBF.First(ref pnt2, ref dx2);

                                   error += Math.Pow(pnt1[1] - pnt2[1], 2);
                                   error += Math.Pow(Math.Pow(dx2[0] - dx1[0], 2) + Math.Pow(dx2[1] - dx1[1], 2), 2);
                              }

                              //int count = 0;

                              double pntError = 1000;

                              gaPnts.ForEach((pnt) =>
                                   {
                                        dx1 = new double[2];
                                        dx2 = new double[2];
                                        pnt2 = new double[] { pnt[0], pnt[1] };
                                        GaRBF.First(ref pnt, ref dx1);
                                        oldRBF.First(ref pnt, ref dx2);
                                        error += 10 * Math.Pow(pnt2[1] - pnt[1], 2);
                                        //error += Math.Pow(Math.Pow(dx2[0] - dx1[0], 2) + Math.Pow(dx2[1] - dx1[1], 2), 2);
                                   });

                              //gaPnts.ForEach((pnt) =>
                              //     {
                              //          if (oldRBF.OriginalFitPoints.Find((Oldpnt) => { return Oldpnt[0] == pnt[0] && Oldpnt[1] == pnt[1]; }) != null)
                              //               count++;
                              //          else
                              //               error *= 4;
                              //     });

                              //if(count != 0)
                              //     pntError /= ((double)count / 5.0) * 1000.0;

                              error += pntError;
                         }

                         return Math.Pow(error, -1);
                    });
        }