def setUp(self): self.spot_setup = spot_setup() self.rep = 200 self.timeout = 10 # Given in Seconds import sys self.use_py_3 = sys.version_info[0] >= 3
def setUp(self): generations=40 n_pop = 20 skip_duplicates = True self.sp_setup=spot_setup(obj_func= multi_obj_func) self.sampler = spotpy.algorithms.NSGAII(self.sp_setup, dbname='NSGA2', dbformat="csv") self.sampler.sample(generations, n_obj= 3, n_pop = n_pop, skip_duplicates = skip_duplicates)
def setUp(self): self.data = np.random.gamma(0.7,2,500) self.spot_setup = spot_setup() self.parameterset = self.spot_setup.parameters()['random'] self.simulation = self.spot_setup.simulation(self.parameterset) self.observation = self.spot_setup.evaluation() self.timespanlen = self.simulation.__len__() try: self.ddd = pd.date_range("2015-01-01 11:00", freq="5min", periods=self.timespanlen) self.dd_daily = pd.date_range("2015-05-01", periods=self.timespanlen) self.usepandas = True except NameError: print('Please install Pandas to use these signature functions') self.usepandas = False
:author: Tobias Houska This class holds example code how to use the dream algorithm ''' import numpy as np import spotpy #from spotpy.examples.spot_setup_hymod_exe import spot_setup from spotpy.examples.spot_setup_hymod_python import spot_setup import pylab as plt if __name__ == "__main__": parallel = 'seq' # Initialize the Hymod example (will only work on Windows systems) #spot_setup=spot_setup(parallel=parallel) spot_setup = spot_setup() # Create the Dream sampler of spotpy, al_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.log_p) #Select number of maximum repetitions rep = 10000 # Select five chains and set the Gelman-Rubin convergence limit nChains = 4 convergence_limit = 1.2 runs_after_convergence = 100 sampler = spotpy.algorithms.dream(spot_setup, dbname='DREAM_hymod',
This class holds example code how to use the dream algorithm ''' import numpy as np import spotpy from spotpy.examples.spot_setup_hymod_python import spot_setup import pylab as plt if __name__ == "__main__": parallel = 'seq' # Runs everthing in sequential mode np.random.seed(2000) # Makes the results reproduceable # Initialize the Hymod example # In this case, we tell the setup which algorithm we want to use, so # we can use this exmaple for different algorithms spot_setup = spot_setup(_used_algorithm='sceua') #Select number of maximum allowed repetitions rep = 10000 # Create the SCE-UA sampler of spotpy, alt_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.rmse) sampler = spotpy.algorithms.sceua(spot_setup, dbname='SCEUA_hymod', dbformat='csv', alt_objfun=None) #Start the sampler, one can specify ngs, kstop, peps and pcento id desired sampler.sample(rep, ngs=10, kstop=50, peps=0.1, pcento=0.1)
def setUp(self): self.spot_setup = spot_setup() self.rep = 200 # REP must be a multiply of amount of parameters which are in 7 if using hymod self.timeout = 10 # Given in Seconds
""" Shows the usage of the matplotlib GUI Needs at least Python 3.5 """ from __future__ import division, print_function, unicode_literals import spotpy from spotpy.gui.mpl import GUI from spotpy.examples.spot_setup_hymod_python import spot_setup from spotpy.objectivefunctions import rmse if __name__ == '__main__': setup_class = spot_setup(rmse) #Select number of maximum allowed repetitions rep = 10000 # Create the SCE-UA sampler of spotpy, alt_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.rmse) sampler = spotpy.algorithms.sceua(setup_class, dbname='SCEUA_hymod', dbformat='csv', alt_objfun=None) #Start the sampler, one can specify ngs, kstop, peps and pcento id desired #sampler.sample(rep,ngs=10, kstop=50, peps=0.1, pcento=0.1) gui = GUI(spot_setup())
This class holds example code how to use the dream algorithm ''' import numpy as np import spotpy #from spotpy.examples.spot_setup_hymod_exe import spot_setup from spotpy.examples.spot_setup_hymod_python import spot_setup import matplotlib.pyplot as plt from spotpy.likelihoods import gaussianLikelihoodMeasErrorOut as GausianLike if __name__ == "__main__": parallel = 'seq' # Initialize the Hymod example (will only work on Windows systems) #spot_setup=spot_setup(parallel=parallel) spot_setup = spot_setup(GausianLike) # Create the Dream sampler of spotpy, al_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.log_p) #Select number of maximum repetitions rep = 5000 # Select five chains and set the Gelman-Rubin convergence limit nChains = 4 convergence_limit = 1.2 runs_after_convergence = 100 sampler = spotpy.algorithms.dream(spot_setup, dbname='DREAM_hymod',
def multi_obj_func(evaluation, simulation): #used to overwrite objective function in hymod example like1 = abs(spotpy.objectivefunctions.pbias(evaluation, simulation)) like2 = spotpy.objectivefunctions.rmse(evaluation, simulation) like3 = spotpy.objectivefunctions.rsquared(evaluation, simulation) * -1 return np.array([like1, like2, like3]) if __name__ == "__main__": parallel = 'seq' # Runs everthing in sequential mode np.random.seed(2000) # Makes the results reproduceable # Initialize the Hymod example # In this case, we tell the setup which algorithm we want to use, so # we can use this exmaple for different algorithms spot_setup = spot_setup(multi_obj_func) #Select number of maximum allowed repetitions rep = 2000 # Create the PADDS sampler of spotpy, alt_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.rmse) sampler = spotpy.algorithms.padds(sp_setup, dbname='padds_hymod', dbformat='csv') #Start the sampler, one can specify metric if desired sampler.sample(rep, metric='ones') # Load the results gained with the sceua sampler, stored in padds_hymod.csv
except ImportError: import sys sys.path.append(".") import spotpy from spotpy.examples.spot_setup_hymod_python import spot_setup import matplotlib.pyplot as plt if __name__ == "__main__": parallel = 'seq' # Runs everthing in sequential mode np.random.seed(2000) # Makes the results reproduceable # Initialize the Hymod example # In this case, we tell the setup which algorithm we want to use, so # we can use this exmaple for different algorithms spot_setup = spot_setup( users_objective_function=spotpy.objectivefunctions.nashsutcliffe) #Select number of maximum allowed repetitions rep = 1000 # Create the SCE-UA sampler of spotpy, alt_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.rmse) sampler = spotpy.algorithms.dds(spot_setup, dbname='DDS_hymod', dbformat='csv') #Start the sampler, one can specify ngs, kstop, peps and pcento id desired sampler.sample(rep) results = sampler.getdata()
This class holds example code how to use the dream algorithm ''' import numpy as np import spotpy from spotpy.examples.spot_setup_hymod_python import spot_setup import matplotlib.pyplot as plt if __name__ == "__main__": parallel = 'seq' # Runs everthing in sequential mode np.random.seed(2000) # Makes the results reproduceable # Initialize the Hymod example # In this case, we tell the setup which algorithm we want to use, so # we can use this exmaple for different algorithms spot_setup = spot_setup(spotpy.objectivefunctions.rmse) #Select number of maximum allowed repetitions rep = 5000 sampler = spotpy.algorithms.sceua(spot_setup, dbname='SCEUA_hymod', dbformat='csv') #Start the sampler, one can specify ngs, kstop, peps and pcento id desired sampler.sample(rep, ngs=7, kstop=3, peps=0.1, pcento=0.1) # Load the results gained with the sceua sampler, stored in SCEUA_hymod.csv results = spotpy.analyser.load_csv_results('SCEUA_hymod') #Plot how the objective function was minimized during sampling fig = plt.figure(1, figsize=(9, 6))
Three different kinds of objective functions. """ like1 = abs(spotpy.objectivefunctions.pbias(evaluation, simulation)) like2 = spotpy.objectivefunctions.rmse(evaluation, simulation) like3 = spotpy.objectivefunctions.rsquared(evaluation, simulation)*-1 return [like1, like2, like3] if __name__ == "__main__": generations=40 n_pop = 20 skip_duplicates = True sp_setup=spot_setup(obj_func= multi_obj_func) sampler = spotpy.algorithms.NSGAII(spot_setup=sp_setup, dbname='NSGA2', dbformat="csv") sampler.sample(generations, n_obj= 3, n_pop = n_pop) results = sampler.getdata() fig= plt.figure(1,figsize=(9,5)) plt.plot(results['like1']) plt.show() plt.ylabel('Objective function') plt.xlabel('Iteration') fig.savefig('hymod_objectivefunction.png',dpi=300) # Example plot to show the parameter distribution ######
''' import numpy as np import spotpy from spotpy.examples.spot_setup_hymod_python import spot_setup import matplotlib.pyplot as plt if __name__ == "__main__": parallel ='seq' # Runs everthing in sequential mode np.random.seed(2000) # Makes the results reproduceable # Initialize the Hymod example # In this case, we tell the setup which algorithm we want to use, so # we can use this exmaple for different algorithms spot_setup=spot_setup(users_objective_function=spotpy.objectivefunctions.rmse) #Select number of maximum allowed repetitions rep=500 filename = 'SCEUA_hymod' # Create the SCE-UA sampler of spotpy, alt_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.rmse) sampler=spotpy.algorithms.sceua(spot_setup, dbname='SCEUA_hymod', dbformat='csv') #Start the sampler, one can specify ngs, kstop, peps and pcento id desired sampler.sample(rep)#,ngs=10, kstop=50, peps=0.1, pcento=0.1) # Load the results gained with the sceua sampler, stored in SCEUA_hymod.csv results = spotpy.analyser.load_csv_results('SCEUA_hymod')
:author: Tobias Houska This class holds example code how to use the dream algorithm ''' import numpy as np import spotpy #from spotpy.examples.spot_setup_hymod_exe import spot_setup from spotpy.examples.spot_setup_hymod_python import spot_setup import pylab as plt if __name__ == "__main__": parallel = 'seq' # Initialize the Hymod example (will only work on Windows systems) #spot_setup=spot_setup(parallel=parallel) spot_setup = spot_setup(_used_algorithm='dream') # Create the Dream sampler of spotpy, al_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.log_p) #Select number of maximum repetitions rep = 10000 # Select five chains and set the Gelman-Rubin convergence limit nChains = 4 convergence_limit = 1.2 runs_after_convergence = 100 sampler = spotpy.algorithms.dream(spot_setup, dbname='DREAM_hymod',
""" Shows the usage of the matplotlib GUI Needs at least Python 3.5 """ from __future__ import division, print_function, unicode_literals import spotpy from spotpy.gui.mpl import GUI from spotpy.examples.spot_setup_hymod_python import spot_setup if __name__ == '__main__': setup_class = spot_setup(_used_algorithm='sceua') #Select number of maximum allowed repetitions rep = 10000 # Create the SCE-UA sampler of spotpy, alt_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.rmse) sampler = spotpy.algorithms.sceua(setup_class, dbname='SCEUA_hymod', dbformat='csv', alt_objfun=None) #Start the sampler, one can specify ngs, kstop, peps and pcento id desired #sampler.sample(rep,ngs=10, kstop=50, peps=0.1, pcento=0.1) gui = GUI(spot_setup()) gui.show()
except ImportError: import sys sys.path.append(".") import spotpy from spotpy.examples.spot_setup_hymod_python import spot_setup import matplotlib.pyplot as plt if __name__ == "__main__": parallel = 'seq' # Runs everthing in sequential mode np.random.seed(2000) # Makes the results reproduceable # Initialize the Hymod example # In this case, we tell the setup which algorithm we want to use, so # we can use this exmaple for different algorithms spot_setup = spot_setup(spotpy.objectivefunctions.nashsutcliffe) #Select number of maximum allowed repetitions rep = 1000 # Create the SCE-UA sampler of spotpy, alt_objfun is set to None to force SPOTPY # to jump into the def objectivefunction in the spot_setup class (default is # spotpy.objectivefunctions.rmse) sampler = spotpy.algorithms.dds(spot_setup, dbname='DDS_hymod', dbformat='csv') #Start the sampler, one can specify ngs, kstop, peps and pcento id desired sampler.sample(rep) results = sampler.getdata()