public static void predict(SupportVectorMachine network, SupportVectorMachine network2) { Console.WriteLine(@"Year\tActual\tPredict\tClosed Loops"); for (int year = EVALUATE_START; year < EVALUATE_END; year++) { // calculate based on actual data IMLData input = new BasicMLData(WINDOW_SIZE); for (int i = 0; i < input.Count; i++) { input.Data[i] = normalizedSunspots[(year - WINDOW_SIZE) + i]; //input.setData(i,this.normalizedSunspots[(year-WINDOW_SIZE)+i]); } IMLData output = network.Compute(input); IMLData output2 = network2.Compute(input); double prediction = output.Data[0]; double prediction2 = output2.Data[0]; closedLoopSunspots[year] = prediction; // calculate "closed loop", based on predicted data for (int i = 0; i < input.Count; i++) { input.Data[i] = closedLoopSunspots[(year - WINDOW_SIZE) + i]; //input.setData(i,this.closedLoopSunspots[(year-WINDOW_SIZE)+i]); } output = network.Compute(input); double closedLoopPrediction = output[0]; IMLData output3 = network2.Compute(input); double closedLoopPrediction2 = output[0]; // display //System.out.println((STARTING_YEAR+year) // +"\t"+f.format(this.normalizedSunspots[year]) // +"\t"+f.format(prediction) // +"\t"+f.format(closedLoopPrediction) Console.WriteLine(((STARTING_YEAR + year) + @"\t " + Format.FormatDouble(SUNSPOTS[year], 4) + @"\t " + Format.FormatDouble(normalizedSunspots[year], 4) + @"\t " + Format.FormatDouble(prediction, 4) + @"\t " + Format.FormatDouble(prediction2, 4) + @"\t " + Format.FormatDouble(closedLoopPrediction, 4) + @"\t " + Format.FormatDouble(closedLoopPrediction2, 4) )); } }
public void Execute(IExampleInterface app) { // create a neural network, without using a factory var svm = new SupportVectorMachine(1,true); // 1 input, & true for regression // create training data IMLDataSet trainingSet = new BasicMLDataSet(RegressionInput, RegressionIdeal); // train the SVM IMLTrain train = new SVMSearchTrain(svm, trainingSet); int epoch = 1; do { train.Iteration(); Console.WriteLine(@"Epoch #" + epoch + @" Error:" + train.Error); epoch++; } while (train.Error > 0.01); // test the SVM Console.WriteLine(@"SVM Results:"); foreach (IMLDataPair pair in trainingSet) { IMLData output = svm.Compute(pair.Input); Console.WriteLine(pair.Input[0] + @", actual=" + output[0] + @",ideal=" + pair.Ideal[0]); } }