Esempio n. 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);
            });
        }
Esempio n. 2
0
        void GAWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (GAWorker.CancellationPending == true)
                Algo.Stop();

            m_progBar.Value = e.ProgressPercentage;

            if (e.UserState == null)
                return;

            List<int> bestChromo = (List<int>)e.UserState;

            if (bestChromo.Count > 0)
            {
                List<double[]> gaPnts = new List<double[]>();

                double[] result = EvalChromosome(ref bestChromo, 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]);

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

                //for (int i = 0; i < fitpoints.Count; i++)
                //fitpoints[i][2] += 15; //offset

                SurfaceRBF tmpSurf = new SurfaceRBF(null, "best", fitpoints, GeneticBasis, targetPoly, 0.0);

                double[] max = new double[3]; double[] min = new double[3];
                max[0] = max[1] = max[2] = -1e9; //start max low
                min[0] = min[1] = min[2] = +1e9; //start min high

                fitpoints.ForEach((double[] v) =>
                {
                    for (int i = 0; i < v.Length; i++) //get fit points' bounding box
                    {
                        max[i] = Math.Max(v[i], Max[i]);
                        min[i] = Math.Min(v[i], Min[i]);
                    }
                });

                double[] pnt1 = new double[3]; double[] pnt2 = new double[3];

                List<double[]> errorSurfPnts = new List<double[]>();
                double gridCount = 10.0;
                List<devDept.Eyeshot.Labels.TextOnly> labels = new List<devDept.Eyeshot.Labels.TextOnly>();
                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);

                        errorSurfPnts.Add(new double[] { (i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0], (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], Math.Pow(pnt2[2] - pnt1[2], 2) });
                        labels.Add(new devDept.Eyeshot.Labels.TextOnly(new Point3D((i / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0] + GridSize * 20, (j / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], Math.Pow(pnt1[2] - pnt2[2], 2)), Math.Pow(((pnt1[2] - pnt2[2]) / pnt1[2]), 1).ToString("#0.00"), new Font(FontFamily.GenericSansSerif, 12.0f), Color.White, ContentAlignment.BottomCenter));

                    }
                }

                SurfaceRBF tmpSurf2 = new SurfaceRBF(null, "error", errorSurfPnts, targetBasis, targetPoly, 0.0);
                List<KeyValuePair<double[], double>> errorpts = tmpSurf2.GetMeshPointsCvt(50, 50, max, min, null);
                MulticolorOnVerticesMesh errorMesh = new MulticolorOnVerticesMesh(0);
                CreateMesh(errorpts, 50, ref errorMesh);
                errorMesh.RegenMode = devDept.Eyeshot.Standard.Entity.regenType.RegenAndCompile;
                errorMesh.EntityData = "errorSurface";
                errorMesh.Translate(GridSize * 20, 0, 0);
                AddEntity(errorMesh, false);

                List<KeyValuePair<double[], double>> pts = tmpSurf.GetMeshPointsCvt(60, 60, max, min, null);
                MulticolorOnVerticesMesh bestMesh = new MulticolorOnVerticesMesh(0);

                CreateMesh(pts, 60, ref bestMesh);
                bestMesh.RegenMode = devDept.Eyeshot.Standard.Entity.regenType.RegenAndCompile;
                bestMesh.EntityData = "bestSurface";
                bestMesh.Translate(-2 * GridSize * 10, 0, 0);
                devDept.Eyeshot.Labels.TextOnly bestBasis = new devDept.Eyeshot.Labels.TextOnly(new Point3D(((gridCount / 2.0) / (gridCount - 1)) * (Max[0] - Min[0]) + Min[0] - (2 * GridSize * 10), ((gridCount / 2.0) / (gridCount - 1)) * (Max[1] - Min[1]) + Min[1], 20), GeneticBasis.ToString(), new Font(FontFamily.GenericSansSerif, 12.0f), Color.White, ContentAlignment.BottomCenter);

                viewportProfessional1.Labels.Clear();
                labels.ForEach((label) => { viewportProfessional1.Labels.Add(label); });
                viewportProfessional1.Labels.Add(bestBasis);

                AddEntity(bestMesh, false);
                //for (int i = 0; i < fitpoints.Count; i++)
                //fitpoints[i][2] -= 15; //offset
                PointCloud fits = new PointCloud(doubleToPoint3d(fitpoints), 7.5f, Color.Blue);
                fits.EntityData = "bestpoints";

                AddEntity(fits, true);
                pts.Clear();
                bestChromo.Clear();
                //GC.Collect();
            }
        }
Esempio n. 3
0
        void p1BRW_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (p1BRW.CancellationPending == true)
                    Algo.Stop();

               m_progBar.Value = e.ProgressPercentage;
               if (e.UserState == null)
                    return;

               List<int> bestChromo = (List<int>)e.UserState;

               if (bestChromo.Count > 0)
               {
                    List<double[]> GAPnts = new List<double[]>();
                    double[] result = EvalChromosome(ref bestChromo, ref GAPnts);

                    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;
                         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]);
                         //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);
                         NPlot.Windows.PlotSurface2D plotter = (NPlot.Windows.PlotSurface2D)plot;

                         plotter.Clear();
                         plotter.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

                         //Add a background grid for better chart readability.
                         NPlot.Grid grid = new NPlot.Grid();
                         grid.VerticalGridType = NPlot.Grid.GridType.Coarse;
                         grid.HorizontalGridType = NPlot.Grid.GridType.Coarse;
                         grid.MinorGridPen = new Pen(Color.Blue, 1.0f);
                         grid.MajorGridPen = new Pen(Color.LightGray, 1.0f);

                         plotter.Add(grid);

                         int length = oldRBF.FitPoints.Count * 5;
                         //Create a step plot instance for the balance chart.
                         LinePlot speed = new LinePlot();
                         LinePlot speed2 = new LinePlot();
                         PointPlot pplot = new PointPlot();
                         PointPlot pplot2 = new PointPlot();

                         pplot2.Marker = new Marker(Marker.MarkerType.Cross1, 10, System.Drawing.Color.Red);

                         speed.Pen = new Pen(Color.Blue, 1);

                         //Create the lists from which to pull data.
                         List<Int32> countaxis = new List<Int32>();
                         List<Int32> Pplotcountaxis = new List<Int32>();
                         List<Int32> Pplotcountaxis2 = new List<Int32>();
                         List<decimal> speedlist = new List<decimal>();
                         List<decimal> speedlist2 = new List<decimal>();

                         for (int i = 0; i < length; i++)
                              countaxis.Add(i);

                         for (int i = 0; i < oldRBF.FitPoints.Count; i++)
                              Pplotcountaxis.Add((int)oldRBF.OriginalFitPoints[i][0]);

                         for (int i = 0; i < GaRBF.FitPoints.Count; i++)
                              Pplotcountaxis2.Add((int)GaRBF.OriginalFitPoints[i][0]);

                         //Populate the balanceAmount list
                         double[] pnt;
                         List<decimal> pointsList = oldRBF.OriginalFitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); }));
                         List<decimal> pointsList2 = GaRBF.OriginalFitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); }));

                         for (int i = 0; i < length; i++)
                         {
                              pnt = new double[] { (double)i, 0 };
                              oldRBF.Value(ref pnt);
                              speedlist.Add(Convert.ToDecimal(pnt[1]));
                              pnt = new double[] { (double)i, 0 };
                              GaRBF.Value(ref pnt);
                              speedlist2.Add(Convert.ToDecimal(pnt[1]));
                         }

                         pplot.AbscissaData = Pplotcountaxis;
                         pplot.DataSource = pointsList;
                         pplot2.AbscissaData = Pplotcountaxis2;
                         pplot2.DataSource = pointsList2;
                         speed.AbscissaData = countaxis;
                         speed.DataSource = speedlist;
                         speed2.AbscissaData = countaxis;
                         speed2.DataSource = speedlist2;

                         //Add stepBalance to plotSurfaceBalance.

                         plotter.Add(speed);
                         plotter.Add(speed2);
                         plotter.Add(pplot);
                         plotter.Add(pplot2);

                         //Balance plot general settings.
                         plotter.ShowCoordinates = true;

                         plotter.AutoScaleAutoGeneratedAxes = true;
                         plotter.AddAxesConstraint(new AxesConstraint.AxisPosition(NPlot.PlotSurface2D.YAxisPosition.Left, 60));

                         plotter.YAxis1.Label = "Y";
                         plotter.YAxis1.LabelFont = new Font(this.Font, FontStyle.Bold);
                         plotter.YAxis1.LabelOffsetAbsolute = true;
                         plotter.XAxis1.Label = "X";
                         plotter.XAxis1.LabelFont = new Font(this.Font, FontStyle.Bold);
                         plotter.YAxis1.LabelOffset = 40;
                         plotter.XAxis1.HideTickText = false;
                         plotter.Padding = 5;

                         plotter.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu;
                         plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false));
                         plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
                         plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());

                         plotter.Title = GeneticBasis.ToString();
                         plotter.TitleFont = new Font(this.Font, FontStyle.Bold);
                         //}

                         //Refresh surfaces.
                         plotter.Refresh();
                    }
                    Application.DoEvents();
               }
        }
Esempio n. 4
0
        private void SetPlots(int p, List<double[]> fitPoints)
        {
            object plot = new object();
               object curve = new object();
               IBasisFunction basis = new RBFBasis.ThinPlateSpline(null);

               switch (Basis)
               {
                    case BasisType.Cubic:
                         basis = new RBFBasis.PolyHarmonic3(null);
                         break;
                    case BasisType.Gaussian:
                         basis = new RBFBasis.Gaussian(null);
                         break;
                    case BasisType.Line:
                         basis = new RBFBasis.CustomBasis(null, 0, 0, 1, 0);
                         break;
                    case BasisType.Parabolic:
                         basis = new RBFBasis.ThinPlateSpline2(null);
                         break;
                    case BasisType.CubicParabolic:
                         if (p % 2 == 0)
                              basis = new RBFBasis.PolyHarmonic3(null);
                         else
                              basis = new RBFBasis.CustomBasis(null, 1, 1, -1, 0);
                         break;
               }

               switch (p)
               {
                    case 1:
                         plot = plotSurface2D1;
                         //basis = new RBFBasis.Exponential(null);
                         p1Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0);
                         curve = p1Curve;
                         break;
                    case 2:
                         plot = plotSurface2D2;
                         //basis = new RBFBasis.Exponential(null);
                         p2Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0);
                         curve = p2Curve;
                         break;
                    case 3:
                         plot = plotSurface2D3;
                         //basis = new RBFBasis.Exponential(null);
                         p3Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0);
                         curve = p3Curve;
                         break;
                    case 4:
                         plot = plotSurface2D4;
                         //basis = new RBFBasis.Exponential(null);
                         p4Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0);
                         curve = p4Curve;
                         break;
                    case 5:
                         plot = plotSurface2D5;
                         //basis = new RBFBasis.Exponential(null);
                         p5Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0);
                         curve = p5Curve;
                         break;
                    case 6:
                         plot = plotSurface2D6;
                         // basis = new RBFBasis.Exponential(null);
                         p6Curve = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0);
                         curve = p6Curve;
                         break;
               }

               if (Max[0] < fitPoints.Max(pt => pt[0]))
                    Max[0] = fitPoints.Max(pt => pt[0]);
               if (Max[1] < fitPoints.Max(pt => pt[1]))
                    Max[1] = fitPoints.Max(pt => pt[1]);

               if (Min[0] > fitPoints.Min(pt => pt[0]))
                    Min[0] = fitPoints.Min(pt => pt[0]);
               if (Min[1] > fitPoints.Min(pt => pt[1]))
                    Min[1] = fitPoints.Min(pt => pt[1]);

               NPlot.Windows.PlotSurface2D plotter = (NPlot.Windows.PlotSurface2D)plot;
               RBFCurve RBF = (RBFCurve)curve;

               //RBF = new RBFCurve(null, "RBF " + p, fitPoints, basis, new RBFPolynomials.Linear(null), 0.0);

               plotter.Clear();
               plotter.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

               //Add a background grid for better chart readability.
               NPlot.Grid grid = new NPlot.Grid();
               grid.VerticalGridType = NPlot.Grid.GridType.Coarse;
               grid.HorizontalGridType = NPlot.Grid.GridType.Coarse;
               grid.MinorGridPen = new Pen(Color.Blue, 1.0f);
               grid.MajorGridPen = new Pen(Color.LightGray, 1.0f);

               plotter.Add(grid);

               int length = fitPoints.Count * 5;
               //Create a step plot instance for the balance chart.
               LinePlot speed = new LinePlot();
               PointPlot pplot = new PointPlot();

               speed.Pen = new Pen(Color.Blue, 1);

               //Create the lists from which to pull data.
               List<Int32> countaxis = new List<Int32>();
               List<Int32> Pplotcountaxis = new List<Int32>();
               List<decimal> speedlist = new List<decimal>();

               for (int i = 0; i < length; i++)
                    countaxis.Add(i);

               for (int i = 0; i < fitPoints.Count; i++)
                    Pplotcountaxis.Add((int)fitPoints[i][0]);
               //Populate the balanceAmount list
               double[] pnt;
               List<decimal> pointsList = fitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); }));

               for (int i = 0; i < length; i++)
               {
                    pnt = new double[] { (double)i, 0 };
                    RBF.Value(ref pnt);
                    speedlist.Add(Convert.ToDecimal(pnt[1]));
               }

               //foreach (double value in pent.Speeds)
               //{
               //     speedlist.Add(Convert.ToDecimal(value) / 1200);
               //}
               pplot.AbscissaData = Pplotcountaxis;
               pplot.DataSource = pointsList;
               speed.AbscissaData = countaxis;
               speed.DataSource = speedlist;

               //Add stepBalance to plotSurfaceBalance.

               plotter.Add(speed);
               plotter.Add(pplot);

               //Balance plot general settings.
               plotter.ShowCoordinates = true;
               //plotter.YAxis1.WorldMax = 10;
               //plotter.YAxis1.WorldMin = 0;
               //this.YAxis1.
               plotter.AutoScaleAutoGeneratedAxes = true;
               plotter.AddAxesConstraint(new AxesConstraint.AxisPosition(NPlot.PlotSurface2D.YAxisPosition.Left, 60));

               //Label Label1 = new Label();
               //Label1.Font = new Font(Label1.Font, FontStyle.Bold);

               //plotter.YAxis1.

               plotter.YAxis1.Label = "Y";
               plotter.YAxis1.LabelFont = new Font(this.Font, FontStyle.Bold);
               plotter.YAxis1.LabelOffsetAbsolute = true;
               plotter.XAxis1.Label = "X";
               plotter.XAxis1.LabelFont = new Font(this.Font, FontStyle.Bold);
               plotter.YAxis1.LabelOffset = 40;
               plotter.XAxis1.HideTickText = false;
               plotter.Padding = 5;

               plotter.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu;
               plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false));
               plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
               plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());

               plotter.Title = basis.Label;
               plotter.TitleFont = new Font(this.Font, FontStyle.Bold);
               //}

               //Refresh surfaces.
               plotter.Refresh();
        }
Esempio n. 5
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);
                    });
        }