Skip to content

Commit

Permalink
Align DEMetropolis defaults with literature recommendations (#6488)
Browse files Browse the repository at this point in the history
* Changed DEMetropolis and DEMetropolisZ sampler defaults to NormalProposal and tune scaling

Co-authored-by: Michael Osthege <michael.osthege@outlook.com>
  • Loading branch information
gbrunkhorst and michaelosthege authored Feb 1, 2023
1 parent 65c1c68 commit af8cab2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pymc/step_methods/metropolis.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,11 @@ class DEMetropolis(PopulationArrayStepShared):
Some measure of variance to parameterize proposal distribution
proposal_dist: function
Function that returns zero-mean deviates when parameterized with
S (and n). Defaults to Uniform(-S,+S).
S (and n). Defaults to NormalProposal(S).
scaling: scalar or array
Initial scale factor for epsilon. Defaults to 0.001
tune: str
Which hyperparameter to tune. Defaults to None, but can also be 'scaling' or 'lambda'.
Which hyperparameter to tune. Defaults to 'scaling', but can also be 'lambda' or None.
tune_interval: int
The frequency of tuning. Defaults to 100 iterations.
model: PyMC Model
Expand Down Expand Up @@ -748,7 +748,7 @@ def __init__(
proposal_dist=None,
lamb=None,
scaling=0.001,
tune=None,
tune: Optional[str] = "scaling",
tune_interval=100,
model=None,
mode=None,
Expand All @@ -770,7 +770,7 @@ def __init__(
if proposal_dist is not None:
self.proposal_dist = proposal_dist(S)
else:
self.proposal_dist = UniformProposal(S)
self.proposal_dist = NormalProposal(S)

self.scaling = np.atleast_1d(scaling).astype("d")
if lamb is None:
Expand Down Expand Up @@ -851,11 +851,11 @@ class DEMetropolisZ(ArrayStepShared):
Some measure of variance to parameterize proposal distribution
proposal_dist: function
Function that returns zero-mean deviates when parameterized with
S (and n). Defaults to Uniform(-S,+S).
S (and n). Defaults to NormalProposal(S).
scaling: scalar or array
Initial scale factor for epsilon. Defaults to 0.001
tune: str
Which hyperparameter to tune. Defaults to 'lambda', but can also be 'scaling' or None.
Which hyperparameter to tune. Defaults to 'scaling', but can also be 'lambda' or None.
tune_interval: int
The frequency of tuning. Defaults to 100 iterations.
tune_drop_fraction: float
Expand All @@ -869,7 +869,7 @@ class DEMetropolisZ(ArrayStepShared):
References
----------
.. [Braak2006] Cajo C.F. ter Braak (2006).
.. [Braak2008] Cajo C.F. ter Braak (2008).
Differential Evolution Markov Chain with snooker updater and fewer chains.
Statistics and Computing
`link <https://doi.org/10.1007/s11222-008-9104-9>`__
Expand All @@ -895,7 +895,7 @@ def __init__(
proposal_dist=None,
lamb=None,
scaling=0.001,
tune="lambda",
tune: Optional[str] = "scaling",
tune_interval=100,
tune_drop_fraction: float = 0.9,
model=None,
Expand All @@ -917,7 +917,7 @@ def __init__(
if proposal_dist is not None:
self.proposal_dist = proposal_dist(S)
else:
self.proposal_dist = UniformProposal(S)
self.proposal_dist = NormalProposal(S)

self.scaling = np.atleast_1d(scaling).astype("d")
if lamb is None:
Expand Down
3 changes: 3 additions & 0 deletions pymc/tests/step_methods/test_metropolis.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def test_demcmc_tune_parameter(self):
pm.Normal("n", mu=0, sigma=1, size=(2, 3))

step = DEMetropolis()
assert step.tune == "scaling"

step = DEMetropolis(tune=None)
assert step.tune is None

step = DEMetropolis(tune="scaling")
Expand Down

0 comments on commit af8cab2

Please sign in to comment.