Example #1
0
        public Matrix <double> ProcessInputs(Matrix <double> neuronValues, Matrix <double> nextLayerNeuronBias = null)      //If nextLayerNeuonBias = null then it is not using bias!!
        {
            //Batch Processing
            if (Synapse == null)
            {
                throw new Exception("No synapse matrix to process layer. Do not process the output layer!");
            }

            if (neuronValues.ColumnCount != NeuronCount)
            {
                throw new Exception("Incorrect number of neuron values as input for layer " + Name);
            }

            //Matrix representation calculations for improved efficiency
            Matrix <double> weights;
            Matrix <double> input;

            if (nextLayerNeuronBias != null)
            {
                weights = Synapse.Stack(nextLayerNeuronBias);                                             //Add Row of biases
                input   = neuronValues.Append(Matrix <double> .Build.Dense(neuronValues.RowCount, 1, 1)); //Add Column of 1s
            }
            else
            {
                weights = Synapse;
                input   = neuronValues;
            }

            var             layerOutput           = input * weights;
            Matrix <double> nextLayerNeuronValues = activationFunction(layerOutput);

            return(nextLayerNeuronValues);
        }