Beispiel #1
0
        static void Main(string[] args)
        {
            int[] array = { 2, 8, 4 };

            string str = File.ReadAllText("TD1.txt");

            float[][] vs1   = JsonConvert.DeserializeObject <float[][]>(str);
            NNModel   model = new NNModel(array);


            BackPropagation backPropagation = new BackPropagation();

            backPropagation.Learn(model, vs1);

            for (int i = 0; i < vs1.Length; i += 2)
            {
                var inp = vs1[i];
                Array.ForEach(model.Compute(inp).Neurons, x =>
                {
                    Console.WriteLine(x.Value + "  ");
                });
                Console.WriteLine();
            }
            Console.ReadKey();
        }
Beispiel #2
0
        public void Process()
        {
            Console.WriteLine("Please wait, reading MNIST training data.");
            var dir              = AppDomain.CurrentDomain.BaseDirectory;
            var trainingReader   = LearnDigitsBackprop.LoadMNIST(dir, true, MNIST_DEPTH);
            var validationReader = LearnDigitsBackprop.LoadMNIST(dir, false, MNIST_DEPTH);

            Console.WriteLine("Training set size: " + trainingReader.NumImages);
            Console.WriteLine("Validation set size: " + validationReader.NumImages);

            var inputCount  = trainingReader.Data[0].Input.Length;
            var outputCount = trainingReader.Data[0].Ideal.Length;

            var network = new BasicNetwork();

            network.AddLayer(new BasicLayer(null, true, inputCount));
            network.AddLayer(new BasicLayer(new ActivationReLU(), true, 100));
            network.AddLayer(new DropoutLayer(new ActivationReLU(), true, 50, 0.5));
            network.AddLayer(new BasicLayer(new ActivationReLU(), true, 25));
            network.AddLayer(new BasicLayer(new ActivationSoftMax(), false, outputCount));
            network.FinalizeStructure();
            network.Reset();

            // train the neural network
            Console.WriteLine("Training neural network.");
            var train = new BackPropagation(network, trainingReader.Data, 1e-4, 0.9);

            train.L1 = 0;
            train.L2 = 1e-11;

            PerformIterationsClassifyEarlyStop(train, network, validationReader.Data, 5);
        }
Beispiel #3
0
 public ConfigurationFile()
 {
     // Retrieve instances
     annComp      = NinjectBinding.GetKernel.Get <AnnBuild>();
     backPropComp = NinjectBinding.GetKernel.Get <BackPropagation>();
     rPropComp    = NinjectBinding.GetKernel.Get <ResilientPropagation>();
 }
Beispiel #4
0
        public void TrainNetwork()
        {
            List <int> list = new List <int>();

            foreach (int layer in layers)
            {
                list.Add(layer);
            }
            Stream       stream            = assets.Open("Classroom_Occupation_Data.csv", Access.Random);
            StreamReader sr                = new StreamReader(stream);
            string       content           = sr.ReadToEnd();
            StreamWriter destinationStream = new StreamWriter(basePath + "/Classroom_Occupation_Data.csv", false);

            destinationStream.Write(content);
            destinationStream.Flush();
            network     = new MultiLayerPerceptron(TransferFunctionType.Sigmoid, list.ToArray());
            trainingSet = new TrainingSet(inputSize, outputSize);
            trainingSet = TrainingSet.CreateFromFile(basePath + "/Classroom_Occupation_Data.csv", inputSize, outputSize, ",");
            BackPropagation learningRule = new BackPropagation();

            network.LearningRule = learningRule;
            network.Learn(trainingSet);
            network.Save(basePath + "/TrainTest.nnet");
            destinationStream.Close();
            destinationStream.Dispose();
        }
        public BackPropagationPerformanceComparisonContainer()
        {
            var neuralNetworkUnderTest =
                NeuralNetwork
                .For(NeuralNetworkContext.MaximumPrecision)
                .WithInputLayer(neuronCount: 5, activationType: ActivationType.Sigmoid)
                .WithHiddenLayer(neuronCount: 100, activationType: ActivationType.Sigmoid)
                .WithHiddenLayer(neuronCount: 70, activationType: ActivationType.TanH)
                .WithHiddenLayer(neuronCount: 40, activationType: ActivationType.TanH)
                .WithHiddenLayer(neuronCount: 100, activationType: ActivationType.Sigmoid)
                .WithOutputLayer(neuronCount: 2, activationType: ActivationType.Sigmoid)
                .Build();

            trainingData = new[] {
                TrainingDataSet.For(new [] { 0.78, 0.99, 0.67, 0.72, 0.22 }, new [] { 0.12, 0.14 })
            };

            multiThreadedController = TrainingController.For(
                BackPropagation
                .WithConfiguration(neuralNetworkUnderTest, ParallelOptionsExtensions.UnrestrictedMultiThreadedOptions));

            singleThreadedController = TrainingController.For(
                BackPropagation
                .WithConfiguration(neuralNetworkUnderTest, ParallelOptionsExtensions.SingleThreadedOptions));
        }
Beispiel #6
0
        static void Testing()
        {
            int[] array = { 10, 20, 2 };

            string str = File.ReadAllText("TD1.txt");

            double[][] vs1   = JsonConvert.DeserializeObject <double[][]>(str);
            NNModel    model = new NNModel(array);

            Console.Beep();
            var             watch           = System.Diagnostics.Stopwatch.StartNew();
            BackPropagation backPropagation = new BackPropagation();

            backPropagation.Learn(model, vs1);
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds);
            string str1 = File.ReadAllText("TD2.txt");

            double[][] vs2 = JsonConvert.DeserializeObject <double[][]>(str1);
            for (int i = 0; i < vs2.Length; i++)
            {
                model.Compute(NNModel.ReculcArray(vs2[i])).Neurons.ForEach(x =>
                {
                    Console.WriteLine(x.Value + "  ");
                });
                Console.WriteLine();
            }
            Console.WriteLine("_______");
            model.Save();
            Console.Beep();
            Console.ReadKey();
        }
Beispiel #7
0
        static void NewNN(string[] args)
        {
            int[] array = new int[args.Length - 1];
            for (int i = 1; i < args.Length; i++)
            {
                if (Int32.TryParse(args[i], out int res))
                {
                    array[i] = res;
                }
                else
                {
                    return;
                }
            }
            string str = File.ReadAllText(args[0]);

            double[][] vs1 = JsonConvert.DeserializeObject <double[][]>(str);

            NNModel         model           = new NNModel(array);
            BackPropagation backPropagation = new BackPropagation();

            backPropagation.Learn(model, vs1);

            for (int i = 0; i < vs1.Length; i += 2)
            {
                var inp = vs1[i];
                model.Compute(inp).Neurons.ForEach(x =>
                {
                    Console.WriteLine(x.Value + "  ");
                });
                Console.WriteLine();
            }
            Console.ReadKey();
        }
Beispiel #8
0
        public static void Main(string[] args)
        {
            //create training set from Data.DIGITS
            DataSet dataSet = generateTraining();

            int inputCount    = Data.CHAR_HEIGHT * Data.CHAR_WIDTH;
            int outputCount   = Data.DIGITS.Length;
            int hiddenNeurons = 19;


            //create neural network
            MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputCount, hiddenNeurons, outputCount);
            //get backpropagation learning rule from network
            BackPropagation learningRule = neuralNet.LearningRule;

            learningRule.LearningRate  = 0.5;
            learningRule.MaxError      = 0.001;
            learningRule.MaxIterations = 5000;

            //add learning listener in order to print out training info
            learningRule.addListener(new LearningEventListenerAnonymousInnerClassHelper());

            //train neural network
            neuralNet.learn(dataSet);

            //train the network with training set
            testNeuralNetwork(neuralNet, dataSet);
        }
Beispiel #9
0
        public static bool Test4()
        {
            var xorinput  = new[] { new[] { 0.0, 0.0 }, new[] { 1.0, 0.0 }, new[] { 0.0, 1.0 }, new[] { 1.0, 1.0 } };
            var xoroutput = new[] { new[] { 0.0 }, new[] { 1.0 }, new[] { 1.0 }, new[] { 0.0 } };
            var mlp       = new MLP(2, 4, 1);
            var stsp      = new StandardTrainingSetProvider(xorinput, xoroutput);

            stsp.Split();
            var gdbp = new BackPropagation(mlp, stsp);

            ((GD)gdbp.Solver).Criterion = LearningCriterion.CrossEntropy;
            //((GD)gdbp.Solver).LearningRate = .01;
            ((GD)gdbp.Solver).AdaGrad = true;

            var minerr = double.MaxValue;

            gdbp.ReportReady += optimizer =>
            {
                Console.WriteLine("Epoch = {0}, Error = {1}", optimizer.CurrentEpoch,
                                  optimizer.TrainingSetProvider.TrainError);
                minerr = Math.Min(minerr, optimizer.Solver.Error);

                if (optimizer.Done)
                {
                    Console.ReadLine();
                }
            };

            gdbp.RunAsync().Wait();
            return(true);
        }
Beispiel #10
0
        /// <summary>
        ///     The entry point for this example.  If you would like to make this example
        ///     stand alone, then add to its own project and rename to Main.
        /// </summary>
        /// <param name="args">Not used.</param>
        public static void ExampleMain(string[] args)
        {
            var network = new BasicNetwork();

            network.AddLayer(new BasicLayer(null, true, 2));
            network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 5));
            network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 1));
            network.FinalizeStructure();
            network.Reset();

            var trainingData = BasicData.ConvertArrays(XOR_INPUT, XOR_IDEAL);

            // train the neural network
            var train = new BackPropagation(network, trainingData, 0.7, 0.9);

            var epoch = 1;

            do
            {
                train.Iteration();
                Console.WriteLine("Epoch #" + epoch + " Error:" + train.LastError);
                epoch++;
            } while (train.LastError > 0.01);

            // test the neural network
            Console.WriteLine("Neural Network Results:");
            for (var i = 0; i < XOR_INPUT.Length; i++)
            {
                var output = network.ComputeRegression(XOR_INPUT[i]);
                Console.WriteLine(string.Join(",", XOR_INPUT[i])
                                  + ", actual=" + string.Join(",", output)
                                  + ",ideal=" + string.Join(",", XOR_IDEAL[i]));
            }
        }
            public virtual void handleLearningEvent(LearningEvent @event)
            {
                BackPropagation bp = (BackPropagation)@event.Source;

                Console.WriteLine("Current iteration: " + bp.CurrentIteration);
                Console.WriteLine("Error: " + bp.TotalNetworkError);
            }
Beispiel #12
0
        static void TestANNMiner(Dataset dataset)
        {
            IClassificationMeasure measure        = new AccuracyMeasure();
            ILearningMethod        learningMethod = new BackPropagation(0.1, 10, 0.9, false);

            int hiddenUnitCount = dataset.Metadata.Attributes.Length * dataset.Metadata.Target.Length;

            IActivationFunction activationFunction = new SigmoidActivationFunction();

            ISolutionQualityEvaluator <ConnectionDC> evaluator  = new NNClassificationQualityEvaluator(measure, learningMethod, hiddenUnitCount, activationFunction);
            IHeuristicsCalculator <ConnectionDC>     calculator = new DefaultHeuristicCalculator <ConnectionDC>();
            ILocalSearch <ConnectionDC>          localSearch    = new DefaultRemovalLocalSearch <ConnectionDC>(evaluator);
            IComponentInvalidator <ConnectionDC> invalidator    = new NNConnectorInvalidator();

            Problem <ConnectionDC> problem = new Problem <ConnectionDC>(invalidator, calculator, evaluator, localSearch);

            NeuralNetwork network_before = null;
            NeuralNetwork network_final  = SingleTest.CreateNeuralNet_ANNMiner(problem, hiddenUnitCount, true, false, dataset, ref network_before);

            double quilty_before = SingleTest.TestClassifier(network_before, dataset, measure);
            double quilty_final  = SingleTest.TestClassifier(network_final, dataset, measure);

            Console.WriteLine("ANN -" + quilty_before);
            Console.WriteLine("ANN -" + quilty_final);
        }
Beispiel #13
0
 void Start()
 {
     backpro = new BackPropagation(NumInput, NumHidden, NumOutput);
     if (trained == false)
     {
         Train();
     }
 }
Beispiel #14
0
        public void CreateBackPropagationTrainingAlgorithm(AnnBuild annComp, BackPropagation prop)
        {
            errorTarget = annComp.ErrorTarget;
            network.InstantiateBackPropagationAlgorithm(
                errorTarget, annComp.MaxEpochs, prop.LearningRate, prop.Beta);

            network.BuildStatsListener();
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            int[] layerSizes = new int[3] {
                2, 2, 1
            };
            TransferFunction[] tFuncs = new TransferFunction[3] {
                TransferFunction.None,
                TransferFunction.Sigmoid,
                TransferFunction.Linear
            };
            BackPropagation bpn = new BackPropagation(layerSizes, tFuncs);

            double[][] input, output;
            input = new double[4][]; output = new double[4][];
            for (int i = 0; i < 4; i++)
            {
                input[i] = new double[2]; output[i] = new double[1];
            }
            input[0][0] = 0.0; input[0][1] = 0.0; output[0][0] = 0.0; // Case 1 F xor F = F
            input[1][0] = 1.0; input[1][1] = 0.0; output[1][0] = 1.0; // Case 2 T xor F = T
            input[2][0] = 0.0; input[2][1] = 1.0; output[2][0] = 1.0; // Case 3 F xor T = T
            input[3][0] = 1.0; input[3][1] = 1.0; output[3][0] = 0.0; // Case 4 T xor T = F

            // Train
            double error = 0.0;
            int    max_count = 10000, count = 0;

            do
            {
                // Prepare training epoch
                count++;
                error = 0.0;

                // Train
                for (int i = 0; i < 4; i++)
                {
                    // TrainRate and Momentm picked arbitrarilly
                    error += bpn.Train(ref input[i], ref output[i], 0.15, 0.10);
                }
                // Show Progress
                if (count % 100 == 0)
                {
                    Console.WriteLine("Epoch {0} completed with error {1:0.0000}", count, error);
                }
            } while (error > 0.0001 && count <= max_count);
            // Display results

            double[] networkOutput = new double[1];
            for (int i = 0; i < 4; i++)
            {
                bpn.Run(ref input[i], out networkOutput);
                Console.WriteLine("Case {3}: {0:0.0} xor {1:0.0} = {2:0.0000}", input[i][0], input[i][1], networkOutput[0], i + 1);
            }

            // End Program
            Console.WriteLine("Press Enter ...");
            Console.ReadLine();
        }
Beispiel #16
0
    //creates an instance of the backpropagation with corresponding number of nodes and weights
    void Start()
    {
        bpro    = new BackPropagation(NumInput, NumHidden, NumOutput);
        pass    = false;
        weights = new double[2451];
        tint    = GameObject.Find("playerInputs").GetComponent <throwinputs>();

        Debug.Log("tssss");
    }
        public virtual void handleLearningEvent(LearningEvent @event)
        {
            BackPropagation bp = (BackPropagation)@event.Source;

            if (@event.EventType != LearningEvent.Type.LEARNING_STOPPED)
            {
                Console.WriteLine(bp.CurrentIteration + ". iteration : " + bp.TotalNetworkError);
            }
        }
        String GetCommandFromBackPropagation(int[,] sensorData, int sensorType)
        {
            int[,] processedSensorData = GetProcessedSensorData(sensorData);
            var robotCommand =
                BackPropagation.Driver("Command", _sensorTypeString[sensorType],
                                       convertToOneDimensionalDouble(processedSensorData));

            return(robotCommand);
        }
Beispiel #19
0
        private void BtnEntrenar_Click(object sender, EventArgs e)
        {
            if (TxtTipoRed.SelectedItem.ToString().Equals("Perceptrón Multicapa"))
            {
                percetronMulticapa = new PercetronMulticapa();


                percetronMulticapa.NumeroEntradas = entradas;
                percetronMulticapa.NumeroSalidas  = salidas;
                percetronMulticapa.NumeroPatrones = patrones;

                percetronMulticapa.NumeroCapas                 = NumeroDeCapas;
                percetronMulticapa.NumeroNeuronasCapas         = ListaNumeroNeuronasCapas;
                percetronMulticapa.FuncionesActivacionCapas    = FuncionActivacionCapas;
                percetronMulticapa.NumeroIteraciones           = Convert.ToInt32(TxtNumeroIteraciones.Value.ToString());
                percetronMulticapa.RataAprendizaje             = Convert.ToDouble(TxtRataAprendizaje.Value.ToString());
                percetronMulticapa.ErrorMaximoPermitido        = Convert.ToDouble(TxtErrorMaximoPermitido.Value.ToString());
                percetronMulticapa.FuncionActivacionCapaSalida = CbxFuncionActivacionCapaSalida.SelectedItem.ToString();
                percetronMulticapa.Umbrales = arraydeumbrales;
                percetronMulticapa.Pesos    = arraydematrizdepesos;
            }
            else
            {
                backPropagation = new BackPropagation();

                backPropagation.NumeroEntradas = entradas;
                backPropagation.NumeroSalidas  = salidas;
                backPropagation.NumeroSalidas  = patrones;

                backPropagation.NumeroCapas                 = NumeroDeCapas;
                backPropagation.NumeroNeuronasCapas         = ListaNumeroNeuronasCapas;
                backPropagation.FuncionesActivacionCapas    = FuncionActivacionCapas;
                backPropagation.NumeroIteraciones           = Convert.ToInt32(TxtNumeroIteraciones.Value.ToString());
                backPropagation.RataAprendizaje             = Convert.ToDouble(TxtRataAprendizaje.Value.ToString());
                backPropagation.ErrorMaximoPermitido        = Convert.ToDouble(TxtErrorMaximoPermitido.Value.ToString());
                backPropagation.FuncionActivacionCapaSalida = CbxFuncionActivacionCapaSalida.SelectedItem.ToString();
                backPropagation.Umbrales = arraydeumbrales;
                backPropagation.Pesos    = arraydematrizdepesos;



                MessageBox.Show("Numero entradas: " + backPropagation.NumeroEntradas.ToString() + "" +
                                "NumeroSalidas: " + backPropagation.NumeroSalidas.ToString() + "" +
                                "NumeroPatrones: " + backPropagation.NumeroPatrones.ToString() + "" +
                                "NumeroCapas: "******"" +
                                "NumeroNeuronasCapas: "******"" +
                                "FuncionActivacionCapas: "******"" +
                                "NumeroIteraciones: " + backPropagation.NumeroIteraciones.ToString() + "" +
                                "RataAprendizaje: " + backPropagation.RataAprendizaje.ToString() + "" +
                                "ErrorMaximoPermitido: " + backPropagation.ErrorMaximoPermitido.ToString() + "" +
                                "FuncionActivacionCapaSalida: " + backPropagation.FuncionActivacionCapaSalida.ToString() + "" +
                                "Umbrales: " + backPropagation.Umbrales[0].ToString() + "" +
                                "Pesos: " + backPropagation.Pesos[0, 0].ToString() + "", "algo");
            }
        }
Beispiel #20
0
            public double Train(double[] input, double[] output, BackPropagation trainer)
            {
                // Run the given input throug the network in order to obtain output
                m_Network.Run (input);
                // Calculate network error between the generated output and the expected output
                double error = CalculateError (output);
                // Update the network to remedy the calculated error
                Update (input, trainer.LearningRate, trainer.Momentum);

                return error;
            }
Beispiel #21
0
        private void testWithParametr(AlgorithmConfig configuration, Vector[] learnVectors, int classes)
        {
            neuronsCount = null;
            int layersCount = (int)hiddenLayers.Value + 1;

            switch (layersCount)
            {
            case 2:
            {
                neuronsCount    = new int[1];
                neuronsCount[0] = (int)firstLayerNeurons.Value;
            } break;

            case 3:
            {
                neuronsCount    = new int[2];
                neuronsCount[0] = (int)firstLayerNeurons.Value;
                neuronsCount[1] = (int)secondtLayerNeurons.Value;
            } break;

            case 4:
            {
                neuronsCount    = new int[3];
                neuronsCount[0] = (int)firstLayerNeurons.Value;
                neuronsCount[1] = (int)secondtLayerNeurons.Value;
                neuronsCount[2] = (int)thirdtLayerNeurons.Value;
            } break;
            }

            beta  = 0.7;
            myNet = new NeuralNetwork(layersCount, neuronsCount, learnVectors[0].input.Length, classes, beta);
            List <Vector> data = new List <Vector>(learnVectors.Length);

            data.AddRange(learnVectors);
            switch (algorithmBox.SelectedIndex)
            {
            case 0:
            {
                BackPropagation method = new BackPropagation(configuration);
                method.RaiseMessageEvent += AddMessage;
                method.Train(myNet, data);
                break;
            }

            case 1:
            {
                QuickProp method = new QuickProp(configuration);
                method.RaiseMessageEvent += AddMessage;
                method.Train(myNet, data);
                break;
            }
            }
        }
        public BackPropagationTester QueueTrainingEpoch(
            Action <TrainingEpochTester <BackPropagation> > action,
            ParallelOptions parallelOptions)
        {
            var backPropagationTrainer = BackPropagation.WithConfiguration(targetNeuralNetwork, parallelOptions, learningRate, momentum);
            var epochTester            = TrainingEpochTester <BackPropagation> .For(backPropagationTrainer);

            action.Invoke(epochTester);

            trainingStates.Add(epochTester);
            return(this);
        }
Beispiel #23
0
            public virtual void handleLearningEvent(LearningEvent @event)
            {
                BackPropagation bp = (BackPropagation)@event.Source;

                LOG.info("Epoch no#: [{}]. Error [{}]", bp.CurrentIteration, bp.TotalNetworkError);
                LOG.info("Epoch execution time: {} sec", (DateTimeHelperClass.CurrentUnixTimeMillis() - start) / 1000.0);
                // neuralNetwork.save(bp.getCurrentIteration() + "_MNIST_CNN-MIC.nnet");

                start = DateTimeHelperClass.CurrentUnixTimeMillis();
                //  if (bp.getCurrentIteration() % 5 == 0)
                //      Evaluation.runFullEvaluation(neuralNetwork, testSet);
            }
Beispiel #24
0
        public BackPropagation GetLearningMethod(object owner, IContextLookup globalVars, BasicNetwork theNetwork,
                                                 IList <BasicData> data)
        {
            double theLearningRate = LearningRate.GetValue(owner, globalVars);
            double theMomentum     = Momentum.GetValue(owner, globalVars);
            var    theL1           = L1.GetValue(owner, globalVars);
            var    theL2           = L2.GetValue(owner, globalVars);
            var    toReturn        = new BackPropagation(theNetwork, data, theLearningRate, theMomentum);

            toReturn.L1 = theL1;
            toReturn.L2 = theL2;
            return(toReturn);
        }
        private void TrainNeuralNetworks(int algorithmType, int sensorType)
        {
            switch (algorithmType)
            {
            case (int)AlgorithmType.BackPropagation:
                BackPropagation.Driver("Train", _sensorTypeString[sensorType], null);
                break;

            case (int)AlgorithmType.FeedForward:
                forwardManager.GetDirectionFromFeedForward(_sensorTypeString[sensorType], new float[] { }, 0);
                break;
            }
        }
Beispiel #26
0
        private void UczenieSieci_Click(object sender, RoutedEventArgs e)
        {
            myVector x = bow.GetVectorsList()[0];

            BackPropagation.UczenieSieci(200, test.GetTrainingtVectors(), NeuralNetwork, classes);
            Console.Beep();

            foreach (myVector testvector in test.GetTestVectors())
            {
                int id     = NeuralConstruction.SampleInput(testvector, NeuralNetwork);
                var output = NeuralNetwork.getNetwork().Where(o => o.type == 2).ToList();
            }
            UczenieSieci.IsEnabled = false;
        }
        public virtual void handleLearningEvent(LearningEvent @event)
        {
            BackPropagation bp = (BackPropagation)@event.Source;

            if (@event.EventType.Equals(LearningEvent.Type.LEARNING_STOPPED))
            {
                double error = bp.TotalNetworkError;
                Console.WriteLine("Training completed in " + bp.CurrentIteration + " iterations, ");
                Console.WriteLine("With total error: " + formatDecimalNumber(error));
            }
            else
            {
                Console.WriteLine("Iteration: " + bp.CurrentIteration + " | Network error: " + bp.TotalNetworkError);
            }
        }
        public async Task TrainConfiguredNetworkForEpochs(
            int epochs,
            NeuralNetworkTrainingConfiguration trainingConfig)
        {
            var trainingData = dataProvider.TrainingData
                               .Select(transaction => transaction.ToTrainingData())
                               .ToList();

            await TrainingController.For(BackPropagation.WithConfiguration(
                                             networkAccessor.TargetNetwork,
                                             ParallelOptionsExtensions.MultiThreadedOptions(trainingConfig.ThreadCount),
                                             trainingConfig.LearningRate,
                                             trainingConfig.Momentum))
            .TrainForEpochsOrErrorThresholdMet(trainingData, epochs, trainingConfig.MinimumErrorThreshold);
        }
Beispiel #29
0
        public static NeuralNetwork CreateNeuralNet_BP(Dataset trainingset, int hiddenUnitCount, double positiveClassValue, double learningRate, int epochCount, IActivationFunction activationFunction)
        {
            counter = 0;

            //MSError measure = new MSError();
            //AccuracyMeasure measure = new AccuracyMeasure();

            Connection[]    connections = NeuralNetwork.Create3LayerConnectedConnections(trainingset.Metadata, hiddenUnitCount);
            NeuralNetwork   network     = new NeuralNetwork(trainingset.Metadata, hiddenUnitCount, activationFunction, connections);
            BackPropagation BP          = new BackPropagation(learningRate, epochCount, positiveClassValue, true);

            BP.OnPostEpoch += new EventHandler(OnPostEpoch);

            BP.TrainNetwork(network, trainingset);
            return(network);
        }
Beispiel #30
0
        public async void CanSuccessfullySolveXorProblemTrainingForErrorThreshold()
        {
            var neuralNetwork = NeuralNetwork.For(NeuralNetworkContext.MaximumPrecision)
                                .WithInputLayer(neuronCount: 2, activationType: ActivationType.Sigmoid)
                                .WithHiddenLayer(neuronCount: 2, activationType: ActivationType.TanH)
                                .WithOutputLayer(neuronCount: 1, activationType: ActivationType.Sigmoid)
                                .Build();

            await TrainingController
            .For(BackPropagation.WithConfiguration(
                     neuralNetwork,
                     ParallelOptionsExtensions.UnrestrictedMultiThreadedOptions,
                     learningRate: 0.4,
                     momentum: 0.9))
            .TrainForErrorThreshold(XorTrainingData(), minimumErrorThreshold: 0.01);

            AssertPredictionsForTrainedNeuralNetwork(neuralNetwork);
        }
        public async void CanSuccessfullySolveIrisProblemTrainingForEpochs()
        {
            var neuralNetwork = NeuralNetwork.For(NeuralNetworkContext.MaximumPrecision)
                                .WithInputLayer(neuronCount: 4, activationType: ActivationType.Sigmoid)
                                .WithHiddenLayer(neuronCount: 8, activationType: ActivationType.Sigmoid)
                                .WithHiddenLayer(neuronCount: 5, activationType: ActivationType.Sigmoid)
                                .WithOutputLayer(neuronCount: 3, activationType: ActivationType.TanH)
                                .Build();

            await TrainingController
            .For(BackPropagation.WithConfiguration(
                     neuralNetwork,
                     ParallelOptionsExtensions.UnrestrictedMultiThreadedOptions,
                     learningRate: 1.15,
                     momentum: 0.4))
            .TrainForEpochs(IrisDataSet.TrainingData, maximumEpochs: 1000);

            AssertPredictionsForTrainedNeuralNetwork(neuralNetwork);
        }
Beispiel #32
0
    IEnumerator Start()
    {
        m_Running = true;

        Debug.Log ("Starting test");

        yield return null;

        Debug.Log ("Setup");

        m_Network = new Network (InputCount, LayerCounts);
        if (m_Randomize)
        {
            m_Network.RandomizeWeights ();
        }

        BackPropagation teacher = new BackPropagation (m_Network)
        {
            LearningRate = this.LearningRate,
            Momentum = this.Momentum
        };

        if (m_LearningCurve != null)
        {
            m_LearningCurve.Curve.keys = new Keyframe[] {};
        }

        if (m_Step)
        {
            Debug.Break ();
        }

        yield return null;

        Debug.Log ("Start training");

        while (m_Running && enabled && Application.isPlaying)
        {
            double error = teacher.TrainSet (Input, Output);

            LogResult ("Training run error: " + error);

            if (m_LearningCurve != null)
            {
                m_LearningCurve.Curve.AddKey (Time.time, (float)error);
            }

            if (error < m_TargetError)
            {
                Debug.Log (string.Format ("Achieved error {0}, beating target {1}", error, m_TargetError));
                yield break;
            }

            if (m_Step)
            {
                Debug.Break ();
            }

            yield return null;
        }
    }