Exemplo n.º 1
0
        /// <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]);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Flattens the inputLayer list (using SelectMany), generates a new layer with a lambda function
        /// and connects the neurons (each neuron has n output neurons) of the new layer to the existing layer
        /// using input and output neuron GUIDs - the inter neuron connection data is held in the
        /// connecting synapse.
        /// </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));
        }