def runStandardESN(): standardError = 0 testPredictedOutputDataStandard = 0 for i in range(runTimes): #Tune the standard reservoir reservoirConnectivityBound = (0.1, 1.0) resTuner = tuner.ESNConnTuner( size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=validationInputData, validationOutputData=validationOutputData, inputConnectivity=inputConnectivity, reservoirConnectivityBound=reservoirConnectivityBound, times=10) reservoirConnectivityOptimum = resTuner.getOptimalParameters() #Train the reservoir with optimal parameters esn = ESN.EchoStateNetwork( size=size, inputData=trainingInputData, outputData=trainingOutputData, reservoirTopology=topology.RandomTopology( size=size, connectivity=reservoirConnectivityOptimum), inputConnectivity=inputConnectivity) esn.trainReservoir() #Warm up for the trained data predictedTrainingOutputData = esn.predict(inputTrainingData) #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 = esn.predict(np.array(query).reshape(1, 2))[0, 0] testingPredictedOutputData.append(nextPoint) lastAvailablePoint = nextPoint testingPredictedOutputData = np.array( testingPredictedOutputData).reshape(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))) return testPredictedOutputDataStandard, (standardError / runTimes)
def runErdosESN(): erdosError = 0 testPredictedOutputDataErdos = 0 for i in range(runTimes): # Tune the Erdoys Renyi Network probabilityBound = ( 0.1, 1.0) #To avoid isolated bounds, keep the upper bound low esnTuner = tuner.ESNErdosTuner( size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=validationInputData, validationOutputData=validationOutputData, inputConnectivity=inputConnectivity, probabilityBound=probabilityBound, times=10) probabilityOptimum = esnTuner.getOptimalParameters() res = ESN.EchoStateNetwork( size=size, inputData=trainingInputData, outputData=trainingOutputData, reservoirTopology=topology.ErdosRenyiTopology( size=size, probability=probabilityOptimum), inputConnectivity=inputConnectivity) res.trainReservoir() #Warm up using training data trainingPredictedOutputData = res.predict(inputTrainingData) #Predict for future lastAvailablePoint = testInputData[0, 1] testingPredictedOutputData = [] for i in range(nTesting): #Compose the query query = [1.0] query.append(lastAvailablePoint) #Predict the next point nextPoint = res.predict(np.array(query).reshape(1, 2))[0, 0] testingPredictedOutputData.append(nextPoint) lastAvailablePoint = nextPoint testingPredictedOutputData = np.array( testingPredictedOutputData).reshape(nTesting, 1) #De-normalize actual = minMax.inverse_transform(testActualOutputData) testPredictedOutputDataErdos = minMax.inverse_transform( testingPredictedOutputData) #Error erdosError += errorFunction.compute( actual.reshape((actual.shape[0], 1)), testPredictedOutputDataErdos.reshape( (testPredictedOutputDataErdos.shape[0], 1))) return testPredictedOutputDataErdos, (erdosError / runTimes)
def runScaleFree(): scaleFreeError = 0 testPredictedOutputDataScaleFree = 0 for i in range(runTimes): # Tune the scale free networks attachmentBound = (1, size - 1) esnTuner = tuner.ESNScaleFreeNetworksTuner( size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=validationInputData, validationOutputData=validationOutputData, inputConnectivity=inputConnectivity, attachmentBound=attachmentBound, times=5) attachmentOptimum = esnTuner.getOptimalParameters() res = ESN.EchoStateNetwork( size=size, inputData=trainingInputData, outputData=trainingOutputData, reservoirTopology=topology.ScaleFreeNetworks( size=size, attachmentCount=attachmentOptimum), inputConnectivity=inputConnectivity) res.trainReservoir() #Warm up using training data trainingPredictedOutputData = res.predict(trainingInputData) #Predict for future lastAvailablePoint = testInputData[0, 1] testingPredictedOutputData = [] for i in range(nTesting): #Compose the query query = [1.0] query.append(lastAvailablePoint) #Predict the next point nextPoint = res.predict(np.array(query).reshape(1, 2))[0, 0] testingPredictedOutputData.append(nextPoint) lastAvailablePoint = nextPoint testingPredictedOutputData = np.array( testingPredictedOutputData).reshape(nTesting, 1) #De-normalize actual = minMax.inverse_transform(testActualOutputData) testPredictedOutputDataScaleFree = minMax.inverse_transform( testingPredictedOutputData) #Error scaleFreeError += errorFunction.compute( actual.reshape((actual.shape[0], 1)), testPredictedOutputDataScaleFree.reshape( (testPredictedOutputDataScaleFree.shape[0], 1))) return testPredictedOutputDataScaleFree, (scaleFreeError / runTimes)
testActualOutputData = data[nTraining + 1:nTraining + nTesting + 1].reshape( (nTesting, 1)) #Tune and Train size = 100 initialTransient = 5 inputConnectivity = 0.6 reservoirTopology = topology.RandomTopology(size=size, connectivity=0.9) inputScalingBound = reservoirScalingBound = leakingRateBound = spectralRadiusBound = ( 0.0, 1.0) esnTuner = tuner.ESNTuner(size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=trainingInputData, validationOutputData=trainingOutputData, inputScalingBound=inputScalingBound, reservoirScalingBound=reservoirScalingBound, leakingRateBound=leakingRateBound, spectralRadiusBound=spectralRadiusBound, reservoirTopology=reservoirTopology, inputConnectivity=inputConnectivity) spectralRadiusOptimum, inputScalingOptimum, reservoirScalingOptimum, leakingRateOptimum, inputWeightConn, reservoirWeightConn = esnTuner.getOptimalParameters( ) network = esn.EchoStateNetwork(size=size, inputData=trainingInputData, outputData=trainingOutputData, reservoirTopology=reservoirTopology, spectralRadius=spectralRadiusOptimum, inputScaling=inputScalingOptimum,
#Validation data validationInputData = trainingInputData validationOutputData = trainingOutputData #Tune the reservoir spectralRadiusBound = (0.0, 1.0) inputScalingBound = (0.0, 1.0) reservoirScalingBound = (0.0, 1.0) leakingRateBound = (0.0, 1.0) size = 500 initialTransient = 50 resTuner = tuner.ReservoirTuner(size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=validationInputData, validationOutputData=validationOutputData, spectralRadiusBound=spectralRadiusBound, inputScalingBound=inputScalingBound, reservoirScalingBound=reservoirScalingBound, leakingRateBound=leakingRateBound) spectralRadiusOptimum, inputScalingOptimum, reservoirScalingOptimum, leakingRateOptimum, inputWeightOptimum, reservoirWeightOptimum = resTuner.getOptimalParameters( ) #Train the reservoir with the optimal parameters res = reservoir.Reservoir(size=size, spectralRadius=spectralRadiusOptimum, inputScaling=inputScalingOptimum, reservoirScaling=reservoirScalingOptimum, leakingRate=leakingRateOptimum, initialTransient=initialTransient, inputData=trainingInputData,
(nTesting, 1)), data[nTraining:nTraining + nTesting].reshape( (nTesting, 1)))) testActualOutputData = data[nTraining + 1:nTraining + nTesting + 1].reshape( (nTesting, 1)) # Tune the Erdoys Renyi Network size = 100 initialTransient = 5 inputConnectivityBound = (0.1, 0.9) # Usually dense probabilityBound = (0.0, 0.9 ) #To avoid isolated bounds, keep the upper bound low errorFunction = rmse.MeanSquareError() esnTuner = tuner.ESNErdosTuner(size=size, initialTransient=initialTransient, trainingInputData=inputTrainingData, trainingOutputData=outputTrainingData, validationInputData=inputTrainingData, validationOutputData=outputTrainingData, inputConnectivityBound=inputConnectivityBound, probabilityBound=probabilityBound) inputConnectivityOptimum, probabilityOptimum = esnTuner.getOptimalParameters() res = esn.EchoStateNetwork(size=size, inputData=inputTrainingData, outputData=outputTrainingData, reservoirTopology=topology.ErdosRenyiTopology( size=size, probability=probabilityOptimum), inputConnectivity=inputConnectivityOptimum) res.trainReservoir() #Warm up using training data trainingPredictedOutputData = res.predict(inputTrainingData)
testInputData = np.hstack((np.ones( (nTesting, 1)), data[nTraining:nTraining + nTesting].reshape( (nTesting, 1)))) testActualOutputData = data[nTraining + 1:nTraining + nTesting + 1].reshape( (nTesting, 1)) #Tune and Train size = 100 initialTransient = 5 inputConnectivityBound = (0.1, 1.0) attachmentBound = (1, size) esnTuner = tuner.ESNScaleFreeNetworksTuner( size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=trainingInputData, validationOutputData=trainingOutputData, inputConnectivityBound=inputConnectivityBound, attachmentBound=attachmentBound) inputConnectivityOptimum, attachmentOptimum = esnTuner.getOptimalParameters() network = esn.EchoStateNetwork(size=size, inputData=trainingInputData, outputData=trainingOutputData, reservoirTopology=topology.ScaleFreeNetworks( size=size, attachmentCount=attachmentOptimum), inputConnectivity=inputConnectivityOptimum) network.trainReservoir()
def runSmallWorld(): smallWorldErrorError = 0 testPredictedOutputDataSmallWorld = 0 for i in range(runTimes): # Tune the Small world graphs meanDegreeBound = (2, size - 1) betaBound = (0.1, 1.0) esnTuner = tuner.ESNSmallWorldGraphsTuner( size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=validationInputData, validationOutputData=validationOutputData, inputConnectivity=inputConnectivity, meanDegreeBound=meanDegreeBound, betaBound=betaBound, times=10) meanDegreeOptimum, betaOptimum = esnTuner.getOptimalParameters() res = ESN.EchoStateNetwork(size=size, inputData=trainingInputData, outputData=trainingOutputData, reservoirTopology=topology.SmallWorldGraphs( size=size, meanDegree=meanDegreeOptimum, beta=betaOptimum), inputConnectivity=inputConnectivity) res.trainReservoir() #Warm up using training data trainingPredictedOutputData = res.predict(inputTrainingData) #Predict for future lastAvailablePoint = testInputData[0, 1] testingPredictedOutputData = [] for i in range(nTesting): #Compose the query query = [1.0] query.append(lastAvailablePoint) #Predict the next point nextPoint = res.predict(np.array(query).reshape(1, 2))[0, 0] testingPredictedOutputData.append(nextPoint) lastAvailablePoint = nextPoint testingPredictedOutputData = np.array( testingPredictedOutputData).reshape(nTesting, 1) #De-normalize actual = minMax.inverse_transform(testActualOutputData) testPredictedOutputDataSmallWorld = minMax.inverse_transform( testingPredictedOutputData) #Error smallWorldErrorError += errorFunction.compute( actual.reshape((actual.shape[0], 1)), testPredictedOutputDataSmallWorld.reshape( (testPredictedOutputDataSmallWorld.shape[0], 1))) return testPredictedOutputDataSmallWorld, (smallWorldErrorError / runTimes)
(nTesting, 1)))) testActualOutputData = data[nTraining + 1:nTraining + nTesting + 1].reshape( (nTesting, 1)) #Tune and Train size = 100 initialTransient = 5 reservoirTopology = topology.RandomTopology(size=size, connectivity=0.3) inputConnectivityBound = (0.1, 1.0) meanDegreeBound = (2, size) betaBound = (0.0, 1.0) esnTuner = tuner.ESNSmallWorldGraphsTuner( size=size, initialTransient=initialTransient, trainingInputData=trainingInputData, trainingOutputData=trainingOutputData, validationInputData=trainingInputData, validationOutputData=trainingOutputData, inputConnectivityBound=inputConnectivityBound, meanDegreeBound=meanDegreeBound, betaBound=betaBound) inputConnectivityOptimum, meanDegreeOptimum, betaOptimum = esnTuner.getOptimalParameters( ) network = esn.EchoStateNetwork(size=size, inputData=trainingInputData, outputData=trainingOutputData, reservoirTopology=topology.SmallWorldGraphs( size=size, meanDegree=meanDegreeOptimum, beta=betaOptimum),