Esempio n. 1
0
        public void Fit(List <List <double> > xs)
        {
            PCANetwork n = (PCANetwork)this.network;
            double     previousTotalWeights = n.CalculateTotalWeights();

            int epoch_executed = 0;

            while (epoch_executed < this.epoch)
            {
                for (var index = 0; index < xs.Count; index++)
                {
                    var x_vector = xs[index];

                    algorithm.Process(x_vector, null);
                }

                epoch_executed++;
                Console.WriteLine(string.Format("SYS: epoch {0} done.", epoch_executed));

                var currentTotalWeights = n.CalculateTotalWeights();
                var diff = Math.Abs(currentTotalWeights - previousTotalWeights);

                previousTotalWeights = currentTotalWeights;

                Console.WriteLine("DIFF:" + diff);

                if (diff <= this.stopCondition)
                {
                    Console.WriteLine("Condition OK");
                    break;
                }
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 public PCATrainer(PCANetwork network, int epoch, PCA algorithm, double stopCondition) : base(network, epoch, algorithm)
 {
     this.stopCondition = stopCondition;
 }
Esempio n. 5
0
 public PCA(PCANetwork network, double learningRate)
 {
     this.network      = network;
     this.learningRate = learningRate;
 }