/// <summary> /// calculates the value of a single layer's neuron values /// </summary> /// <param name="preLayer"></param> /// <param name="curLayer"></param> public void calcLayer(Layer preLayer, Layer curLayer) { double[] temp = NetworkMath.multiply(curLayer.weight, preLayer.neuron); //multiplies the weights and the value of the previous layers neurons curLayer.z = NetworkMath.add(curLayer.bias, temp); //adds the appropriate biases to the product of the weights and neurons curLayer.neuron = NetworkMath.activationFunction(curLayer.z); //applies an activation function on the previous sum }
/// <summary> /// calculates all neuron values in the network /// </summary> /// <param name="input"></param> public void calcNetwork(double[] input) { layers[0].neuron = input; //sets the correct values of the nodes of the input layer for (int i = 1; i < (layers.Count); i++) //loops through each layer (starting with the first hidden layer) { //calcLayer(layers[i - 1], layers[i]); double[] temp = NetworkMath.multiply(layers[i].weight, layers[i - 1].neuron); //multiplies the weights and the value of the previous layers neurons layers[i].z = NetworkMath.add(layers[i].bias, temp); //adds the appropriate biases to the product of the weights and neurons layers[i].neuron = NetworkMath.activationFunction(layers[i].z); //applies an activation function on the previous sum } }