Skip to content

Commit

Permalink
Fix multi objective tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thouska committed Oct 9, 2020
1 parent afd996d commit a6e921d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spotpy/examples/tutorial_padds_hymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def plot_parameter_histogram(ax, results, parameter):
ax11.plot(q5,color='dimgrey',linestyle='solid')
ax11.plot(q95,color='dimgrey',linestyle='solid')
ax11.fill_between(np.arange(0,len(q5),1),list(q5),list(q95),facecolor='dimgrey',zorder=0,
linewidth=0,label='parameter uncertainty')
linewidth=0,label='parameter uncertainty')
ax11.plot(spot_setup.evaluation(),'r.',label='data')
ax11.set_ylim(-50,450)
ax11.set_xlim(0,729)
Expand Down
23 changes: 20 additions & 3 deletions tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@
import spotpy
import numpy as np
from spotpy.examples.spot_setup_rosenbrock import spot_setup
from spotpy.examples.tutorial_padds import padds_spot_setup
from spotpy.examples.spot_setup_hymod_python import spot_setup as spot_setup_hymod
from spotpy.describe import describe
import os
import numpy as np
from spotpy.likelihoods import gaussianLikelihoodMeasErrorOut as GausianLike


#https://docs.python.org/3/library/unittest.html

class TestAlgorithms(unittest.TestCase):

def multi_obj_func(self, evaluation, simulation, params=None):
#used to overwrite objective function in hymod example
like1 = abs(spotpy.objectivefunctions.bias(evaluation, simulation))
like2 = spotpy.objectivefunctions.rmse(evaluation, simulation)
like3 = spotpy.objectivefunctions.rsquared(evaluation, simulation)*-1
return np.array([like1, like2, like3])

def setUp(self):
# How many digits to match in case of floating point answers
self.tolerance = 7
Expand Down Expand Up @@ -116,8 +125,16 @@ def test_fast(self):
self.assertEqual(len(results), self.rep) #Si values should be returned

def test_padds(self):
sampler=spotpy.algorithms.padds(padds_spot_setup(),parallel=self.parallel, dbname='RosenPADDS', dbformat=self.dbformat, sim_timeout=self.timeout)
sampler.sample(self.rep)
sampler=spotpy.algorithms.padds(spot_setup_hymod(self.multi_obj_func),parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout)
sampler.sample(int(self.rep*0.5), metric='ones')
results = sampler.getdata()
self.assertEqual(len(results)+5, int(self.rep*0.5))

def test_nsgaii(self):
generations=20
n_pop = 10
sampler=spotpy.algorithms.NSGAII(spot_setup_hymod(self.multi_obj_func),parallel=self.parallel, dbname='Rosen', dbformat=self.dbformat, sim_timeout=self.timeout)
sampler.sample(generations, n_obj= 3, n_pop = n_pop)
results = sampler.getdata()
self.assertEqual(len(results)+5, self.rep) #Si values should be returned

Expand Down

0 comments on commit a6e921d

Please sign in to comment.