Exemple #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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }