public NeuralNetwork(NeuronCount inputs, NeuronCount[] numberOfNeuronsPerHiddenLayer, NeuronCount outputs) { layers = new[] { inputs } .Concat(numberOfNeuronsPerHiddenLayer) .Concat(new[] { outputs }) .Select(n => new NeuralNetworkLayer(n)) .ToArray(); for (var i = layers.Length - 1; i > 1; i--) { ((INeuralNetworkLayer)layers[i]).BuildSynapses(layers[i - 1]); } }
public NeuralNetwork(NeuronCount inputs, NeuronCount outputs, params NeuronCount[] hiddenLayers) { if (hiddenLayers == null || !hiddenLayers.Any()) { throw new ArgumentException("At least one hidden layer is required", nameof(hiddenLayers)); } NeuralNetworkLayer previousLayer = null; layers = new[] { inputs } .Concat(hiddenLayers) .Concat(new[] { outputs }) .Select(nc => { previousLayer = previousLayer == null ? new NeuralNetworkLayer(nc) : new NeuralNetworkLayer(nc, previousLayer); return(previousLayer); }) .ToArray(); }
public NeuralNetworkLayer(NeuronCount numberOfNeurons) { neurons = Enumerable.Range(1, numberOfNeurons) .Select(_ => new Neuron()) .ToArray(); }