public NeuralNetwork(int[] layerSizes) { //UnityEngine.Random.InitState(505); neuronLayers = new NeuronLayer[layerSizes.Length]; for (int iLayer = 0; iLayer < layerSizes.Length; ++iLayer) { var numNeuronsInLayer = layerSizes[iLayer]; // create neurons var currNeuronLayer = new NeuronLayer(); currNeuronLayer.InitNeurons(numNeuronsInLayer); // connect to previous neurons if (iLayer > 0) { var prevNeuronLayer = neuronLayers[iLayer - 1]; for (int iNeuron = 0; iNeuron < numNeuronsInLayer; ++iNeuron) { var neuron = currNeuronLayer.neurons[iNeuron]; neuron.InitWeights(prevNeuronLayer.neurons.Length); } } neuronLayers[iLayer] = currNeuronLayer; } }
public NeuralNetwork(NeuralNetwork other) { neuronLayers = new NeuronLayer[other.neuronLayers.Length]; // copy layers for (int iLayer = 0; iLayer < other.neuronLayers.Length; ++iLayer) { var otherNeuronLayer = other.neuronLayers[iLayer]; var currNeuronLayer = new NeuronLayer(); currNeuronLayer.InitNeurons(otherNeuronLayer.neurons.Length); // copy neurons for (int iNeuron = 0; iNeuron < currNeuronLayer.neurons.Length; ++iNeuron) { var otherNeuron = otherNeuronLayer.neurons[iNeuron]; // copy other neurons if (otherNeuron.weights != null) { var currNeuron = currNeuronLayer.neurons[iNeuron]; currNeuron.InitWeights(otherNeuron.weights.Length); // copy weights for (int iWeight = 0; iWeight < otherNeuron.weights.Length; ++iWeight) { currNeuron.weights[iWeight] = otherNeuron.weights[iWeight]; currNeuron.val = 0.0f; } } } neuronLayers[iLayer] = currNeuronLayer; } }
public NeuronalNetwork(NeuronalNetwork aSource) { input = new NeuronLayer(aSource.input); output = new NeuronLayer(aSource.output); var last = input; for (int i = 0; i < aSource.layers.Count; i++) { var layer = new NeuronLayer(aSource.layers[i]); layers.Add(layer); layer.InitNeurons(last, aSource.layers[i]); last = layer; } output.InitNeurons(last, aSource.output); }
public NeuronalNetwork(int aInputCount, int aOutputCount, params int[] aMiddleLayers) { input = new NeuronLayer(ENeuronType.Input, aInputCount); output = new NeuronLayer(ENeuronType.Output, aOutputCount); if (aMiddleLayers != null) { for (int i = 0; i < aMiddleLayers.Length; i++) { layers.Add(new NeuronLayer(ENeuronType.Hidden, aMiddleLayers[i])); } } var last = input; for (int i = 0; i < layers.Count; i++) { layers[i].InitNeurons(last); last = layers[i]; } output.InitNeurons(last); // init all neurons with random values Mutate(-1); }