private void StartTraining() { var(inputData, expectedOutputData) = NeuralNetworkHelper.ReduceDataset( humanCar.StateInputMeasurements.ToList(), humanCar.StateOutputMeasurements.ToList()); for (int i = 0; i < inputData.Count(); i++) { if (inputData[i].All(d => d == 0)) { inputData.RemoveAt(i); expectedOutputData.RemoveAt(i); i--; } } notificationService.ShowToast( ToastType.Info, "Training Started..."); // Right now the training happens so fast, not sure if we need to be reporting progress network = NeuralNetworkHelper.GetTrainedNetwork(inputData, expectedOutputData, (c, t) => { }); notificationService.ShowToast( ToastType.Info, "Training Complete."); }
public void Initialize(Track track, MLPNeuralNetwork controller) { var carAi = new CarAI(random, controller); // Load the simulation simulation = appService.Kernel.Get <RacingSimulationLogic>(); simulation.SetTrack(track); // Add the 1:1 trained AI to the list of cars var cars = new List <ICarController>() { carAi }; // Spawn 100 mutated versions of our AI for (int i = 0; i < 100; i++) { var car = carAi.Clone(); car.Mutate(); cars.Add((CarAI)car); } // Initialize the simulation simulation.SetCars(cars); simulation.ResetCars(); // If the visualization is turned on, create it, set the track and add the cars. simulationVisualization = appService.Kernel.Get <RacingSimulationVisualization>(); simulationVisualization.SetTrack(track); simulationVisualization.InitializeCars(simulation.GetCars()); }
public CarAI(Random random, MLPNeuralNetwork network) { this.networkStructure = network.GetStructure(); this.Network = network; this.Random = random; this.Configuration = new CarConfiguration(); }
private void TrainNetwork() { // Define the layour for our NN. // -- Input Nodes 784 - 1 per pixel (28x28). // -- 2 Hidden Layer. 16 nodes each - arbitrary. // -- 1 Output Layer. 10 Nodes (0-10). var inputNodes = 784; var outputNodes = 10; var innerLayers = 2; var hiddenLayerDepth = 16; // Inner Layer + Input + Output = 3 var layers = new int[innerLayers + 2]; layers[0] = inputNodes; for (int i = 1; i < innerLayers + 1; i++) { layers[i] = hiddenLayerDepth; } layers[innerLayers + 1] = outputNodes; // Create the NN. net = new MLPNeuralNetwork(layers); // Grab the training data from the images loaded. var trainData = imageExtraction.Images.Select(i => i.GetImageAsInput()).ToList(); // Grab the reinforcement data from the labels provided. var reinforceValues = imageExtraction.Images.Select(i => i.integerValues).ToList(); // Train the network with our known good data. net.Train(trainData, reinforceValues, ReportProgress); // We now want to display our guess of the number. guessNumber = true; }