Exemplo n.º 1
0
        public static void Demo()
        {
            PCANetwork network = PCANetwork.Create(64, 8);

            var dataSet = DataGenerator.GenerateDataSet1();

            var pca = new PCA(network, 0.7);

            PCATrainer trainer = new PCATrainer(network, 50, pca, 0.00000005);

            Normalizer3 normalizer = new Normalizer3();

            //Normalizer normalizer = new Normalizer();

            normalizer.Fit(dataSet.XList);

            var normalizedX = normalizer.Normalize(dataSet.XList);


            Utils.DisplayListList(dataSet.XList);
            Console.WriteLine("--------------------------");
            Utils.DisplayListList(normalizedX);

            //Utils.DisplayListList(normalizer.DeNormalize(normalizedX));

            trainer.Fit(normalizedX);

            List <List <double> > convertedX = trainer.GetConvertedDim(normalizedX);

            //convertedX=normalizer.DeNormalize(convertedX);

            BPNetwork bpNetwork = BPNetwork.Create(8, new int[] { 4 /*, 4, 3*/ }, 3, ActivationFunction.SIGMOID, ActivationFunction.SIGMOID);

            var       bp        = new BP(bpNetwork, 0.6);
            BPTrainer bpTrainer = new BPTrainer(bpNetwork, 2000, bp);

            bpTrainer.Fit(convertedX, dataSet.YList);

            List <List <double> > predicted_ys = bpTrainer.Predict(convertedX);

            CorrectCalculator correctCalculator = new CorrectCalculator();

            var convertedPredictValue = NeuronOutputConverter.OrderInteger(predicted_ys);

            double correct = correctCalculator.Calculate(convertedPredictValue, dataSet.YList);

            Console.WriteLine("Score: {0}%", correct * 100);
        }
Exemplo n.º 2
0
        public static void Demo()
        {
            PCANetwork network = PCANetwork.Create(2, 1);

            var dataSet = DataGenerator.GenerateDataSet2();

            var pca = new PCA(network, 0.7);

            PCATrainer trainer = new PCATrainer(network, 50, pca, 0.0000005);

            Normalizer2 normalizer = new Normalizer2();

            normalizer.Fit(dataSet.XList);

            var normalizedX = normalizer.Normalize(dataSet.XList);

            trainer.Fit(normalizedX);

            List <List <double> > convertedX = trainer.GetConvertedDim(normalizedX);

            List <List <double> > denormalX = normalizer.DeNormalize(convertedX);

            network.Display();

            Console.WriteLine("OLD VECTORS===>");
            Utils.DisplayListList(dataSet.XList);

            Console.WriteLine("OLD VECTORS(NORMALIZED)===>");
            Utils.DisplayListList(normalizedX);

            Console.WriteLine("NEW VECTORS(NORMALIZED)===>");
            Utils.DisplayListList(convertedX);

            Console.WriteLine("NEW VECTORS===>");
            Utils.DisplayListList(denormalX);
        }