Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }