/** * Prints network output for the each element from the specified training set. * @param neuralNet neural network * @param trainingSet training set */ public static void TestNeuralNetwork(NeuralNetwork neuralNet, TrainingSet trainingSet) { foreach (TrainingElement trainingElement in trainingSet.TrainingElements) { neuralNet.SetInput(trainingElement.Input); neuralNet.Calculate(); double[] networkOutput = neuralNet.Output; Console.Write("Input: " + trainingElement.Input.ArrayString()); Console.WriteLine(" Output: " + networkOutput.ArrayString()); } }
/** * Predict sunspots. * @param network Neural network to use. */ public void Predict(NeuralNetwork network) { Console.WriteLine("Year\tActual\tPredict\tClosed Loop Predict"); for (int year = EVALUATE_START; year < EVALUATE_END; year++) { // calculate based on actual data double[] input = new double[WINDOW_SIZE]; for (int i = 0; i < input.Length; i++) { input[i] = this.normalizedSunspots[(year - WINDOW_SIZE) + i]; } network.SetInput(input); network.Calculate(); double[] output = network.Output; double prediction = output[0]; this.closedLoopSunspots[year] = prediction; // calculate "closed loop", based on predicted data for (int i = 0; i < input.Length; i++) { input[i] = this.closedLoopSunspots[(year - WINDOW_SIZE) + i]; } network.SetInput(input); network.Calculate(); output = network.Output; double closedLoopPrediction = output[0]; // display Console.WriteLine((STARTING_YEAR + year) + "\t" + this.normalizedSunspots[year] + "\t" + prediction + "\t" + closedLoopPrediction); } }