public void testDataSetPopulation() { DataSet irisDataSet = DataSetFactory.getIrisDataSet(); INumerizer numerizer = new IrisDataSetNumerizer(); NeuralNetworkDataSet innds = new IrisNeuralNetworkDataSet(); innds.CreateExamplesFromDataSet(irisDataSet, numerizer); NeuralNetworkConfig config = new NeuralNetworkConfig(); config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_INPUTS, 4); config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_OUTPUTS, 3); config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_HIDDEN_NEURONS, 6); config.SetConfig(FeedForwardNeuralNetwork.LOWER_LIMIT_WEIGHTS, -2.0); config.SetConfig(FeedForwardNeuralNetwork.UPPER_LIMIT_WEIGHTS, 2.0); FeedForwardNeuralNetwork ffnn = new FeedForwardNeuralNetwork(config); ffnn.SetTrainingScheme(new BackPropagationLearning(0.1, 0.9)); ffnn.TrainOn(innds, 10); innds.RefreshDataset(); ffnn.TestOnDataSet(innds); }
internal static void backPropogationDemo() { try { DataSet irisDataSet = DataSetFactory.getIrisDataSet(); INumerizer numerizer = new IrisDataSetNumerizer(); NeuralNetworkDataSet innds = new IrisNeuralNetworkDataSet(); innds.CreateExamplesFromDataSet(irisDataSet, numerizer); NeuralNetworkConfig config = new NeuralNetworkConfig(); config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_INPUTS, 4); config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_OUTPUTS, 3); config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_HIDDEN_NEURONS, 6); config.SetConfig(FeedForwardNeuralNetwork.LOWER_LIMIT_WEIGHTS, -2.0); config.SetConfig(FeedForwardNeuralNetwork.UPPER_LIMIT_WEIGHTS, 2.0); FeedForwardNeuralNetwork ffnn = new FeedForwardNeuralNetwork(config); ffnn.SetTrainingScheme(new BackPropagationLearning(0.1, 0.9)); ffnn.TrainOn(innds, 1000); innds.RefreshDataset(); int[] result = ffnn.TestOnDataSet(innds); System.Console.WriteLine(result[0] + " right, " + result[1] + " wrong"); } catch (Exception e) { throw e; } }
public static NeuralNetwork GetBrain() { if (_brain == null) { NeuralNetworkConfig nnConfig = new NeuralNetworkConfig(); nnConfig.AddLayer(LayerType.Input, 5); //Vision inouts nnConfig.AddLayer(LayerType.Intermediate, 12, ActivationType.LeakyRelu); nnConfig.AddLayer(LayerType.Output, 5, ActivationType.LeakyRelu); //Movement decisions. _brain = new NeuralNetwork(nnConfig, 0.02f); for (int i = 0; i < 10000; i++) { //Left side detection, go right. _brain.BackPropagate(TrainingScenerio(1, 0, 0, 0, 0), TrainingDecision(1, 1, 1, 1, 0)); _brain.BackPropagate(TrainingScenerio(0, 1, 0, 0, 0), TrainingDecision(1, 1, 1, 1, 0)); _brain.BackPropagate(TrainingScenerio(1, 1, 0, 0, 0), TrainingDecision(1, 1, 1, 1, 0)); //Right side detection, go left. _brain.BackPropagate(TrainingScenerio(0, 0, 0, 0, 1), TrainingDecision(1, 0, 1, 1, 0)); _brain.BackPropagate(TrainingScenerio(0, 0, 0, 1, 0), TrainingDecision(1, 0, 1, 1, 0)); _brain.BackPropagate(TrainingScenerio(0, 0, 0, 1, 1), TrainingDecision(1, 0, 1, 1, 0)); //Front side detection, so left or right. _brain.BackPropagate(TrainingScenerio(0, 0, 1, 0, 0), TrainingDecision(1, 0, 1, 1, 0)); _brain.BackPropagate(TrainingScenerio(0, 1, 1, 1, 0), TrainingDecision(1, 1, 1, 1, 0)); _brain.BackPropagate(TrainingScenerio(1, 1, 1, 1, 1), TrainingDecision(1, 1, 1, 1, 0)); //No objects dection, speed up and cruise. _brain.BackPropagate(TrainingScenerio(0, 0, 0, 0, 0), TrainingDecision(0.4f, 0.4f, 0.4f, 0.9f, 0.9f)); } } return _brain.Clone(); }
private static void Start() { NeuralNetworkConfig nnConfig = new NeuralNetworkConfig(); nnConfig.AddLayer(LayerType.Input, 3); nnConfig.AddLayer(LayerType.Intermediate, 5, ActivationType.LeakyRelu); nnConfig.AddLayer(LayerType.Output, 1, ActivationType.LeakyRelu); nn = new NeuralNetwork(nnConfig, 0.01f); nn.Load("C:\\network.txt"); //Train the network for (int i = 0; i < 20000; i++) { nn.BackPropagate(new float[] { 0, 0, 0 }, new float[] { 0 }); nn.BackPropagate(new float[] { 1, 0, 0 }, new float[] { 1 }); nn.BackPropagate(new float[] { 0, 1, 0 }, new float[] { 1 }); nn.BackPropagate(new float[] { 0, 0, 1 }, new float[] { 1 }); nn.BackPropagate(new float[] { 0, 0, 1 }, new float[] { 0 }); nn.BackPropagate(new float[] { 0, 0, 1 }, new float[] { 1 }); nn.BackPropagate(new float[] { 0, 0, 1 }, new float[] { 1 }); nn.BackPropagate(new float[] { 0, 0, 1 }, new float[] { 0 }); nn.BackPropagate(new float[] { 1, 1, 0 }, new float[] { 1 }); nn.BackPropagate(new float[] { 0, 1, 1 }, new float[] { 1 }); nn.BackPropagate(new float[] { 1, 0, 1 }, new float[] { 1 }); nn.BackPropagate(new float[] { 1, 1, 1 }, new float[] { 1 }); } Console.WriteLine($"Cost: {nn.cost:0.########}"); nn.Save("C:\\network.txt"); VerboseFeedForward(nn, new float[] { 0, 0, 0 }); VerboseFeedForward(nn, new float[] { 1, 0, 0 }); VerboseFeedForward(nn, new float[] { 0, 1, 0 }); VerboseFeedForward(nn, new float[] { 0, 0, 1 }); VerboseFeedForward(nn, new float[] { 1, 1, 0 }); VerboseFeedForward(nn, new float[] { 0, 1, 1 }); VerboseFeedForward(nn, new float[] { 1, 0, 1 }); VerboseFeedForward(nn, new float[] { 1, 1, 1 }); //We want the gate to simulate 3 input or gate (A or B or C) // 0 0 0 => 0 // 1 0 0 => 1 // 0 1 0 => 1 // 0 0 1 => 1 // 1 1 0 => 1 // 0 1 1 => 1 // 1 0 1 => 1 // 1 1 1 => 1 }
public NeuralNetworkEngineTests() { _config400x25x10 = new NeuralNetworkConfig { InputUnits = 400, HiddenLayers = new int[] { 25 }, OutputUnits = 10 }; _config1x2X2x1 = new NeuralNetworkConfig { InputUnits = 1, HiddenLayers = new int[] { 2, 2 }, OutputUnits = 1 }; }
internal static void backPropogationDeepLearningDemo() { try { System.Console.WriteLine(Util.ntimes("*", 100)); System.Console.WriteLine( "\n BackpropagationnDemo - Running BackProp {1} hidden layers on Iris data Set with {0} epochs of learning ", epochs, numHiddenLayers); System.Console.WriteLine(Util.ntimes("*", 100)); DataSet animalDataSet = DataSetFactory.getAnimalDataSet(); INumerizer numerizer = new AnimalDataSetNumerizer(); NeuralNetworkDataSet innds = new IrisNeuralNetworkDataSet(); innds.CreateExamplesFromDataSet(animalDataSet, numerizer); NeuralNetworkConfig config = new NeuralNetworkConfig(); config.SetConfig(FeedForwardDeepNeuralNetwork.NUMBER_OF_INPUTS, 20); config.SetConfig(FeedForwardDeepNeuralNetwork.NUMBER_OF_OUTPUTS, 3); config.SetConfig(FeedForwardDeepNeuralNetwork.NUMBER_OF_HIDDEN_LAYERS, numHiddenLayers); config.SetConfig(FeedForwardDeepNeuralNetwork.NUMBER_OF_HIDDEN_NEURONS_PER_LAYER, numNeuronsPerLayer); config.SetConfig(FeedForwardDeepNeuralNetwork.LOWER_LIMIT_WEIGHTS, -2.0); config.SetConfig(FeedForwardDeepNeuralNetwork.UPPER_LIMIT_WEIGHTS, 2.0); FeedForwardDeepNeuralNetwork ffnn = new FeedForwardDeepNeuralNetwork(config, new SoftSignActivationFunction()); ffnn.SetTrainingScheme(new BackPropagationDeepLearning(0.1, 0.9)); ffnn.TrainOn(innds, epochs); innds.RefreshDataset(); int[] result = ffnn.TestOnDataSet(innds); System.Console.WriteLine(result[0] + " right, " + result[1] + " wrong"); } catch (Exception e) { throw e; } }