Пример #1
0
        /// <summary>
        /// Compute the outputs for this layer given the input pattern. The output is
        /// also stored in the fire instance variable.
        /// </summary>
        /// <param name="pattern">The input pattern.</param>
        /// <returns>The output from this layer.</returns>
        public virtual INeuralData Compute(INeuralData pattern)
        {
            INeuralData result = (INeuralData)pattern.Clone();

            if (this.HasBias)
            {
                // apply the bias values
                for (int i = 0; i < this.biasWeights.Length; i++)
                {
                    result[i] = result[i] + this.biasWeights[i];
                }
            }

            // apply the activation function
            ActivationFunction.ActivationFunction(result.Data, 0, result.Data.Length);

            return(result);
        }
        /// <summary>
        /// Compute the output for this layer given the input pattern.
        /// The output is also stored in the fire instance variable.
        /// </summary>
        /// <param name="pattern">The input pattern</param>
        /// <returns>The output from this layer.</returns>
        public double[] ComputeOutputs(double[] pattern)
        {
            if (pattern != null)
            {
                for (int i = 0; i < NeuronCount; i++)
                {
                    SetFire(i, pattern[i]);
                }
            }
            Matrix inputMatrix = CreateInputMatrix(_fire);

            for (int i = 0; i < _next.NeuronCount; i++)
            {
                Matrix col = _matrix.GetColumn(i);
                double sum = MatrixMath.DotProduct(col, inputMatrix);
                _next.SetFire(i, _activationFunction.ActivationFunction(sum));
            }
            return(_fire);
        }
Пример #3
0
        /// <inheritdoc/>
        public double Calculate()
        {
            var sumArray = new double[1];

            _sum = 0;

            // sum the input connections
            foreach (IFreeformConnection connection in _inputs)
            {
                connection.Source.PerformCalculation();
                _sum += connection.Weight
                        * connection.Source.Activation;
            }

            // perform the activation function
            sumArray[0] = _sum;
            ActivationFunction
            .ActivationFunction(sumArray, 0, sumArray.Count());

            return(sumArray[0]);
        }