/// <summary> /// Add layer to the neural network. /// Layer will automatically be added as the output layer to the last layer in the neural network. /// </summary> public void AddLayer(NeuralLayer newLayer) { if (_layers.Any()) { var lastLayer = _layers.Last(); newLayer.ConnectLayers(lastLayer); } _layers.Add(newLayer); _neuronErrors.Add(_layers.Count - 1, new double[newLayer.Neurons.Count]); }
public NeuralLayer CreateNeuralLayer(int numberOfNeurons, IActivationFunction activationFunction, IInputFunction inputFunction) { var layer = new NeuralLayer(); for (int i = 0; i < numberOfNeurons; i++) { var neuron = new Neuron.Neuron(activationFunction, inputFunction); layer.Neurons.Add(neuron); } return(layer); }
/// <summary> /// Connecting two layers. /// </summary> public void ConnectLayers(NeuralLayer inputLayer) { var combos = Neurons.SelectMany(neuron => inputLayer.Neurons, (neuron, input) => new { neuron, input }); combos.ToList().ForEach(x => x.neuron.AddInputNeuron(x.input)); }