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); }
public static void BipolarNXORExample(ILogger logger) { var neuralNetworkBuilder = new NeuralNetworkBuilder(); var network = neuralNetworkBuilder .AddBiasConnections() .SetActivationFunction(new TANHActivationFunction()) .SetErrorFunction(new MeanSquaredErrorFunction(1)) .SetNumberOfInputNeurons(2) .SetNumberOfHiddenNeurons(3) .SetNumberOfOutputNeurons(1) .Build(); var trainer = new Trainer(neuralNetwork: network, learningRate: 0.01, logger: logger); var trainDataCollection = new[] { new TrainData(new double [] { -1, -1 }, new double [] { 1 }), new TrainData(new double [] { 1, -1 }, new double [] { -1 }), new TrainData(new double [] { -1, 1 }, new double [] { -1 }), new TrainData(new double [] { 1, 1 }, new double [] { 1 }), }; trainer.Train(trainDataCollection, numberOfEpochs: 100000, terminalEpochError: 0.01); TestNetwork(network, trainDataCollection, logger); }