Encog.Neural.Networks.BasicNetwork.GetWeight C# (CSharp) Method

GetWeight() public method

Get the weight between the two layers.
public GetWeight ( int fromLayer, int fromNeuron, int toNeuron ) : double
fromLayer int The from layer.
fromNeuron int The from neuron.
toNeuron int The to neuron.
return double
        public double GetWeight(int fromLayer, int fromNeuron,
                                int toNeuron)
        {
            _structure.RequireFlat();
            ValidateNeuron(fromLayer, fromNeuron);
            ValidateNeuron(fromLayer + 1, toNeuron);
            int fromLayerNumber = LayerCount - fromLayer - 1;
            int toLayerNumber = fromLayerNumber - 1;

            if (toLayerNumber < 0)
            {
                throw new NeuralNetworkError(
                    "The specified layer is not connected to another layer: "
                    + fromLayer);
            }

            int weightBaseIndex = _structure.Flat.WeightIndex[toLayerNumber];
            int count = _structure.Flat.LayerCounts[fromLayerNumber];
            int weightIndex = weightBaseIndex + fromNeuron
                              + (toNeuron*count);

            return _structure.Flat.Weights[weightIndex];
        }

Usage Example

        /// <summary>
        /// Connect layers from a BasicNetwork. Used internally only.
        /// </summary>
        /// <param name="network">The BasicNetwork.</param>
        /// <param name="fromLayerIdx">The from layer index.</param>
        /// <param name="source">The from layer.</param>
        /// <param name="target">The target.</param>
        private void ConnectLayersFromBasic(BasicNetwork network,
            int fromLayerIdx, IFreeformLayer source, IFreeformLayer target)
        {
            for (int targetNeuronIdx = 0; targetNeuronIdx < target.Count; targetNeuronIdx++)
            {
                for (int sourceNeuronIdx = 0; sourceNeuronIdx < source.Count; sourceNeuronIdx++)
                {
                    IFreeformNeuron sourceNeuron = source.Neurons[sourceNeuronIdx];
                    IFreeformNeuron targetNeuron = target.Neurons[targetNeuronIdx];

                    // neurons with no input (i.e. bias neurons)
                    if (targetNeuron.InputSummation == null)
                    {
                        continue;
                    }

                    IFreeformConnection connection = _connectionFactory
                        .Factor(sourceNeuron, targetNeuron);
                    sourceNeuron.AddOutput(connection);
                    targetNeuron.AddInput(connection);
                    double weight = network.GetWeight(fromLayerIdx,
                        sourceNeuronIdx, targetNeuronIdx);
                    connection.Weight = weight;
                }
            }
        }
All Usage Examples Of Encog.Neural.Networks.BasicNetwork::GetWeight