示例#1
0
        public void TestIrisDataset()
        {
            int trainingSamples = IrisDataset.input.Length;

            Backprop bprop = new Backprop(1e-2, abstol: 1e-4, reltol: 1e-7, adjustThreshold: 1e-20);

            bprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            BatchBackprop bbprop = new BatchBackprop(1e-2, abstol: 1e-4, reltol: 1e-7, adjustThreshold: 1e-20);

            bbprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            QProp qprop = new QProp(abstol: 1e-4, reltol: 1e-7, adjustThreshold: 1e-20, InitialLearningRate: 1e-4);

            qprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            StochasticBatch sprop = new StochasticBatch(40, 1e-2);

            sprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            StochasticQprop sqprop = new StochasticQprop(40);

            sqprop.UnknownCaseFaced += AddRule <GaussianRule2>;

            double[][] x;
            double[][] y;
            double[][] tx;
            double[][] ty;
            SampleData(IrisDataset.input, IrisDataset.output, 120, out x, out y, out tx, out ty);

            subtestIris(x, y, tx, ty, bprop);
            subtestIris(x, y, tx, ty, bbprop);
            subtestIris(x, y, tx, ty, qprop);
            subtestIris(x, y, tx, ty, sprop);
            subtestIris(x, y, tx, ty, sqprop);
        }
示例#2
0
        private async void btnCalc_Click(object sender, EventArgs e)
        {
            try
            {
                double[][] x;
                double[][] y;
                double[][] tx;
                double[][] ty;
                SampleData(input, output, input.Count() - int.Parse(txtbxTestCount.Text), out x, out y, out tx, out ty);

                Backprop bprop = new Backprop(1e-2, abstol: 1e-4, reltol: 1e-7, adjustThreshold: 1e-20);
                bprop.UnknownCaseFaced += AddRule <GaussianRule2>;

                await Task.Run(() => Solve(x, y, tx, ty, bprop));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        void Awake()
        {
            //Check if there is already an instance of SoundManager
            if (instance == null)
            {
                //if not, set it to this.
                instance = this;
            }
            //If instance already exists:
            else if (instance != this)
            {
                //Destroy this, this enforces our singleton pattern so there can only be one instance of SoundManager.
                Destroy(gameObject);
            }

            //Set SoundManager to DontDestroyOnLoad so that it won't be destroyed when reloading our scene.
            DontDestroyOnLoad(gameObject);
            Backprop          bprop     = new Backprop(1e-2);
            KMEANSExtractorIO extractor = new KMEANSExtractorIO(5);

            fis = ANFISBuilder <GaussianRule> .Build(gameParams, musicParams, extractor, bprop, 5);
        }
示例#4
0
        public void TestOptimization1()
        {
            Backprop        bprop  = new Backprop(1e-2);
            BatchBackprop   bbprop = new BatchBackprop(1e-2);
            QProp           qprop  = new QProp();
            StochasticBatch sprop  = new StochasticBatch(100, 1e-2);
            StochasticQprop sqprop = new StochasticQprop(100);

            int trainingSamples = 1000;

            double[][] x  = new double[trainingSamples][];
            double[][] y  = new double[trainingSamples][];
            double[][] tx = new double[trainingSamples][];
            double[][] ty = new double[trainingSamples][];

            Random rnd = new Random();

            for (int i = 0; i < trainingSamples; i++)
            {
                double valx = 0.5 - rnd.NextDouble();
                double valy = 0.5 - rnd.NextDouble();

                x[i] = new double[] { valx, valy };
                y[i] = new double[] { 1 };


                valx = 0.5 - rnd.NextDouble();
                valy = 0.5 - rnd.NextDouble();

                tx[i] = new double[] { valx, valy };
                ty[i] = new double[] { 1 };
            }

            subTestOptimization1(bprop, x, y, tx, ty);
            subTestOptimization1(bbprop, x, y, tx, ty);
            subTestOptimization1(qprop, x, y, tx, ty);
            subTestOptimization1(sprop, x, y, tx, ty);
            subTestOptimization1(sqprop, x, y, tx, ty);
        }
示例#5
0
        public void TestOptimization2()
        {
            Backprop        bprop  = new Backprop(1e-2);
            BatchBackprop   bbprop = new BatchBackprop(1e-2);
            QProp           qprop  = new QProp();
            StochasticBatch sprop  = new StochasticBatch(100, 1e-2);
            StochasticQprop sqprop = new StochasticQprop(100);

            int trainingSamples = 100;

            double[][] x  = new double[trainingSamples][];
            double[][] y  = new double[trainingSamples][];
            double[][] tx = new double[trainingSamples][];
            double[][] ty = new double[trainingSamples][];

            Random rnd = new Random();

            for (int i = 0; i < trainingSamples; i++)
            {
                bool   isRigth = i % 2 == 0;
                double valx    = (isRigth ? 1 : -1) + (0.5 - rnd.NextDouble());

                x[i] = new double[] { valx };
                y[i] = new double[] { isRigth ? 1 : 0, isRigth ? 0 : 1 };

                valx = (isRigth ? 1 : -1) + (0.5 - rnd.NextDouble());

                tx[i] = new double[] { valx };
                ty[i] = new double[] { isRigth ? 1 : 0, isRigth ? 0 : 1 };
            }

            subTestOptimization2(bprop, x, y, tx, ty);
            subTestOptimization2(bbprop, x, y, tx, ty);
            subTestOptimization2(qprop, x, y, tx, ty);
            subTestOptimization2(sprop, x, y, tx, ty);
            subTestOptimization2(sqprop, x, y, tx, ty);
        }
示例#6
0
        public static void Main()
        {
            Console.WriteLine("Инициализация обучающей выборки");
            List <double[]> x = new List <double[]>();
            List <double[]> y = new List <double[]>();

            double ar;
            double dr;

            for (double i = 0; i <= 100; i += 1)
            {
                for (double j = 0; j <= 100; j += 1)
                {
                    ar = i;
                    dr = j;
                    //  high 100%
                    if (ar >= 80 && ar <= 100 && dr >= 0 && dr <= 1)
                    {
                        x.Add(new double[] { ar, dr });
                        y.Add(new double[] { 0, 0, 0, 0, 1 });
                    }
                    //  average 100%
                    else if ((ar >= 31 && ar <= 70 && dr >= 0 && dr <= 1) || (ar >= 80 && ar <= 100 && dr > 1 && dr <= 30))
                    {
                        x.Add(new double[] { ar, dr });
                        y.Add(new double[] { 0, 0, 0, 1, 0 });
                    }
                    //  minor 100%
                    else if ((ar >= 4 && ar <= 29 && dr >= 0 && dr <= 1) || (ar >= 31 && ar <= 70 && dr > 1 && dr <= 30) || (ar >= 80 && ar <= 100 && dr >= 40 && dr <= 70))
                    {
                        x.Add(new double[] { ar, dr });
                        y.Add(new double[] { 0, 0, 1, 0, 0 });
                    }
                    //  small 100%
                    else if ((ar >= 0 && ar <= 1 && dr >= 0 && dr <= 1) || (ar >= 4 && ar <= 29 && dr > 1 && dr <= 30) || (ar >= 31 && ar <= 70 && dr >= 40 && dr <= 70) || (ar >= 80 && ar <= 100 && dr >= 90 && dr <= 100))
                    {
                        x.Add(new double[] { ar, dr });
                        y.Add(new double[] { 0, 1, 0, 0, 0 });
                    }
                    //  No 100%
                    else if ((ar >= 0 && ar <= 1 && dr > 4 && dr <= 100) || (ar >= 1 && ar <= 25 && dr >= 30 && dr <= 100) || (ar >= 25 && ar <= 45 && dr >= 60 && dr <= 100) || (ar >= 45 && ar <= 70 && dr >= 90 & dr <= 100))
                    {
                        x.Add(new double[] { ar, dr });
                        y.Add(new double[] { 1, 0, 0, 0, 0 });
                    }
                }
            }

            Backprop bprop = new Backprop(1e-3);

            СMEANSExtractorIO extractor = new СMEANSExtractorIO(5);

            Console.WriteLine("Инициализация ANFIS");
            ANFIS fis = ANFISBuilder <GaussianRule> .Build(x.ToArray(), y.ToArray(), extractor, bprop, 1000);

            bool state = true;

            while (state)
            {
                Console.Write("Введите коэффициент атаки: ");
                string ars = Console.ReadLine();
                if (ars == "q" || ars == "quit" || ars == "Q" || ars == "Quit")
                {
                    state = false;
                    continue;
                }
                ar = Convert.ToDouble(ars);
                Console.Write("Введите коэффициент защиты: ");
                string drs = Console.ReadLine();
                if (drs == "q" || drs == "quit" || drs == "Q" || drs == "Quit")
                {
                    state = false;
                    continue;
                }
                dr = Convert.ToDouble(drs);

                double[] args = new double[] { ar, dr };
                double[] res  = fis.Inference(args);

                int    maxI = 0;
                double max  = res[0];
                for (int I = 1; I < res.Length; I++)
                {
                    if (max < res[I])
                    {
                        maxI = I;
                        max  = res[I];
                    }
                }

                switch (maxI)
                {
                case 0:
                    Console.WriteLine("Вероятнее всего урона не будет");
                    break;

                case 1:
                    Console.WriteLine("Вероятнее всего урон будет очень маленьким");
                    break;

                case 2:
                    Console.WriteLine("Вероятнее всего урон будет незначительным");
                    break;

                case 3:
                    Console.WriteLine("Вероятнее всего урон будет средним");
                    break;

                case 4:
                    Console.WriteLine("Вероятнее всего урон будет большим");
                    break;
                }
            }
            Console.ReadKey();
        }
示例#7
0
        public void TestLogisticMap()
        {
            int trainingSamples = 2000;

            double[][] x  = new double[trainingSamples][];
            double[][] y  = new double[trainingSamples][];
            double[][] tx = new double[trainingSamples][];
            double[][] ty = new double[trainingSamples][];

            double px = 0.1;
            double r  = 3.8;//3.56995;
            double lx = r * px * (1 - px);

            for (int i = 0; i < trainingSamples; i++)
            {
                x[i] = new double[] { px, lx };
                px   = lx;
                lx   = r * lx * (1 - lx);
                y[i] = new double[] { lx };
            }

            for (int i = 0; i < trainingSamples; i++)
            {
                tx[i] = new double[] { px, lx };
                px    = lx;
                lx    = r * lx * (1 - lx);
                ty[i] = new double[] { lx };
            }

            Backprop bprop = new Backprop(1e-2);

            bprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            BatchBackprop bbprop = new BatchBackprop(1e-2);

            bbprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            QProp qprop = new QProp();

            qprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            StochasticBatch sprop = new StochasticBatch(500, 1e-2);

            sprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            StochasticQprop sqprop = new StochasticQprop(500);

            sqprop.UnknownCaseFaced += AddRule <GaussianRule2>;

            subtestLogisticsMap <LinearRule>(x, y, tx, ty, bprop);
            subtestLogisticsMap <LinearRule>(x, y, tx, ty, bbprop);
            subtestLogisticsMap <LinearRule>(x, y, tx, ty, qprop);
            subtestLogisticsMap <LinearRule>(x, y, tx, ty, sprop);
            subtestLogisticsMap <LinearRule>(x, y, tx, ty, sqprop);

            bprop = new Backprop(1e-2);
            bprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            bbprop = new BatchBackprop(1e-2);
            bbprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            qprop = new QProp();
            qprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            sprop = new StochasticBatch(500, 1e-2);
            sprop.UnknownCaseFaced += AddRule <GaussianRule2>;
            sqprop = new StochasticQprop(500);
            sqprop.UnknownCaseFaced += AddRule <GaussianRule2>;

            subtestLogisticsMap <GaussianRule>(x, y, tx, ty, bprop);
            subtestLogisticsMap <GaussianRule>(x, y, tx, ty, bbprop);
            subtestLogisticsMap <GaussianRule>(x, y, tx, ty, qprop);
            subtestLogisticsMap <GaussianRule>(x, y, tx, ty, sprop);
            subtestLogisticsMap <GaussianRule>(x, y, tx, ty, sqprop);
        }