コード例 #1
0
        public static void KmeansMain()
        {
            Console.WriteLine("Using demo setup?[y/n]");
            string str = Console.ReadLine();

            if (str.ToLower().Contains("y") == false)
            {
                Console.WriteLine("Input node maximum value:(Default:10000 , Min:0)");
                NodesMaxValueSet = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Input node count:(Default:10000 , Min:0)");
                NodesSet = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Input groups count for random points to divid into:(Default:3 , Min:0)");
                DataGroupCount = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Input fluctuation ratio:(Default:0.18 , Min:0 , Max:0.5)");
                FluctuationRatio = Convert.ToSingle(Console.ReadLine());

                Console.WriteLine("Input k:( Default:3 , Min:1)");
                k = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Input iteration limit:(Default:100)");
                IterationLimit = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Input convergence distance:(Default:5)");
                ConvDistance = Convert.ToInt32(Console.ReadLine());
            }

            //Gen grouped random nodes
            Random2DPoints.OnGeneratePointGroups += Random2DPoints_OnGeneratePointGroups;
            var RandomPoints = Random2DPoints.GenerateRandomPointsGroup(NodesMaxValueSet, NodesSet, DataGroupCount, FluctuationRatio);
            var Dataset      = new VectorCollection <Point2D>(RandomPoints);

            Dataset.Print();

            while (Retry)
            {
                KmeansTrainer <Point2D> kmeansTrainer = new KmeansTrainer <Point2D>(Dataset, k, ConvDistance, IterationLimit);
                kmeansTrainer.OnIteration += Kmeans_OnIteration;

                var TrainResult = kmeansTrainer.Train();

                //Kmeans<Point2D> kmeans = new Kmeans<Point2D>(TrainResult);

                InputCommand();
                kmeansTrainer.OnIteration -= Kmeans_OnIteration;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: aiex718/ML_Learning
        private static KmeansTrainResult <RawImage28x28> AskKmeansTrainData(bool SkipConfirm)
        {
            while (true)
            {
                string input;

                if (SkipConfirm)
                {
                    input = "t";
                }
                else
                {
                    Console.WriteLine("Input 't' to start training, 'i' to ignore.");
                    input = Console.ReadLine();
                }

                if (input.ToLower().Contains('t'))
                {
                    Console.WriteLine("Input ConvDistance:(Default:3)");
                    float ConvDistance = Convert.ToSingle(Console.ReadLine());
                    Console.WriteLine("Input iteration limit:(Default:200)");
                    int IterationLimit = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("Training......");
                    var MnistDataSet = MnistDataSetLoader.LoadData(MnistPixelFilePath, MnistLabelFilePath);
                    KmeansTrainer <RawImage28x28> kmeansTrainer = new KmeansTrainer <RawImage28x28>(MnistDataSet, 10, ConvDistance, IterationLimit);
                    var TrainResult = kmeansTrainer.Train();

                    Console.WriteLine("Save trained result?[y/n]");
                    if (Console.ReadLine().ToLower().Contains('y'))
                    {
                        TrainResult.SaveToFile(KmeansTrainResultFilePath);
                        Console.WriteLine("Saved at {0}", KmeansTrainResultFilePath);
                    }

                    return(TrainResult);
                }
                else if (input.ToLower().Contains("i"))
                {
                    return(null);
                }
            }
        }