/// <summary> /// Creates a neural net /// </summary> /// <param name='inLayerNeuronCount'> In layer neuron count. </param> /// <param name='hiddenLayerNeuronCounts'> Array containing the hidden layers neuron count. </param> /// <param name='outLayerNeuronCount'> Out layer neuron count.</param> /// <exception cref='Exception'> Throws an exception if the hidden layers are 0. </exception> public NeuralNet(int inLayerNeuronCount, int[] hiddenLayerNeuronCounts, int outLayerNeuronCount) { if (hiddenLayerNeuronCounts.Length == 0) { throw new Exception("The neural net must have at least one hidden layer"); } inLayer = new NeuronLayer(inLayerNeuronCount); hiddenLayers = new NeuronLayer[hiddenLayerNeuronCounts.Length]; outLayer = new NeuronLayer(outLayerNeuronCount); UnityEngine.Debug.Log(hiddenLayerNeuronCounts.Length); for (int i = 0; i < hiddenLayerNeuronCounts.Length; i++) { hiddenLayers [i] = new NeuronLayer(hiddenLayerNeuronCounts [i]); } inLayer.ConnectAxonsWith(hiddenLayers [0]); for (int i = 0; i < hiddenLayers.Length - 1; i++) { hiddenLayers [i].ConnectAxonsWith(hiddenLayers [i + 1]); } hiddenLayers [hiddenLayers.Length - 1].ConnectAxonsWith(outLayer); }
/// <summary> /// Connects all the axons of the layers with another layer. /// </summary> /// <param name='pNextLayer'> /// Layer To Connect. /// </param> public void ConnectAxonsWith(NeuronLayer pNextLayer) { nextLayer = pNextLayer; nextLayer.previousLayer = this; for (int i = 0; i < neurons.Count; i++) { for (int j = 0; j < nextLayer.neurons.Count; j++) { neurons [i].ConnectAxonWith(nextLayer.neurons [j]); } } }