Ejemplo n.º 1
0
        private Algorithms.GravitationalClustering PredictIrisDataSimProto()
        {
            var data = File.ReadAllLines("iris.csv")
                       .Skip(1)
                       .Select(x =>
            {
                var left  = x.Split(',').Skip(1).Select(y => double.Parse(y)).ToArray();
                var right = int.Parse(x.Split(',').Last());
                return(Tuple.Create(left, right));
            })
                       .ToArray();

            Algorithms.GravitationalClustering clustering = new Algorithms.GravitationalClustering(0.01, 0.1, 100, new SquaredEuclideanDistance());
            return(RunProtoGCAlgoritym(ref data, clustering, true));
        }
Ejemplo n.º 2
0
        private Algorithms.GravitationalClustering PredictOllivetiDataSimProto()
        {
            int index = 0;
            var pred  = File.ReadAllLines("olevitti_p.csv");
            var data  = File.ReadAllLines("olevitti.csv")
                        .Select(x =>
            {
                var left = x.Split(',').Skip(1).Select(y => double.Parse(y)).ToArray();
                return(Tuple.Create(left, (int)double.Parse(pred[index++])));
            })
                        .ToArray();

            Algorithms.GravitationalClustering clustering = new Algorithms.GravitationalClustering(10, 0.1, 1, new SquaredEuclideanDistance());

            return(RunProtoGCAlgoritym(ref data, clustering, true));
        }
Ejemplo n.º 3
0
        private Algorithms.GravitationalClustering PredictDigitsDataProb()
        {
            var data = File.ReadAllLines("digits.csv")
                       .Skip(1)
                       .Select(x =>
            {
                var left  = x.Split(',').Skip(1).Select(y => double.Parse(y)).ToArray();
                var right = int.Parse(x.Split(',').Last());
                return(Tuple.Create(left, right));
            })
                       .ToArray();

            Algorithms.GravitationalClustering clustering = new Algorithms.GravitationalClustering(40, 0.01, 100, new SquaredEuclideanDistance());

            return(RunGCAlgorithm(ref data, clustering, false, 50));
        }
Ejemplo n.º 4
0
 public void DrawClusters(Algorithms.GravitationalClustering clust)
 {
     for (int i = 0; i < 4; i++)
     {
         for (int x = i; x < 4; x++)
         {
             if (i != x)
             {
                 Graphics g = this.pictureBox1.CreateGraphics();
                 foreach (var item in clust.EnumeratePlanets())
                 {
                     this.DrawCircle(g, Pens.Red, new Point(
                                         (int)(item.Position[i] * this.ScaleCluster + this.ShiftCluster),
                                         (int)(item.Position[x] * this.ScaleCluster + 300)),
                                     (int)((item.Radius * ScaleRadius) * this.ScaleCluster * this.ScaleCluster));
                 }
                 this.ShiftCluster += 100;
             }
         }
     }
 }
Ejemplo n.º 5
0
        private Algorithms.GravitationalClustering PredictBreastCancerSimProto()
        {
            double[][] input = new double[569][];
            for (int x = 0; x < input.Length; x++)
            {
                input[x] = new double[32];
            }

            double[] output = new double[569];
            var      data   = File.ReadAllLines("wdbc.txt")
                              .Select(x =>
            {
                var left  = x.Split(',').Skip(2).Select(y => double.Parse(y)).ToArray();
                var right = x.Split(',').Skip(1).First().First() == 'M' ? 0 : 1;
                return(Tuple.Create(left, right));
            })
                              .ToArray();

            Algorithms.GravitationalClustering clustering = new Algorithms.GravitationalClustering(5000, 0.01, 100, new SquaredEuclideanDistance());

            return(RunProtoGCAlgoritym(ref data, clustering, true));
        }
Ejemplo n.º 6
0
        private Algorithms.GravitationalClustering RunProtoGCAlgoritym(ref Tuple <double[], int>[] data, Algorithms.GravitationalClustering clustering, bool sim)
        {
            var newData = this.GetProto(data);

            foreach (var item in newData)
            {
                clustering.OnlineTrainSingular(item.Item1, item.Item2);
            }
            Debug.WriteLine("Number of Clusters " + clustering.EnumeratePlanets().Count());
            var d = data.Select(xx =>
            {
                int outP = 0;
                if (sim)
                {
                    outP = clustering.PredictSimulation(xx.Item1);
                }
                else
                {
                    outP = clustering.PredictProbabilistic(xx.Item1);
                }

                Debug.WriteLine("Predicted Class " + outP);
                if (outP == xx.Item2)
                {
                    return(1);
                }
                return(0);
            }).Sum();

#if DEBUG
            {
                Debug.WriteLine("Percent Accuracy " + ((double)d / ((double)data.Length)).ToString());
            }
#else
            {
                MessageBox.Show(((double)d / ((double)data.Length)).ToString());
            }
#endif
            return(clustering);
        }
Ejemplo n.º 7
0
        private Algorithms.GravitationalClustering RunGCAlgorithm(ref Tuple <double[], int>[] data, Algorithms.GravitationalClustering clustering, bool sim, int rand = 4)
        {
            RandomizeArray(ref data, rand);

            int take = data.Length / 2;

            foreach (var item in data.Take(take))
            {
                clustering.OnlineTrainSingular(item.Item1, item.Item2);
            }
            Debug.WriteLine("Number of Clusters " + clustering.EnumeratePlanets().Count());
            var d = data.Skip(take).Select(xx =>
            {
                int outP = 0;
                if (sim)
                {
                    outP = clustering.PredictSimulation(xx.Item1);
                }
                else
                {
                    outP = clustering.PredictProbabilistic(xx.Item1);
                }

                Debug.WriteLine("Predicted Class " + outP);
                if (outP == xx.Item2)
                {
                    return(1);
                }
                return(0);
            }).Sum();

#if DEBUG
            {
                Debug.WriteLine("Percent Accuracy " + ((double)d / ((double)data.Length - take)).ToString());
            }
#else
            {
                MessageBox.Show(((double)d / ((double)data.Length - take)).ToString());
            }
#endif
            return(clustering);
        }