Skip to content

Commit

Permalink
Fix for #213
Browse files Browse the repository at this point in the history
  • Loading branch information
thouska committed May 17, 2019
1 parent 4844cbc commit 7f9cbb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
37 changes: 13 additions & 24 deletions spotpy/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,46 +596,35 @@ def plot_objectivefunction(results,evaluation,limit=None,sort=True, fig_name = '
plt.plot(bestlike)
plt.savefig(fig_name)

def plot_parametertrace_algorithms(results,algorithmnames=None,parameternames=None, fig_name='parametertrace_algorithms.png'):
def plot_parametertrace_algorithms(result_lists, algorithmnames, spot_setup,
fig_name='parametertrace_algorithms.png'):
"""Example Plot as seen in the SPOTPY Documentation"""
import matplotlib.pyplot as plt
font = {'family' : 'calibri',
'weight' : 'normal',
'size' : 20}
plt.rc('font', **font)
fig=plt.figure(figsize=(17,5))
subplots=len(results)
rows=2
subplots=len(result_lists)
parameter = spotpy.parameter.get_parameters_array(spot_setup)
rows=len(parameter['name'])
for j in range(rows):
for i in range(subplots):
ax = plt.subplot(rows,subplots,i+1+j*subplots)
if j==0:
if parameternames:
data=results[i]['par'+parameternames[0]]
else:
data=results[i]['par0']
if j==1:
if parameternames:
data=results[i]['par'+parameternames[1]]
else:
data=results[i]['par1']
ax.set_xlabel(algorithmnames[i-subplots])

data=result_lists[i]['par'+parameter['name'][j]]
ax.plot(data,'b-')
ax.set_ylim(-50,50)
if i==0 and j==0:
ax.set_ylabel('x')
ax.yaxis.set_ticks([-50,0,50])
if i==0:
ax.set_ylabel(parameter['name'][j])
rep = len(data)
if i==0 and j==1:
ax.set_ylabel('y')
ax.yaxis.set_ticks([-50,0,50])
if j==0:
ax.xaxis.set_ticks([])
if i>0:
ax.yaxis.set_ticks([])
if j==rows-1:
ax.set_xlabel(algorithmnames[i-subplots])
else:
ax.xaxis.set_ticks([])
ax.plot([1]*rep,'r--')
ax.set_xlim(0,rep)
ax.set_ylim(parameter['minbound'][j],parameter['maxbound'][j])

#plt.tight_layout()
fig.savefig(fig_name, bbox_inches='tight')
Expand Down
12 changes: 9 additions & 3 deletions spotpy/examples/spot_setup_rosenbrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np

from spotpy.parameter import Uniform
from spotpy.objectivefunctions import rmse
from spotpy.objectivefunctions import rmse, log_p

class spot_setup(object):
"""
Expand All @@ -23,7 +23,8 @@ class spot_setup(object):
x = Uniform(-10, 10, 1.5, 3.0, -10, 10, doc='x value of Rosenbrock function')
y = Uniform(-10, 10, 1.5, 3.0, -10, 10, doc='y value of Rosenbrock function')
z = Uniform(-10, 10, 1.5, 3.0, -10, 10, doc='z value of Rosenbrock function')

def __init__(self,used_algorithm='default'):
self.used_algorithm =used_algorithm
def simulation(self, vector):
x=np.array(vector)
simulations= [sum(100.0 * (x[1:] - x[:-1] ** 2.0) ** 2.0 + (1 - x[:-1]) ** 2.0)]
Expand All @@ -34,5 +35,10 @@ def evaluation(self):
return observations

def objectivefunction(self, simulation, evaluation):
objectivefunction = rmse(evaluation=evaluation, simulation=simulation)
if self.used_algorithm == 'sceua':
objectivefunction = rmse(evaluation=evaluation, simulation=simulation)
elif self.used_algorithm == 'dream' or self.used_algorithm == 'demcz' or self.used_algorithm == 'mcmc':
objectivefunction = log_p(evaluation=evaluation, simulation=simulation)
elif self.used_algorithm == 'default':
objectivefunction = - rmse(evaluation=evaluation, simulation=simulation)
return objectivefunction

0 comments on commit 7f9cbb7

Please sign in to comment.