Exemple #1
0
        /// <summary>
        /// Computes output value of neuron.
        /// </summary>
        ///
        /// <param name="input">Input vector.</param>
        ///
        /// <returns>Returns neuron's output value.</returns>
        ///
        /// <remarks><para>The output value of activation neuron is equal to value
        /// of nueron's activation function, which parameter is weighted sum
        /// of its inputs plus threshold value. The output value is also stored
        /// in <see cref="Neuron.Output">Output</see> property.</para>
        ///
        /// <para><note>The method may be called safely from multiple threads to compute neuron's
        /// output value for the specified input values. However, the value of
        /// <see cref="Neuron.Output"/> property in multi-threaded environment is not predictable,
        /// since it may hold neuron's output computed from any of the caller threads. Multi-threaded
        /// access to the method is useful in those cases when it is required to improve performance
        /// by utilizing several threads and the computation is based on the immediate return value
        /// of the method, but not on neuron's output property.</note></para>
        /// </remarks>
        ///
        /// <exception cref="ArgumentException">Wrong length of the input vector, which is not
        /// equal to the <see cref="Neuron.InputsCount">expected value</see>.</exception>
        ///
        public override double Compute(double[] input)
        {
            // check for corrent input vector
            if (input.Length != inputsCount)
            {
                throw new ArgumentException("Wrong length of the input vector.");
            }

            // initial sum value
            double sum = 0.0;

            // compute weighted sum of inputs
            for (int i = 0; i < weights.Length; i++)
            {
                sum += weights[i] * input[i];
            }
            sum += threshold;

            // local variable to avoid mutlithreaded conflicts
            double output = function.Function(sum);

            // assign output property as well (works correctly for single threaded usage)
            this.output = output;

            return(output);
        }
Exemple #2
0
        /// <summary>
        /// Propogates wights to the right node. Adds the biases to the right node. Then executes the activation function on the right node member-wise
        /// <code>
        /// Complexity: ~ O(n³) Exact: O(n³) + O(2nm)
        /// </code>
        /// </summary>
        /// <param name="Node"></param>
        /// <param name="Right"></param>
        /// <param name="Activator"></param>
        /// <returns></returns>
        public IMatrix <T> Forward(IMatrix <T> Node, IMatrix <T> Matrix, IActivationFunction <T> Activator)
        {
            var result = Node * Matrix;

            result.PerformMemberWise((ref T val) => val = Activator.Function(ref val));

            return(result);
        }
        public double Compute(double[] input)
        {
            Trace.Assert(input.Length == inputs);

            //individual activation
            double sum = Enumerable
                         .Range(0, inputs)
                         .Select(x => activate.Function(WeightsInput[x] * input[x]))
                         .Sum();

            //individual activation
            // still normal function
            double sumHidden = Enumerable
                               .Range(0, hidden)
                               .Select(x => activate.Function(WeightsHidden[x] * sum))
                               .Sum();

            return(sumHidden > 0 ? 1 : 0);
        }
Exemple #4
0
        public override double Compute(Indexer inputs, Indexer weights)
        {
            var sum = weights[inputsCount];

            for (int i = 0; i < inputsCount; i++)
            {
                sum += inputs[i] * weights[i];
            }
            return(Function.Function(sum));
        }
Exemple #5
0
        public double GetOutput(double[] x)
        {
            if (InputSize != 0 && x.Length != InputSize)
            {
                throw new ArgumentException(@"Array must have exact number of elements.", x.ToString());
            }

            if (_weights is null)
            {
                return(_function.Function(x[0]));
            }

            double sum = _weights[0];

            for (int i = 0; i < x.Length; i++)
            {
                sum += _weights[i + 1] * _function.Function(x[i]);
            }
            return(_function.Function(sum));
        }
 public void Launch()
 {
     if (ActivationFunction == null)
     {
         throw new System.Exception("Activation function is missed!");
     }
     InputImpulse += Bias;
     OutputImpulse = ActivationFunction.Function(InputImpulse);
     foreach (Link Bridge in Outputs)
     {
         Bridge.Transfer(OutputImpulse);
     }
 }
Exemple #7
0
        /// <summary>
        /// Computes output value of neuron
        /// </summary>
        ///
        /// <param name="input">Input vector</param>
        ///
        /// <returns>Returns neuron's output value</returns>
        ///
        /// <remarks>The output value of activation neuron is equal to value
        /// of nueron's activation function, which parameter is weighted sum
        /// of its inputs plus threshold value. The output value is also stored
        /// in <see cref="Neuron.Output">Output</see> property.</remarks>
        ///
        public override double Compute(double[] input)
        {
            // check for corrent input vector
            if (input.Length != inputsCount)
            {
                throw new ArgumentException();
            }

            // initial sum value
            double sum = 0.0;

            // compute weighted sum of inputs
            for (int i = 0; i < inputsCount; i++)
            {
                sum += weights[i] * input[i];
            }
            sum += threshold;

            return(output = function.Function(sum));
        }
Exemple #8
0
        /// <summary>
        /// Подсчет выходного значения
        /// </summary>
        /// <param name="parInput">Входной вектор</param>
        /// <returns>Выходное значение нейрона</returns>
        /// <remarks><para>Выходное значение нейрона - это значение активационной функции,
        /// от суммы весов + пороговое значение. Также сохраняется в свойстве Output
        /// <exception cref="ArgumentException">Длина входного вектора не совпадает с ожидаемым
        /// значением в InputsCount</see>.</exception>
        public double Compute(double[] parInput)
        {
            // проверка корректности входного вектора
            if (parInput.Length != _inputsCount)
            {
                throw new ArgumentException("Wrong length of the input vector.");
            }

            // инициализация суммы
            double sum = 0.0;

            // расчет суммы вес*входное значение
            for (int i = 0; i < _weights.Length; i++)
            {
                sum += _weights[i] * parInput[i];
            }
            sum += _threshold;

            double output = _function.Function(sum);

            this._output = output;

            return(output);
        }