Skip to content

Commit

Permalink
Fix generalizedLikelihoodFunction as proposed #256
Browse files Browse the repository at this point in the history
  • Loading branch information
thouska committed Sep 18, 2020
1 parent 3574b35 commit 99a8f9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions spotpy/examples/tutorial_dream_hymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@
# Select five chains and set the Gelman-Rubin convergence limit
nChains = 4
convergence_limit = 1.2

# Other possible settings to modify the DREAM algorithm, for details see Vrugt (2016)
nCr = 3
eps = 10e-6
runs_after_convergence = 100
acceptance_test_option = 6

sampler=spotpy.algorithms.dream(spot_setup, dbname='DREAM_hymod', dbformat='csv')
r_hat = sampler.sample(rep,nChains=nChains,convergence_limit=convergence_limit,
runs_after_convergence=runs_after_convergence)
r_hat = sampler.sample(rep, nChains, nCr, eps, convergence_limit,
runs_after_convergence,acceptance_test_option)



Expand Down
13 changes: 10 additions & 3 deletions spotpy/likelihoods.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Dream has now a bunch of options. We tested only likelihoods, which do not need a additional parameter
# from this we saw that
# ExponentialTransformErrVarShapingFactor with option 2 and 6 is good
# InverseErrorVarianceShapingFactor with option 2 ist good
# InverseErrorVarianceShapingFactor with option 2 is good
# gaussianLikelihoodMeasErrorOut with option 6 is good
# NoisyABCGaussianLikelihood with Option 6 is good
# ABCBoxcarLikelihood with Option 2 and 6 is good
Expand All @@ -33,6 +33,14 @@ class LikelihoodError(Exception):
def __generateMeaserror(data):
return np.array(data) * 0.1

def __calcSimpleDeviation_bias(data, comparedata, mu_h):
__standartChecksBeforeStart(data, comparedata)
d = np.array(data)
c = np.array(comparedata)
#Adjust c for multiplicative bias parameter:
mu_t = np.exp(mu_h * c)
Et = c * mu_t
return d - Et

def __calcSimpleDeviation(data, comparedata):
__standartChecksBeforeStart(data, comparedata)
Expand Down Expand Up @@ -429,7 +437,6 @@ def generalizedLikelihoodFunction(data, comparedata, measerror=None, params=None
"""

__standartChecksBeforeStart(data, comparedata)
errorArr = __calcSimpleDeviation(data, comparedata)
if measerror is None:
measerror = __generateMeaserror(data)
measerror = np.array(measerror)
Expand Down Expand Up @@ -505,7 +512,7 @@ def generalizedLikelihoodFunction(data, comparedata, measerror=None, params=None
mu_xi = 0.0

n = data.__len__()

errorArr = __calcSimpleDeviation_bias(data, comparedata, muh)
sum_at = 0
# formula for a_t is from page 3, (6)
for j in range(n - 1):
Expand Down

1 comment on commit 99a8f9c

@thouska
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title has a typo, this belongs to #257

Please sign in to comment.