public Network(int inputSize, int layerSize, int layerCount, int outputSize) { InputSize = inputSize; OutputSize = outputSize; LayerCount = layerCount; if (layerCount > 0) { HiddernLayers.Add(new NeuronLayer(layerSize, InputSize)); for (int x = 1; x < LayerCount; x++) { HiddernLayers.Add(new NeuronLayer(layerSize, layerSize)); } LastLayer = new NeuronLayer(OutputSize, layerSize); } else if (layerCount == 0) { LastLayer = new NeuronLayer(OutputSize, InputSize); } else { throw new ArgumentOutOfRangeException("Input size cannot be negative"); } }
public void ConnectLayer(NeuronLayer next, double[,] weights) { for (int i = 0; i < this.neurons.Length; i++) { for (int j = 0; j < next.neurons.Length; j++) { weights[this.neurons[i].globalIndex, next.neurons[j].globalIndex] = 1; } } }
static void Main(string[] args) { var neuron1 = new Neuron(); var neuron2 = new Neuron(); var neuronLayer1 = new NeuronLayer(); var neuronLayer2 = new NeuronLayer(); neuron1.ConnectTo(neuronLayer1); neuronLayer2.ConnectTo(neuronLayer1); }
public static void Main(string[] args) { // unite Neuron and NeuronLayer in IEnumerable<Neuron> Composite Class // Add an Extension Method for IEnumerable<Neuron> // We will be able to connect a single node to the group of nodes (layer) var neuron1 = new Neuron(); var neuron2 = new Neuron(); neuron1.ConnectTo(neuron2); var layer1 = new NeuronLayer(); var layer2 = new NeuronLayer(); neuron1.ConnectTo(layer1); layer1.ConnectTo(neuron2); }
public NeuralNetwork(int[] _topology) { topology = _topology; layersCount = topology.Length; layers = new NeuronLayer[layersCount]; int count = 0; for (int i = 0; i < topology.Length; i++) { count += topology[i]; layers[i] = new NeuronLayer(topology[i], i); } neurons = new Neuron[count]; weights = new double[count, count]; for (int i = 0; i < count; i++) { for (int j = 0; j < count; j++) { weights[i, j] = double.NegativeInfinity; } } int index = 0; for (int i = 0; i < layers.Length; i++) { for (int j = 0; j < topology[i]; j++) { neurons[index] = new Neuron(index, i, j); layers[i].AddNeuron(j, neurons[index]); index++; } } for (int i = 0; i < layers.Length - 1; i++) { layers[i].ConnectLayer(layers[i + 1], weights); } this.RandomizeWeights(); }