Exemple #1
0
        /// <summary>
        /// Gets the activation value of the neuron
        /// </summary>
        /// <param name="activationTable">An activation table with all activations up to L-1 filled in</param>
        /// <returns>the float value of the neuron activation</returns>
        public float GetActivation(float[,] activationTable)
        {
            var z          = GetInputValue(activationTable);
            var activation = _activationFunction.GetValue(z); //activation = p.activationMethod(z)

            return(activation);
        }
Exemple #2
0
        /// <summary>
        /// Returns the computed value of each unit in the layer
        ///
        /// For each unit, take input from upstream layer, multiply by weights
        /// and then apply transfer function
        /// </summary>
        /// <returns></returns>
        public virtual double GetValue(long idxUnit, long row)
        {
            double net = 0;

            for (int idxUp = 0; idxUp < Weights.Length - 1; idxUp++)
            {
                net += Weights[idxUp][idxUnit]
                       * GetValueUpstreamLayer(idxUp, row);
            }

            //For Bias term
            net += Weights[Weights.Length - 1][idxUnit] * 1.0;
            return(_activationFunction.GetValue(net));
        }
Exemple #3
0
        /// <summary>
        /// Computes the FilterMap by convolution over each Input array
        /// from Upstream layer
        ///
        /// This function contains the sliding convolution window logic
        /// </summary>
        /// <param name="upStreamLayer"></param>
        public override void ComputeValueMap()
        {
            int filterSize = _weights.Length; //Filter is same as window

            //Slide the filter Window to compute value for each Cell in ValueMap (VM)
            for (int idxRowVM = 0; idxRowVM < GetValueMapNoOfRows(); idxRowVM++)
            {     //idxRowVM
                for (int idxColVM = 0; idxColVM < GetValueMapNoOfColumns(); idxColVM++)
                { //idxColVM
                    double sum = 0;
                    int    idxUpValueMapCol = 0, idxUpValueMapRow = 0;
                    //Set the filter window co-ordinates in the upstream value map
                    //relative to the current Value Map
                    int upMapLeftCol = idxColVM * _stride;
                    int upMapLeftRow = idxRowVM * _stride;
                    //TODO: Assign value
                    for (int idxFilter = 0; idxFilter < _upStreamLayer.GetNumberOfFilterUnits();
                         idxFilter++)        //For each Filter Unit Upstream
                    {
                        SingleFilterUnit upFilterUnit =
                            (SingleFilterUnit)_upStreamLayer.GetFilterUnit(idxFilter);

                        for (int idxFilterRow = 0; idxFilterRow < filterSize; idxFilterRow++)
                        {
                            for (int idxFilterCol = 0; idxFilterCol < filterSize; idxFilterCol++)
                            {
                                //Update value
                                idxUpValueMapCol = upMapLeftCol + idxFilterCol;
                                idxUpValueMapRow = upMapLeftRow + idxFilterRow;
                                //Multiply upStream FilterMap by current Filter weights
                                sum += _weights[idxFilterCol][idxFilterRow] *
                                       upFilterUnit.GetValueMapAtIndex(idxUpValueMapCol,
                                                                       idxUpValueMapRow);
                            } //idxFilterCol
                              //Do for bias term
                            sum += _bias * 1.0;
                        } //idxFilterRow
                    }     //idxFilter

                    //Normalize Sum
                    sum = sum / (filterSize * 2); //divide sum by filter Grid size
                    //Apply activation function - this saves time
                    sum = _activationFunction.GetValue(sum);
                    ValueMap[idxColVM][idxRowVM] = sum; //Assign value to FilterMap
                } //idxColFM
            } //idxRowFM
        }
Exemple #4
0
        public IList <double> GetOutputs(IList <double> inputs, IActivationFunction activationFunction, double bias)
        {
            if (inputs.Count != InputSize)
            {
                throw new ArgumentOutOfRangeException(nameof(inputs),
                                                      "Inputs size should be the same as layer input size.");
            }

            var output = new double[OutputSize];

            for (var row = 0; row < OutputSize; row++)
            {
                var value = bias;

                for (var col = 0; col < InputSize; col++)
                {
                    value += WeightMatrix[row, col] * inputs[col];
                }

                output[row] = activationFunction.GetValue(value);
            }

            return(output);
        }