def test_list(self): #generate a List sampler input sampler=spotpy.algorithms.mc(spot_setup(),parallel=self.parallel, dbname='Rosen', dbformat='csv', sim_timeout=self.timeout) sampler.sample(self.rep) sampler=spotpy.algorithms.list_sampler(spot_setup(),parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout) sampler.sample(self.rep) results = sampler.getdata() self.assertEqual(len(results), self.rep)
def setup_griewank(self): if not os.path.isfile("setup_griewank_pickle"): from spotpy.examples.spot_setup_griewank import spot_setup # Create samplers for every algorithm: spot_setup = spot_setup() rep = 100 timeout = 10 # Given in Seconds parallel = "seq" dbformat = "csv" sampler = spotpy.algorithms.mc(spot_setup, parallel=parallel, dbname='RosenMC', dbformat=dbformat, sim_timeout=timeout) sampler.sample(rep) fl = open("setup_griewank_pickle", "wb") pickle.dump( { "getdata": sampler.getdata(), "evaluation": sampler.evaluation }, fl) fl.close() with open("setup_griewank_pickle", "rb") as file: return pickle.load(file)
def test_plot_fast_sensitivity(self): from spotpy.examples.spot_setup_rosenbrock import spot_setup spot_setup_object = spot_setup() parallel = "seq" dbformat = "ram" timeout = 5 sampler = spotpy.algorithms.fast(spot_setup_object, parallel=parallel, dbname='test_get_sensitivity_of_fast', dbformat=dbformat, sim_timeout=timeout) sampler.sample(300) results = [] results.append(sampler.getdata()) results = np.array(results)[0] print("Sampler is done with") print(results) spotpy.analyser.plot_fast_sensitivity(results) fig_name = "FAST_sensitivity.png" # approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so # we expecting a plot with some content without testing the structure of the pot just # the size self.assertGreaterEqual(os.path.getsize(fig_name), 8855) # tidy up all os.remove(fig_name)
def test_demcz(self): sampler = spotpy.algorithms.demcz(spot_setup(GausianLike), parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout) sampler.sample(self.rep, convergenceCriteria=0) results = sampler.getdata() self.assertEqual(len(results), self.rep)
def test_fscabc(self): sampler = spotpy.algorithms.fscabc(spot_setup(used_algorithm='fscabc'), parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout) sampler.sample(self.rep) results = sampler.getdata() self.assertEqual(len(results), self.rep)
def test_fast(self): sampler = spotpy.algorithms.fast(spot_setup(), parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout) sampler.sample(self.rep, M=5) results = sampler.getdata() self.assertEqual(len(results), self.rep) #Si values should be returned
def test_umpc(self): sampler = spotpy.algorithms.mc(spot_setup(), parallel='umpc', dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout) sampler.sample(self.rep) results = sampler.getdata() self.assertEqual(len(results), self.rep)
def setUp(self): # How many digits to match in case of floating point answers self.tolerance = 7 #Create samplers for every algorithm: self.spot_setup = spot_setup() self.rep = 987 self.timeout = 10 #Given in Seconds self.parallel = os.environ.get('SPOTPY_PARALLEL', 'seq') self.dbformat = "ram"
def test_dream(self): sampler = spotpy.algorithms.dream(spot_setup(GausianLike), parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout) sampler.sample(self.rep, convergence_limit=0.9, runs_after_convergence=500) results = sampler.getdata() self.assertEqual(len(results), self.rep)
def test_sceua(self): sampler = spotpy.algorithms.sceua(spot_setup(), parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout) sampler.sample(self.rep) results = sampler.getdata() self.assertLessEqual( len(results), self.rep) #Sceua save per definition not all sampled runs
def setUp(self): np.random.seed(42) self.rep = 100 if not os.path.isfile("setUp_pickle_file"): from spotpy.examples.spot_setup_rosenbrock import spot_setup spot_setup_object = spot_setup() self.results = [] parallel = "seq" dbformat = "ram" timeout = 5 self.sampler = spotpy.algorithms.dream(spot_setup_object, parallel=parallel, dbname='RosenDREAM', dbformat=dbformat, sim_timeout=timeout) self.sampler.sample(self.rep) self.results.append(self.sampler.getdata()) self.results = np.array(self.results)
def test_plot_regression(self): from spotpy.examples.spot_setup_rosenbrock import spot_setup spot_setup_object = spot_setup() parallel = "mpc" dbformat = "ram" timeout = 5 sampler = spotpy.algorithms.mc(spot_setup_object, parallel=parallel, dbname='test_plot_regression', dbformat=dbformat, sim_timeout=timeout) sampler.sample(300) spotpy.analyser.plot_regression(sampler.getdata(), sampler.evaluation) fig_name = "regressionanalysis.png" # approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so # we expecting a plot with some content without testing the structure of the pot just # the size self.assertGreaterEqual(os.path.getsize(fig_name), 8855) os.remove(fig_name)
def test_get_sensitivity_of_fast(self): from spotpy.examples.spot_setup_rosenbrock import spot_setup spot_setup_object = spot_setup() results = [] parallel = "seq" dbformat = "ram" timeout = 5 self.sampler = spotpy.algorithms.fast( spot_setup_object, parallel=parallel, dbname='test_get_sensitivity_of_fast', dbformat=dbformat, sim_timeout=timeout) self.sampler.sample(200) results.append(self.sampler.getdata()) results = np.array(results)[0] get_sensitivity_of_fast = spotpy.analyser.get_sensitivity_of_fast( results) self.assertEqual(len(get_sensitivity_of_fast), 2) self.assertEqual(len(get_sensitivity_of_fast["S1"]), 3) self.assertEqual(len(get_sensitivity_of_fast["ST"]), 3) self.assertEqual(type(get_sensitivity_of_fast), type({}))
def test_cli_run(self): setup = spot_setup() runner = CliRunner() result = runner.invoke(run, ['-n 10', '-s', 'lhs', '-p', 'seq'], obj=setup) self.assertEqual(result.exit_code, 0)
Copyright 2015 by Tobias Houska This file is part of Statistical Parameter Estimation Tool (SPOTPY). :author: Tobias Houska This class holds the example code from the Rosenbrock tutorial web-documention. ''' from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import spotpy from spotpy.examples.spot_setup_rosenbrock import spot_setup from spotpy.describe import describe #Create samplers for every algorithm: results=[] spot_setup=spot_setup() rep=5000 sampler=spotpy.algorithms.mc(spot_setup, dbname='RosenMC', dbformat='csv') print(describe(sampler)) sampler.sample(rep) results.append(sampler.getdata()) sampler=spotpy.algorithms.lhs(spot_setup, dbname='RosenLHS', dbformat='csv') print(describe(sampler)) sampler.sample(rep) results.append(sampler.getdata()) sampler=spotpy.algorithms.mle(spot_setup, dbname='RosenMLE', dbformat='csv') print(describe(sampler)) sampler.sample(rep)
''' Copyright 2015 by Tobias Houska This file is part of Statistical Parameter Estimation Tool (SPOTPY). :author: Tobias Houska This class holds the example code from the Rosenbrock tutorial web-documention. ''' from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import spotpy from spotpy.examples.spot_setup_rosenbrock import spot_setup #Create samplers for every algorithm: results=[] spot_setup=spot_setup() rep=5000 sampler=spotpy.algorithms.mc(spot_setup, dbname='RosenMC', dbformat='csv') sampler.sample(rep) results.append(sampler.getdata()) sampler=spotpy.algorithms.lhs(spot_setup, dbname='RosenLHS', dbformat='csv') sampler.sample(rep) results.append(sampler.getdata()) sampler=spotpy.algorithms.mle(spot_setup, dbname='RosenMLE', dbformat='csv') sampler.sample(rep) results.append(sampler.getdata()) sampler=spotpy.algorithms.mcmc(spot_setup, dbname='RosenMCMC', dbformat='csv')
This class holds the example code from the getting_started web-documention. ''' # Getting started #To start your experience with SPOT you need to have SPOT installed. Please see the [Installation chapter](index.md) for further details. #To use SPOT we have to import it and use one of the pre-build examples: import spotpy # Load the SPOT package into your working storage from spotpy import analyser # Load the Plotting extension from spotpy.examples.spot_setup_rosenbrock import spot_setup # Import the two dimensional Rosenbrock example #from spot_setup_griewank import spot_setup #The example comes along with parameter boundaries, the Rosenbrock function, the optimal value of the function and RMSE as a likelihood. #So we can directly start to analyse the Rosenbrock function with one of the algorithms. We start with a simple Monte Carlo sampling: if __name__ == '__main__': # Give Monte Carlo algorithm the example setup and saves results in a RosenMC.csv file #spot_setup.slow = True sampler = spotpy.algorithms.mc(spot_setup(), dbname='RosenMC', dbformat='ram') #Now we can sample with the implemented Monte Carlo algortihm: sampler.sample(100000) # Sample 100.000 parameter combinations results=sampler.getdata() #Now we want to have a look at the results. First we want to know, what the algorithm has done during the 10.000 iterations: #spot.analyser.plot_parametertrace(results) # Use the analyser to show the parameter trace spotpy.analyser.plot_parameterInteraction(results) posterior=spotpy.analyser.get_posterior(results) spotpy.analyser.plot_parameterInteraction(posterior) #spotpy.analyser.plot_posterior_parametertrace(results, threshold=0.9) print spotpy.analyser.get_best_parameterset(results)
from spotpy.examples.spot_setup_rosenbrock import spot_setup from spotpy.describe import describe #Create samplers for every algorithm: results = [] rep = 1000 timeout = 10 #Given in Seconds parallel = "seq" dbformat = "csv" # Bayesian algorithms should be run with a likelihood function bayesian_likelihood_func = spotpy.likelihoods.gaussianLikelihoodMeasErrorOut sampler = spotpy.algorithms.mc(spot_setup(), parallel=parallel, dbname='RosenMC', dbformat=dbformat, sim_timeout=timeout) print(describe(sampler)) sampler.sample(rep) results.append(sampler.getdata()) sampler = spotpy.algorithms.lhs(spot_setup(), parallel=parallel, dbname='RosenLHS', dbformat=dbformat, sim_timeout=timeout) sampler.sample(rep) results.append(sampler.getdata())
This class holds the example code from the getting_started web-documention. ''' from __future__ import print_function, division, absolute_import, unicode_literals # Getting started #To start your experience with SPOT you need to have SPOT installed. Please see the [Installation chapter](index.md) for further details. #To use SPOT we have to import it and use one of the pre-build examples: import spotpy # Load the SPOT package into your working storage from spotpy.examples.spot_setup_rosenbrock import spot_setup # Import the two dimensional Rosenbrock example #The example comes along with parameter boundaries, the Rosenbrock function, the optimal value of the function and RMSE as a likelihood. #So we can directly start to analyse the Rosenbrock function with one of the algorithms. We start with a simple Monte Carlo sampling: if __name__ == '__main__': # Give Monte Carlo algorithm the example setup and saves results in a RosenMC.csv file #spot_setup.slow = True sampler = spotpy.algorithms.mc(spot_setup(), dbname='RosenMC', dbformat='ram') #Now we can sample with the implemented Monte Carlo algortihm: sampler.sample(100000) # Sample 100.000 parameter combinations results = sampler.getdata() #Now we want to have a look at the results. First we want to know, what the algorithm has done during the 10.000 iterations: #spot.analyser.plot_parametertrace(results) # Use the analyser to show the parameter trace spotpy.analyser.plot_parameterInteraction(results) posterior = spotpy.analyser.get_posterior(results) spotpy.analyser.plot_parameterInteraction(posterior) #spotpy.analyser.plot_posterior_parametertrace(results, threshold=0.9) print(spotpy.analyser.get_best_parameterset(results))