/// <summary> /// Creates a new instance of a <see cref="NeuralNet"/> /// </summary> /// <param name="numInputs">The number of nodes in the input layer</param> /// <param name="numOutputs">The number of nodes in the output layer</param> public NeuralNet(int numInputs, int numOutputs) { if (numInputs <= 0) { throw new ArgumentOutOfRangeException(nameof(numInputs), "You must have at least one input node"); } if (numOutputs <= 0) { throw new ArgumentOutOfRangeException(nameof(numOutputs), "You must have at least one output node"); } Inputs = new NeuralNetLayer(numInputs); Outputs = new NeuralNetLayer(numOutputs); }
/// <summary> /// Adds a hidden layer to the neural net and returns the new layer. /// </summary> /// <param name="numNeurons">The number of neurons in the layer</param> public void AddHiddenLayer(int numNeurons) { if (numNeurons <= 0) { throw new ArgumentOutOfRangeException(nameof(numNeurons), "You cannot add a hidden layer without any nodes"); } if (IsConnected) { throw new InvalidOperationException("Cannot add a new layer after the network has been evaluated."); } var layer = new NeuralNetLayer(numNeurons); _hiddenLayers.Add(layer); }
/// <summary> /// Connects this layer to the <paramref name="nextLayer"/>, forming connections between each node in this /// layer and each node in the next layer. /// </summary> /// <param name="nextLayer">The layer to connect to</param> internal void ConnectTo([NotNull] NeuralNetLayer nextLayer) { _nextLayer = nextLayer ?? throw new ArgumentNullException(nameof(nextLayer)); _neurons.Each(source => nextLayer.Each(source.ConnectTo)); }