nTesting, 1) #Predict testPredictedOutputDataStandard = minMax.inverse_transform( testingPredictedOutputData) actual = minMax.inverse_transform(testActualOutputData) standardError = errorFunction.compute( actual.reshape((actual.shape[0], 1)), testPredictedOutputDataStandard.reshape( (testPredictedOutputDataStandard.shape[0], 1))) testActualOutputData = minMax.inverse_transform(testActualOutputData[:nTesting, 0]) #Plotting of the prediction output and error outplot = outputPlot.OutputPlot( "Outputs/Prediction.html", "Darwin Sea Level Pressure Prediction", "Comparison of Random Graph Topolgies - Standard Vs Erdos", "Time", "Sea Level Pressure") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', testActualOutputData) outplot.setYSeries('Predicted Output_standard_ESN_with_parameters_tuned', testPredictedOutputDataStandard) outplot.setYSeries('Predicted Output_Erdoys_ESN_with_parameters_tuned', testPredictedOutputDataErdos) outplot.createOutput() #Plotting of regression error errPlot = errorPlot.ErrorPlot("Outputs/RegressionError.html", "Comparison of standard vs deterministic", "with parameters tuner", "ESN Configuration", "Total Error") errPlot.setXAxis(np.array(['Standard', 'Erdos Renyi']))
# Predict predictedTargetVectors = model.predict(featureVectors) outputFolderName = "Outputs/Outputs" + datetime.now().strftime("%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) for i in range(horizon): # Plot the actual and predicted actual = targetVectors[:, i] predicted = predictedTargetVectors[:, i] # Descale actual = util.scalingFunction.inverse_transform(actual) predicted = util.scalingFunction.inverse_transform(predicted) outplot = outputPlot.OutputPlot(outputFolderName + "/Prediction_horizon"+str(i+1)+".html", "Facebook Fans Change - Linear Regression", "Taylor Swift", "Time", "Output") outplot.setXSeries(np.arange(1, targetVectors.shape[0])) outplot.setYSeries('Actual Output', actual) outplot.setYSeries('Predicted Output', predicted) outplot.createOutput() print("Done!")
testingPredictedOutputData = np.array(testingPredictedOutputData).reshape( nTesting, 1) #Predict testPredictedOutputDataStandard = minMax.inverse_transform( testingPredictedOutputData) standardError = errorFunction.compute( testActualOutputData.reshape((testActualOutputData.shape[0], 1)), testPredictedOutputDataStandard.reshape( (testPredictedOutputDataStandard.shape[0], 1))) testActualOutputData = minMax.inverse_transform(testActualOutputData[:nTesting, 0]) #Plotting of the prediction output and error outplot = outputPlot.OutputPlot("Outputs/Prediction.html", "Darwin Sea Level Pressure Prediction", "Comparison of standard vs deterministic", "Time", "Sea Level Pressure") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', testActualOutputData) outplot.setYSeries('Predicted Output_standard_ESN', testPredictedOutputDataStandard) for i in range(len(topologyObjects)): seriesName = 'Predicted Output_' + topologyNames[i] seriesData = topologyTestOutput[i] outplot.setYSeries(seriesName, seriesData) outplot.createOutput() #Plotting of regression error topologyNames.append('Standard') topologyError.append(standardError) errPlot = errorPlot.ErrorPlot("Outputs/RegressionError.html",
topologyTestOutput.append(testPredictedOutputData) #Error topologyError.append( errorFunction.compute( testActualOutputData.reshape((testActualOutputData.shape[0], 1)), testPredictedOutputData.reshape( (testPredictedOutputData.shape[0], 1)))) #De-normalize testActualOutputData = minMax.inverse_transform(testActualOutputData[:nTesting, 0]) #Plotting of the prediction output and error outplot = outputPlot.OutputPlot("Outputs/Prediction.html", "Darwin Sea Level Pressure Prediction", "Deterministic echo state networks", "Time", "Sea Level Pressure") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', testActualOutputData) for i in range(len(topologyObjects)): seriesName = 'Predicted Output_' + topologyNames[i] seriesData = topologyTestOutput[i] outplot.setYSeries(seriesName, seriesData) outplot.createOutput() #Plotting of regression error topologyNames.append('Standard') errPlot = errorPlot.ErrorPlot("Outputs/RegressionError.html", "Deterministic echo state networks", "with different topologies", "Topology", "Total Error")
# Initial seed initialSeedForValidation = trainingData[-1] predictedOutputData = util.tuneTrainPredictConnectivity( trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationOutputData=validationData, initialInputSeedForValidation=initialSeedForValidation, horizon=nTesting, resTopology=util.Topology.ScaleFreeNetworks) predictedOutputData = minMax.inverse_transform(predictedOutputData) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot( outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - Scale Free Networks (Tuned)", "Prediction on Validation + Testing Set", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', actualOutputData) outplot.setYSeries('Predicted Output', predictedOutputData) outplot.createOutput() endTime = time() run_time = endTime - startTime print("The run time:" + str(run_time)) print("Done!")
# Initial seed initialSeedForValidation = trainingData[-1] predictedOutputData = util.tuneTrainPredictConnectivityNonBrute( trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationOutputData=validationData, initialInputSeedForValidation=initialSeedForValidation, horizon=nTesting, resTopology=util.Topology.SmallWorldGraphs) predictedOutputData = minMax.inverse_transform(predictedOutputData) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot( outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - Small World Graphs (Tuned)", "Prediction on Validation + Testing Set", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', actualOutputData) outplot.setYSeries('Predicted Output', predictedOutputData) outplot.createOutput() endTime = time() run_time = endTime - startTime print("The run time:" + str(run_time)) print("Done!")
trainingInputData, trainingOutputData = util.formFeatureVectors(trainingData) actualOutputData = minMax.inverse_transform(testingData)[:, 0] # Initial seed initialSeedForValidation = trainingData[-1] predictedOutputData = utilGA.tuneTrainPredictGA( trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationOutputData=validationData, initialInputSeedForValidation=initialSeedForValidation, testingData=actualOutputData) predictedOutputData = minMax.inverse_transform(predictedOutputData) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot(outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - GA Optimization", "Predicted vs Actual", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', actualOutputData) outplot.setYSeries('Predicted Output', predictedOutputData) outplot.createOutput() endTime = time() run_time = endTime - startTime print("The run time:" + str(run_time)) print("Done!")
inputWeightRandom=inputWeight, reservoirWeightRandom=reservoirWeight) res.trainReservoir() #Warm up predictedTrainingOutputData = res.predict(inputTrainingData) #Predict future values predictedTestOutputData = util.predictFuture(res, trainingData[-1], nTesting) #Calculate the error errorFunction = rmse.MeanSquareError() error = errorFunction.compute(testingData, predictedTestOutputData) print("Regression error:" + str(error)) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot( outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - Small World Graphs ESN", "Prediction of Future values", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', minMax.inverse_transform(testingData[:nTesting, 0])) outplot.setYSeries( 'Predicted Output', minMax.inverse_transform(predictedTestOutputData[:nTesting, 0])) outplot.createOutput() print("Done!")
) #Train res = reservoir.Reservoir(size=size, spectralRadius=spectralRadiusOptimum, inputScaling=inputScalingOptimum, reservoirScaling=reservoirScalingOptimum, leakingRate=leakingRateOptimum, initialTransient=initialTransient, inputData=trainingInputData, outputData=trainingOutputData, inputWeightRandom=inputWeightOptimum, reservoirWeightRandom=reservoirWeightOptimum) res.trainReservoir() #Warm up predictedTrainingOutputData = res.predict(validationInputData) # Predict predictedTestOutputData = util.predictFuture(res, validationData[-1], nTesting) #Plotting of the prediction output and error outplot = outputPlot.OutputPlot("Outputs/Prediction.html", "Mackey-Glass Time Series", "Prediction of future values", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', testingData[:nTesting, 0]) outplot.setYSeries('Predicted Output', predictedTestOutputData[:nTesting, 0]) outplot.createOutput() print("Done!")
initialInputSeedForValidation=initialSeedForValidation, horizon=nTesting, noOfBest=noOfBest, resTopology=utilityGA.Topology.Random, size=networkSize, popSize=populationSize, maxGeneration=noOfGenerations) predictedOutputData = minMax.inverse_transform(predictedOutputData) #Plotting of the prediction output and error outputFolderName = "Outputs/Random_Graph_Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot(outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - GA Optimization)", "Prediction on Testing data", "Time", "Output") outplot.setXSeries(np.arange(1, nValidation + nTesting + 1)) outplot.setYSeries('Actual Output', actualOutputData) outplot.setYSeries('Predicted Output', predictedOutputData) outplot.createOutput() # Plotting of the best population details utilityGA.plotNetworkPerformance(bestPopulation, topology=utilityGA.Topology.Random, fileName=outputFolderName + "/NetworkPerformance.html", networkSize=networkSize) # Store the best population in a file (for later analysis) popFileName = outputFolderName + "/population.pkl"
# Form feature vectors for training data trainingInputData, trainingOutputData = util.formFeatureVectors(trainingData) actualOutputData = minMax.inverse_transform(testingData)[:,0] # Initial seed initialSeedForValidation = trainingData[-1] predictedOutputData = util.tuneTrainPredictConnectivity(trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationOutputData=validationData, initialInputSeedForValidation=initialSeedForValidation, horizon = nTesting, resTopology= util.Topology.ErdosRenyi) predictedOutputData = minMax.inverse_transform(predictedOutputData) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime("%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot(outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - Erdos Renyi (Tuned)", "Prediction on Validation + Testing Set", "Time", "Output") outplot.setXSeries(np.arange(1, nValidation + nTesting + 1)) outplot.setYSeries('Actual Output', actualOutputData) outplot.setYSeries('Predicted Output', predictedOutputData) outplot.createOutput() endTime = time() run_time = endTime - startTime print("The run time:"+str(run_time)) print("Done!")
inputWeightRandom=inputWeight, reservoirWeightRandom=reservoirWeight) res.trainReservoir() #Warm up predictedTrainingOutputData = res.predict(inputTrainingData) #Predict future values predictedTestOutputData = util.predictFuture(res, trainingData[-1], nTesting) #Calculate the error errorFunction = rmse.MeanSquareError() error = errorFunction.compute(testingData, predictedTestOutputData) print("Regression error:" + str(error)) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot( outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - Scale Free Networks ESN", "Prediction of Future values", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', minMax.inverse_transform(testingData[:nTesting, 0])) outplot.setYSeries( 'Predicted Output', minMax.inverse_transform(predictedTestOutputData[:nTesting, 0])) outplot.createOutput() print("Done!")
testPredictedOutputDataStandard, standardError = runStandardESN() testPredictedOutputDataErdos, erdosError = runErdosESN() testPredictedOutputDataSmallWorld, smallWorldError = runSmallWorld() testPredictedOutputDataScaleFree, scaleFreeError = runScaleFree() testActualOutputData = minMax.inverse_transform(testActualOutputData[:nTesting, 0]) outputFolderName = "Outputs/Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) #Plotting of the prediction output and error outplot = outputPlot.OutputPlot( outputFolderName + "/Prediction.html", "Mackey Glass Prediction", "Comparison of Random Graph Topolgies - Standard Vs Erdos", "Time", "Sea Level Pressure") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', testActualOutputData) outplot.setYSeries('Predicted Output_standard_ESN_with_all_parameters_tuned', testPredictedOutputDataStandard) outplot.setYSeries('Predicted Output_Erdoys_ESN_with_parameters_tuned', testPredictedOutputDataErdos) outplot.setYSeries('Predicted Output_Small World_ESN_with_parameters_tuned', testPredictedOutputDataSmallWorld) outplot.setYSeries('Predicted Output_Scale_Free_with_parameters_tuned', testPredictedOutputDataScaleFree) outplot.createOutput() #Plotting of regression error errPlot = errorPlot.ErrorPlot(outputFolderName + "/RegressionError.html",
lastAvailableData = testInputData[0, 1] for i in range(nTesting): query = [1.0] query.append(lastAvailableData) #Predict the next point nextPoint = res.predict(np.array(query).reshape((1, 2)))[0, 0] predictedTestOutputData.append(nextPoint) lastAvailableData = nextPoint predictedTestOutputData = np.array(predictedTestOutputData).reshape( (nTesting, 1)) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime( "%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot(outputFolderName + "/Prediction.html", "Mackey-Glass Time Series", "Prediction of future values", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries( 'Actual Output', minMax.inverse_transform(testActualOutputData[:nTesting, 0])) outplot.setYSeries( 'Predicted Output', minMax.inverse_transform(predictedTestOutputData[:nTesting, 0])) outplot.createOutput() print("Done!")
from utility import Utility import sys import numpy as np from scipy.stats import pearsonr, spearmanr from plotting import OutputPlot as plot from datetime import datetime import os from sklearn import preprocessing as pp folderName = "Outputs/Outputs_" + str(datetime.now()) os.mkdir(folderName) output = plot.OutputPlot(folderName + "/Correlation.html", "Correlation of output with depth", "", "Depth (hours)", "Correlation coefficient") #Get the commamd line arguments profileList = ["AcerDE"] directoryName = "Datasets/" for i in range(len(profileList)): profileName = profileList[i] datasetFileName = directoryName + profileName + "_time_interaction.csv" util = Utility.SeriesUtility() series = util.convertDatasetsToSeries(datasetFileName) resampledSeries = util.resampleSeriesSum(series, "H") yearsOfData = 3 recentCount = yearsOfData * 365 * 24 filteredSeries = util.filterRecent(resampledSeries, recentCount) depth = 365 * 24 #1 year
#Predict for future lastAvailablePoint = predictedTrainingOutputData[nTraining - 1, 0] testingPredictedOutputData = [] for i in range(nTesting): #Compose the query query = [1.0] query.append(lastAvailablePoint) #Predict the next point nextPoint = network.predict(np.array(query).reshape(1, 2))[0, 0] testingPredictedOutputData.append(nextPoint) lastAvailablePoint = nextPoint testingPredictedOutputData = np.array(testingPredictedOutputData).reshape( nTesting, 1) #Plotting of the prediction output and error outplot = outputPlot.OutputPlot("Outputs/Prediction.html", "Darwin Sea Level Pressure Prediction", "Prediction of future values", "Time", "Sea Level Pressure") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries( 'Actual Output', minMax.inverse_transform(testActualOutputData[:nTesting, 0])) outplot.setYSeries( 'Predicted Output', minMax.inverse_transform(testingPredictedOutputData[:nTesting, 0])) outplot.createOutput()
resOnline = onlineESN.Reservoir(size=size, inputData=inputTrainingData, outputData=outputTrainingData, spectralRadius=0.79, inputScaling=0.5, reservoirScaling=0.5, leakingRate=0.3, initialTransient=initialTransient, inputWeightRandom=inputWeight, reservoirWeightRandom=reservoirWeight) resOnline.trainReservoir() #Warm up predictedTrainingOutputData = resBatch.predict(inputTrainingData[-initialTransient:]) predictedTrainingOutputData = resOnline.predict(inputTrainingData[-initialTransient:]) #Predict future values predictedTestOutputDataBatch = util.predictFuture(resBatch, trainingData[-1], nTesting) predictedTestOutputDataOnline = util.predictFuture(resOnline, trainingData[-1], nTesting) #Plotting of the prediction output and error outputFolderName = "Outputs/Outputs" + datetime.now().strftime("%Y_%m_%d_%H_%M_%S") os.mkdir(outputFolderName) outplot = outputPlot.OutputPlot(outputFolderName + "/Prediction.html", "Mackey-Glass Time Series - Comparison of Batch vs Online", "Prediction of future values", "Time", "Output") outplot.setXSeries(np.arange(1, nTesting + 1)) outplot.setYSeries('Actual Output', minMax.inverse_transform(testingData[:nTesting, 0])) outplot.setYSeries('Predicted Batch learning Output', minMax.inverse_transform(predictedTestOutputDataBatch[:nTesting, 0])) outplot.setYSeries('Predicted Online RLS learning Output', minMax.inverse_transform(predictedTestOutputDataOnline[:nTesting, 0])) outplot.createOutput() print("Done!")