/// <summary>
        /// Predict the value of each output node using trained weights of a neural network.
        /// </summary>
        /// <param name="input"> The input layer vector.</param>
        /// <returns>A vector of size (number of nodes in the output layer), containing the results. </returns>
        public matrix FeedForward(double[][] input)
        {
            matrix result = new matrix(input.Length, nr_of_nodes[nr_of_nodes.Length - 1]);

            for (int i = 0; i < input.Length; i++)
            {
                matrix z_ = new matrix(input[i]);
                a[0] = new matrix(input[i]);
                for (int j = 0; j < this.nr_of_layers - 1; j++)
                {
                    z_       = weights[j].Transpose * a[j] + bias[j].Transpose;
                    a[j + 1] = z_;
                    a[j + 1].ApplySigmoid();
                }
                //z[L]
                //a[L]
                for (int j = 0; j < result.columns; j++)
                {
                    result.data[i][j] = a[nr_of_layers - 1].data[j][0];
                }
            }
            return(result);
        }
 double CostFunction_L(int layer, int node, matrix target)
 {
     return(a[layer].data[node][0] * (1 - a[layer].data[node][0]) * (a[layer].data[node][0] - target.data[node][0]));
 }
예제 #3
0
 /// <summary>
 /// Indicates if this Matrix has the same dimensions as another supplied Matrix.
 /// </summary>
 /// <param name="other">Another matrix object to compare this instance to.</param>
 /// <returns>true if both matrices have the same dimensions. Otherwise, false.</returns>
 public bool HaveSameDimensions(matrix other)
 {
     return((this.rows == other.rows) && (this.columns == other.columns));
 }