Beispiel #1
0
        private void RB_Train()
        {
            int    K            = (int)RBNumOfKUpDown.Value;
            int    numOfEpocks  = int.Parse(RBNumOfEpocksUpDown.Value.ToString());
            double learningRate = (double)RBLearningRateUpDown.Value;
            double maxError     = (double)RB_MaxErrorNumericUpDown.Value;

            this.getData(ref trainingSamples, ref trainingLabels, true);
            this.getData(ref testSamples, ref testLabels, false);

            _RBF = new RBF(K, numOfEpocks, learningRate, maxError, trainingSamples, trainingLabels, testSamples, testLabels);
            _RBF.Train();
        }
Beispiel #2
0
 public static IRBFPolynomial CreatePoly(RBF.PolyTypes type, RBFSurface surf)
 {
     switch (type)
     {
         case PolyTypes.Plane:
             return new RBFPolynomials.Plane(surf);
         case PolyTypes.Paraboloid:
             return new RBFPolynomials.Paraboloid(surf);
         case PolyTypes.ParaboloidC:
             return new RBFPolynomials.ParaboloidConst(surf);
         case PolyTypes.Conic:
             return new RBFPolynomials.Conic(surf);
         default :
             return new RBFPolynomials.Plane(surf);
     }
 }
Beispiel #3
0
        //List<double> vals = new List<double>();
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            object[]             arguments = e.Argument as object[];
            List <List <Point> > inputs    = new List <List <Point> >(arguments[0] as List <List <Point> >);
            List <Kluster>       output    = new List <Kluster>(arguments[1] as List <Kluster>);

            List <double[]> allpoints      = new List <double[]>();
            List <double[]> ClusterCenters = new List <double[]>();
            List <double>   clusterCounts  = new List <double>(0);

            lock (inputs)
            {
                //int count = 0;
                inputs.ForEach(satList =>
                {
                    lock (satList)
                    {
                        satList.ForEach(sat =>
                        {
                            //if(count%5==0)
                            lock (allpoints)
                            {
                                allpoints.Add(new double[] { sat.X, sat.Y });
                            }
                            //count++;
                        });
                        clusterCounts.Add(satList.Count);
                    }
                });
            }
            lock (output)
            {
                output.ForEach(cluster =>
                {
                    ClusterCenters.Add(new double[] { cluster.X, cluster.Y });
                });
            }
            if (allpoints.Count == 0 || ClusterCenters.Count == 0)
            {
                return;
            }
            if (e.Cancel)
            {
                return;
            }

            List <kMeans.RBFLite> rbfs = new List <kMeans.RBFLite>();

            if (!Type1)
            {
                RBF = new kMeans.RBFLiteCluster(allpoints, ClusterCenters, gamma, clusterCounts, checkBox1.Checked);
            }
            else
            {
                for (int i = 0; i < inputs.Count; i++)
                {
                    rbfs.Add(new kMeans.RBFLite(inputs[i].ConvertAll(new Converter <Point, double[]>((pnt) => { return(new double[] { pnt.X, pnt.Y }); })), new double[] { output[i].Location.X, output[i].Location.Y }, clusterCounts[i], gamma));
                }
            }

            double width  = this.Width;
            double height = this.Height;

            double scaleScreenX = 0.1;
            double scaleScreenY = 0.1;

            double gridResolutionX = width / PixelDensity;
            double gridResolutionY = height / PixelDensity;

            gridRes[0] = gridResolutionX;
            gridRes[1] = gridResolutionY;
            //double gridResolutionX = width / (1 * 10.0 - 4 * (1 - scaleScreenX));
            //double gridResolutionY = height / (1 * 10.0 - 4 * (1 - scaleScreenY));
            //double x = 0; double y = 0;

            double        xstep   = width / gridResolutionX;
            double        ystep   = height / gridResolutionY;
            List <double> heights = new List <double>();
            double        X       = 0;
            double        Y       = 0;
            double        Val     = 0;

            for (double i = 0; i < gridResolutionX; i++)
            {
                for (double j = 0; j < gridResolutionY; j++)
                {
                    if (e.Cancel)
                    {
                        return;
                    }
                    Val = 0;
                    X   = xstep * i;
                    Y   = ystep * j;
                    if (Type1)
                    {
                        rbfs.ForEach(rbf => Val += rbf.Eval(new double[] { X, Y }));
                    }
                    else
                    {
                        Val = RBF.Eval(new double[] { X, Y });
                    }
                    heights.Add(Val);
                }
            }

            double max, min;

            max = heights.Max();
            min = heights.Min();

            pntCollection.Clear();

            List <ColoredPoint> pnts1 = new List <ColoredPoint>();
            List <ColoredPoint> pnts2 = new List <ColoredPoint>();
            List <ColoredPoint> pnts3 = new List <ColoredPoint>();
            List <ColoredPoint> pnts4 = new List <ColoredPoint>();
            List <ColoredPoint> pnts5 = new List <ColoredPoint>();
            List <ColoredPoint> pnts6 = new List <ColoredPoint>();
            List <ColoredPoint> pnts7 = new List <ColoredPoint>();
            List <ColoredPoint> pnts8 = new List <ColoredPoint>();

            List <double> vals1 = new List <double>();
            List <double> vals2 = new List <double>();
            List <double> vals3 = new List <double>();
            List <double> vals4 = new List <double>();
            List <double> vals5 = new List <double>();
            List <double> vals6 = new List <double>();
            List <double> vals7 = new List <double>();
            List <double> vals8 = new List <double>();

            #region Parallel Reads


            Parallel.Invoke(
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = 0; i < gridResolutionX / 4; i++)
                {
                    for (double j = 0; j < gridResolutionY / 2; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts1.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            },
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = 0; i < gridResolutionX / 4; i++)
                {
                    for (double j = gridResolutionY / 2; j < gridResolutionY; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts2.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            },
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = gridResolutionX / 4; i < gridResolutionX / 2; i++)
                {
                    for (double j = 0; j < gridResolutionY / 2; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts3.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            },
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = gridResolutionX / 4; i < gridResolutionX / 2; i++)
                {
                    for (double j = gridResolutionY / 2; j < gridResolutionY; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts4.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            },
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = gridResolutionX / 2; i < 3 * gridResolutionX / 4; i++)
                {
                    for (double j = 0; j < gridResolutionY / 2; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts5.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            },
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = gridResolutionX / 2; i < 3 * gridResolutionX / 4; i++)
                {
                    for (double j = gridResolutionY / 2; j < gridResolutionY; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts6.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            },
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = 3 * gridResolutionX / 4; i < gridResolutionX; i++)
                {
                    for (double j = 0; j < gridResolutionY / 2; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts7.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            },
                () =>
            {
                double x = 0; double y = 0; double val = 0;
                for (double i = 3 * gridResolutionX / 4; i < gridResolutionX; i++)
                {
                    for (double j = gridResolutionY / 2; j < gridResolutionY; j++)
                    {
                        val = 0;
                        x   = xstep * i;
                        y   = ystep * j;
                        if (Type1)
                        {
                            rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
                        }
                        else
                        {
                            val = RBF.Eval(new double[] { x, y });
                        }
                        if (!double.IsNaN(val) && !double.IsInfinity(val))
                        {
                            pnts8.Add(new ColoredPoint(new Point((int)x, (int)y), GetColor(max, min, val), val));
                        }
                    }
                }
            }
                );

            pntCollection.Add(new List <ColoredPoint>(pnts1));
            pntCollection.Add(pnts2);
            pntCollection.Add(pnts3);
            pntCollection.Add(pnts4);
            pntCollection.Add(pnts5);
            pntCollection.Add(pnts6);
            pntCollection.Add(pnts7);
            pntCollection.Add(pnts8);

            coloredPoints.Clear();
            coloredPoints.AddRange(pnts1);
            coloredPoints.AddRange(pnts2);
            coloredPoints.AddRange(pnts3);
            coloredPoints.AddRange(pnts4);
            coloredPoints.AddRange(pnts5);
            coloredPoints.AddRange(pnts6);
            coloredPoints.AddRange(pnts7);
            coloredPoints.AddRange(pnts8);

            #endregion Parallel Reads


            //double x = 0; double y = 0;
            //for (double i = 0; i < gridResolutionX; i++)
            //{
            //    for (double j = 0; j < gridResolutionY; j++)
            //    {
            //        if (e.Cancel)
            //            return;
            //        val = 0;
            //        x = xstep * i;
            //        y = ystep * j;
            //      //  val = rbf.Eval(new double[] { x, y });
            //        rbfs.ForEach(rbf => val += rbf.Eval(new double[] { x, y }));
            //        if (!double.IsNaN(val) && !double.IsInfinity(val))
            //        {
            //            Color c = GetColor(max, min, val);
            //            coloredPoints.Add(new ColoredPoint(new Point((int)x, (int)y), c));

            //        }
            //    }
            //}
            //pntCollection.Add(coloredPoints);
        }