private TrainStats ExecuteSingleIteration(ArchitectureTestConfig config)
        {
            var neuralNetworkBuilder = new NeuralNetworkBuilder()
                                       .SetActivationFunction(new SigmoidActivationFunction())
                                       .SetErrorFunction(new MeanSquaredErrorFunction(1))
                                       .SetNumberOfInputNeurons(2)
                                       .SetNumberOfHiddenNeurons(config.NumberOfHiddenNeurons)
                                       .SetNumberOfOutputNeurons(1);

            if (config.EnableBias)
            {
                neuralNetworkBuilder.AddBiasConnections();
            }

            var network = neuralNetworkBuilder.Build();

            var trainer             = new Trainer(neuralNetwork: network, learningRate: 0.01, logger: new DummyLogger());
            var trainDataCollection = new[]
            {
                new TrainData(new double [] { 0, 0 }, new double [] { 1 }),
                new TrainData(new double [] { 1, 0 }, new double [] { 0 }),
                new TrainData(new double [] { 0, 1 }, new double [] { 0 }),
                new TrainData(new double [] { 1, 1 }, new double [] { 1 }),
            };
            var trainStats = trainer.Train(trainDataCollection, numberOfEpochs: _maxNumberOfEpochs, terminalEpochError: _terminalEpochError);

            return(trainStats);
        }
Esempio n. 2
0
        public static trainerParams BuildNet(FlowLayoutPanel layers, FileDialog LoadData_dlg, Result r, Telerik.WinControls.UI.RadDiagram radDiagram1)
        {
            Training.Trainer     trainer = new Training.Trainer();
            NeuralNetworkBuilder b       = new NeuralNetworkBuilder();
            L_ctrl_mat           temp;
            int neuronsnumber;
            IActivatorFunction AF = null;
            FunctionApplier    functionApplier = new FunctionApplier();

            foreach (var layer in layers.Controls)
            {
                temp          = layer as L_ctrl_mat;
                neuronsnumber = Convert.ToInt16(temp.NN_drpdn.Value);
                if (ActivatorFunctions.FunctionName.SIGMOID.ToString() == temp.AF_drpdn.SelectedItem.Text)
                {
                    AF = new SigmoidFunction();
                    imgs.Add(Resources.Layer__Sigmoid);
                }
                if (ActivatorFunctions.FunctionName.TANH.ToString() == temp.AF_drpdn.SelectedItem.Text)
                {
                    AF = new TanhFunction();
                    imgs.Add(Resources.Layer_Tan_H);
                }
                functionApplier.ActivatorFunction = AF;
                b.Layer(neuronsnumber, functionApplier, (double)temp.Lr_drpdn.Value);
            }
            NeuralNetwork.NeuralNetwork nn = b.Build();
            string FileName = LoadData_dlg.FileName;
            var    tuples   = DataReader.DataReader.Instance.ReadFromFile(FileName);

            var inputs  = tuples.Item1;
            var outputs = tuples.Item2;

            // StaticDivider Divider = new StaticDivider(.6,.3);
            //var temp2 = Divider.Divide(inputs, outputs);
            //ActivatorFunctions.FunctionName applier ;

            //// test case (should belong to the second class = [0 1 0])
            //var tt = nn.ForwardInput(Vector<double>.Build.DenseOfArray(new double[] { 5.5, 2.5, 4.0, 1.3 }));
            Params       = new trainerParams();
            Params.nn    = nn;
            Params.Tuple = tuples;
            NetGraph(nn, radDiagram1);

            return(Params);
        }