/// <summary> /// Function for predicting the output of the Neural Network, given the inputs, via multiplicating the inputs with the weights of the Network, adding the Bias and then /// applying an Activation function to the result. This is done until we have reached the last layer, the output layer. /// </summary> /// <param name="inputs">The inputs are the speed and distances projected in 5 different dirrections from the car to the next nearest object.</param> /// <param name="outSteering">The predicted steering.</param> /// <param name="outAxeleration">The predicted axeleration</param> public void predict(float[] inputs, ref double outSteering, ref double outAxeleration) { double[] firstHiddenLayer = new double[7]; double[] secondHiddenLayer = new double[6]; double[] outputLayer = new double[2]; int i, j; #region Prediction Algorithm for (j = 0; j < 7; j++) { for (i = 0; i < 6; i++) { firstHiddenLayer[j] += inputs[i] * inputWeights[i, j]; } } for (i = 0; i < 7; i++) { firstHiddenLayer[i] = ActivationFunctions.SigmoidFunction(firstHiddenLayer[i] + inputBias[i]); } for (j = 0; j < 6; j++) { for (i = 0; i < 7; i++) { secondHiddenLayer[j] += firstHiddenLayer[i] * hiddenWeights[i, j]; } } for (i = 0; i < 6; i++) { secondHiddenLayer[i] = ActivationFunctions.SigmoidFunction(secondHiddenLayer[i] + hiddenBias[i]); } for (j = 0; j < 2; j++) { for (i = 0; i < 6; i++) { outputLayer[j] += secondHiddenLayer[i] * outputWeights[i, j]; } } for (i = 0; i < 2; i++) { outputLayer[i] = ActivationFunctions.SigmoidFunction(outputLayer[i] + outputBias[i]); } outSteering = outputLayer[0]; outAxeleration = outputLayer[1]; #endregion }