private INeuralModel InitNeuralModel() { var model = new NeuralModelBase(); model.defaultWeightInitializer = () => GARandomManager.NextFloat(-1f, 1f); model.WeightConstraints = new Tuple <float, float>(-10, 10); var bias = model.AddBiasNeuron(); var layers = new List <Neuron[]>() { model.AddInputNeurons(inputs).ToArray(), model.AddNeurons( new Neuron(-1, ActivationFunctions.Gaussian) { //ValueModifiers = new[] { Dropout.DropoutFunc(0.06f) }, }, count: inputs ).ToArray(), model.AddOutputNeurons( inputs, ActivationFunctions.Sigmoid ).ToArray(), }; model.ConnectLayers(layers); model.ConnectBias(bias, layers.Skip(1)); return(model); }
private INeuralModel Init4InputsNeuralModel() { var model = new NeuralModelBase(); model.defaultWeightInitializer = () => GARandomManager.NextFloat(-1, 1);; model.WeightConstraints = new Tuple <float, float>(-50f, 50f); var layers = new List <Neuron[]>() { model.AddInputNeurons(CartPoleAgent.nbOfInputs).ToArray(), model.AddOutputNeurons( 1, ActivationFunctions.TanH ).ToArray(), }; model.ConnectLayers(layers); var outputNeuron = layers.Last().Last(); model.AddConnection(outputNeuron.InnovationNb, outputNeuron.InnovationNb); return(model); }
protected override INeuralModel InitNeuralModel() { var model = new NeuralModelBase(); model.defaultWeightInitializer = () => GARandomManager.NextFloat(-1, 1); model.WeightConstraints = weightConstraints.ToTuple(); var layers = new List <Neuron[]>() { // Inputs model.AddInputNeurons( agentPrefab.GetComponent <AgentProxy>().nbOfInputs ).ToArray(), model.AddNeurons( new Neuron(-1, ActivationFunctions.TanH), count: agentPrefab.GetComponent <AgentProxy>().nbOfInputs * 4 ).ToArray(), // Outputs model.AddOutputNeurons( agentPrefab.GetComponent <AgentProxy>().nbOfOutputs, ActivationFunctions.Sigmoid ).ToArray(), }; model.ConnectLayers(layers); var outputs = layers.Last(); //model.ConnectNeurons(outputs, outputs); model.ConnectLayers(new[] { outputs, outputs }); return(model); }
private INeuralModel InitModel() { var model = new NeuralModelBase(); model.defaultWeightInitializer = () => GARandomManager.NextFloat(-1, 1); model.WeightConstraints = new Tuple <float, float>(-5, 5); var bias = model.AddBiasNeuron(); var layers = new[] { model.AddInputNeurons(1).ToArray(), model.AddNeurons( sampleNeuron: new Neuron(-1, ActivationFunctions.Gaussian), count: 1 ).ToArray(), model.AddOutputNeurons(1, ActivationFunctions.Sigmoid).ToArray() }; model.ConnectBias(bias, layers.Skip(1)); model.ConnectLayers(layers); // Adding RNN //foreach (var neuron in layers[1]) //{ // var mem = model.AddNeurons( // sampleNeuron: new MemoryNeuron(-1, neuron.InnovationNb), // count: 1); // model.AddConnection(mem[0].InnovationNb, neuron.InnovationNb); //} // Addin LSTM var input = layers.First().First(); var output = layers[1].First(); var a = new[] { 1, 2, 3 }; a.Where(x => x == 0) .GroupBy(x => x) .ToArray(); model.AddLSTM(out var lstmIn, out var lstmOut, biasNeuron: bias); model.AddConnection(input, lstmIn); model.AddConnection(lstmOut, output); return(model); }
private INeuralModel Init2InputsNeuralModel() { var model = new NeuralModelBase(); model.defaultWeightInitializer = () => GARandomManager.NextFloat(-1, 1);; model.WeightConstraints = new Tuple <float, float>(-5f, 5f); var bias = model.AddBiasNeuron(); var layers = new List <Neuron[]>() { model.AddInputNeurons(CartPoleAgent.nbOfInputs).ToArray(), model.AddOutputNeurons( 1, ActivationFunctions.TanH ).ToArray(), }; model.ConnectLayers(layers); var outputNeuron = layers.Last().Last(); //var memNeurons = model.AddNeurons( // sampleNeuron: new MemoryNeuron(-1, outputNeuron.InnovationNb), // count: 1 //).ToArray(); // RNN //var innerMemNeurons = model.AddNeurons( // sampleNeuron: new Neuron(-1, ActivationFunctions.TanH), // count: 1).ToArray(); //model.ConnectLayers(new[] { memNeurons, innerMemNeurons }); //model.ConnectLayers(new[] { layers[0], innerMemNeurons, new[] { outputNeuron } }); // LSTM Neuron lstmIn, lstmOut; model.AddLSTM(out lstmIn, out lstmOut, biasNeuron: bias); //model.ConnectNeurons(memNeurons, new[] { lstmIn }).ToArray(); model.ConnectNeurons(layers[0], new[] { lstmIn }).ToArray(); model.ConnectNeurons(new[] { lstmOut }, layers.Last()).ToArray(); return(model); }
private INeuralModel InitModel() { var model = new NeuralModelBase(); model.defaultWeightInitializer = () => GARandomManager.NextFloat(-3, 3); model.WeightConstraints = new Tuple <float, float>(-20, 20); var bias = model.AddBiasNeuron(); var layers = new[] { model.AddInputNeurons(2).ToArray(), model.AddNeurons( sampleNeuron: new Neuron(-1, ActivationFunctions.Gaussian), count: 1 ).ToArray(), model.AddOutputNeurons(1, ActivationFunctions.Sigmoid).ToArray() }; model.ConnectBias(bias, layers.Skip(1)); model.ConnectLayers(layers); return(model); }
public static void AddLSTM( this NeuralModelBase model, out Neuron input, out Neuron output, BiasNeuron biasNeuron = null, WeightInitializer weightInitializer = null, string groupName = "LSTM") { var concatNeur = model.AddNeuron( sampleNeuron: new Neuron(-1, null) ); // Multiply Gate var sigmoid1 = model.AddNeuron( sampleNeuron: new Neuron(-1, ActivationFunctions.Sigmoid) ); model.AddConnection(concatNeur, sigmoid1, weightInitializer) .isTransferConnection = true; var multiplyGate = model.AddNeuron( sampleNeuron: new Neuron(-1, null) { ValueCollector = new MultValueCollector() } ); model.AddConnection(sigmoid1, multiplyGate, weightInitializer); // Addition gate var sigmoid2 = model.AddNeuron( sampleNeuron: new Neuron(-1, ActivationFunctions.Sigmoid) ); model.AddConnection(concatNeur, sigmoid2, weightInitializer) .isTransferConnection = true; var tanh = model.AddNeuron( sampleNeuron: new Neuron(-1, ActivationFunctions.TanH) ); model.AddConnection(concatNeur, tanh, weightInitializer) .isTransferConnection = true; var sigmoidAndTanhMultGate = model.AddNeuron( sampleNeuron: new Neuron(-1, null) { ValueCollector = new MultValueCollector() } ); model.AddConnection(sigmoid2, sigmoidAndTanhMultGate, weightInitializer); model.AddConnection(tanh, sigmoidAndTanhMultGate, weightInitializer); var additionGate = model.AddNeuron(new Neuron(-1, null)); model.AddConnection(multiplyGate, additionGate, weightInitializer) .isTransferConnection = true; model.AddConnection(sigmoidAndTanhMultGate, additionGate, weightInitializer) .isTransferConnection = true; // Tanh gate var sigmoid3 = model.AddNeuron( sampleNeuron: new Neuron(-1, ActivationFunctions.Sigmoid) ); model.AddConnection(concatNeur, sigmoid3, weightInitializer) .isTransferConnection = true; var finalMult = model.AddNeuron( sampleNeuron: new Neuron(-1, null) { ValueCollector = new MultValueCollector() } ); var tanhGate = model.AddNeuron( sampleNeuron: new Neuron(-1, ActivationFunctions.TanH) ); model.AddConnection(additionGate, tanhGate, weightInitializer) .isTransferConnection = true; model.AddConnection(sigmoid3, finalMult, weightInitializer); model.AddConnection(tanhGate, finalMult, weightInitializer) .isTransferConnection = true; // Adding memory neurons var finalMultMem = model.AddNeuron( sampleNeuron: new MemoryNeuron(-1, finalMult.InnovationNb) ); model.AddConnection(finalMultMem, concatNeur, weightInitializer) .isTransferConnection = true; var cellStateMem = model.AddNeuron( sampleNeuron: new MemoryNeuron(-1, additionGate.InnovationNb) ); model.AddConnection(cellStateMem, multiplyGate, weightInitializer) .isTransferConnection = true; // Connecting bias if (biasNeuron != null) { model.AddConnection(biasNeuron, sigmoid1); model.AddConnection(biasNeuron, sigmoid2); model.AddConnection(biasNeuron, tanh); model.AddConnection(biasNeuron, sigmoid3); } // Assign neuron group concatNeur.group = groupName; sigmoid1.group = groupName; sigmoid2.group = groupName; sigmoid3.group = groupName; tanh.group = groupName; additionGate.group = groupName; multiplyGate.group = groupName; tanhGate.group = groupName; sigmoidAndTanhMultGate.group = groupName; finalMult.group = groupName; cellStateMem.group = groupName; finalMultMem.group = groupName; // Assigning out's input = concatNeur; output = finalMult; }
protected override INeuralModel InitNeuralModel() { var model = new NeuralModelBase(); model.defaultWeightInitializer = () => GARandomManager.NextFloat(-1, 1); model.WeightConstraints = new Tuple <float, float>( weightConstraints.x, weightConstraints.y ); var bias = model.AddBiasNeuron(); var layers = new List <Neuron[]>() { // Inputs model.AddInputNeurons( agentPrefab.GetComponent <AgentProxy>().nbOfInputs ).ToArray(), //model.AddNeurons( // new Neuron(-1, ActivationFunctions.TanH), // count: 4 //).ToArray(), // Outputs model.AddOutputNeurons( agentPrefab.GetComponent <AgentProxy>().nbOfOutputs, ActivationFunctions.Sigmoid ).ToArray(), }; model.ConnectLayers(layers); model.ConnectBias(bias, layers.Skip(1)); //var memoryNeurons = new List<Neuron>(); //foreach (var neuron in layers.Last()) //{ // var mem = model.AddNeurons( // sampleNeuron: new MemoryNeuron(-1, neuron.InnovationNb), // count: 1 // ); // memoryNeurons.Add(mem[0]); //} //var memoryProcLayer1 = model.AddNeurons( // new Neuron(-1, ActivationFunctions.TanH), // count: 4 //).ToArray(); //var memoryProcLayer2 = model.AddNeurons( // new Neuron(-1, ActivationFunctions.TanH), // count: 4 // ).ToArray(); //model.ConnectLayers( // new Neuron[][] // { // memoryNeurons.ToArray(), // memoryProcLayer1, // memoryProcLayer2, // layers.Last() // } //); Neuron lstmIn, lstmOut; model.AddLSTM(out lstmIn, out lstmOut, biasNeuron: bias); model.ConnectNeurons(layers[0], new[] { lstmIn }).ToArray(); model.ConnectNeurons(new[] { lstmOut }, layers.Last()).ToArray(); return(model); }