Пример #1
0
        /// <summary>
        /// Connects current layer to output (right layer)
        /// It should not connect biases with previous layer
        /// </summary>
        /// <param name="outputNeuronLayer">Layer from the right side</param>
        /// <param name="max">Max value of weight</param>
        /// <param name="min">Min value of weight</param>
        public void ConnectToOutputLayerWithBiases(NeuronLayer outputNeuronLayer, double max, double min)
        {
            var random = new Random();

            IEnumerable <Neuron> outputNeurons;

            //handle case, when we have one neuron on the output
            if (outputNeuronLayer.Neurons.Count > 1)
            {
                outputNeurons = outputNeuronLayer.Neurons.Take(outputNeuronLayer.Neurons.Count - 1);
            }
            else
            {
                outputNeurons = outputNeuronLayer.Neurons;
            }

            //leave the bias
            foreach (var outputNeuron in outputNeurons)
            {
                //connect all neurons with bias from current layer to right layer
                foreach (var inputNeuron in Neurons)
                {
                    var value = random.NextDouble() * (max - min) + min;

                    inputNeuron.ConnectToOutputNeuron(
                        outputNeuron, (float)value);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Connects current neuron layer with right (next) layer
        /// It will connect all neurons of current layer and all neurons of right layer
        /// </summary>
        /// <param name="outputNeuronLayer">Layer from right side (next)</param>
        public void ConnectToOutputLayer(NeuronLayer outputNeuronLayer)
        {
            var random = new Random();

            foreach (var localNeuron in Neurons)
            {
                foreach (var outputNeuron in outputNeuronLayer.Neurons)
                {
                    localNeuron.ConnectToOutputNeuron(outputNeuron, (float)random.NextDouble());
                }
            }
        }