Skip to content

Commit 8ea0fa5

Browse files
committed
let MVNormal Proposal return 2d step matrix, SMC uses this, remove unused import
1 parent 19bf9bd commit 8ea0fa5

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

pymc3/step_methods/metropolis.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ def __init__(self, s):
5050
self.chol = scipy.linalg.cholesky(s, lower=True)
5151

5252
def __call__(self, num_draws=None):
53-
b = np.random.randn(self.n)
54-
return np.dot(self.chol, b)
53+
if num_draws is not None:
54+
b = np.random.randn(self.n, num_draws)
55+
return np.dot(self.chol, b).T
56+
else:
57+
b = np.random.randn(self.n)
58+
return np.dot(self.chol, b)
5559

5660

5761
class Metropolis(ArrayStepShared):

pymc3/step_methods/smc.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from ..theanof import inputvars, make_shared_replacements, join_nonshared_inputs
2626
import numpy.random as nr
2727

28+
from .metropolis import MultivariateNormalProposal
2829
from .arraystep import metrop_select
2930
from ..backends import smc_text as atext
3031

@@ -33,25 +34,6 @@
3334
EXPERIMENTAL_WARNING = "Warning: SMC is an experimental step method, and not yet"\
3435
" recommended for use in PyMC3!"
3536

36-
37-
class Proposal(object):
38-
"""Proposal distributions modified from pymc3 to initially create all the
39-
Proposal steps without repeated execution of the RNG - significant speedup!
40-
41-
Parameters
42-
----------
43-
s : :class:`numpy.ndarray`
44-
"""
45-
def __init__(self, s):
46-
self.s = np.atleast_1d(s)
47-
48-
49-
class MultivariateNormalProposal(Proposal):
50-
def __call__(self, num_draws=None):
51-
return np.random.multivariate_normal(
52-
mean=np.zeros(self.s.shape[0]), cov=self.s, size=num_draws)
53-
54-
5537
proposal_dists = {
5638
'MultivariateNormal': MultivariateNormalProposal,
5739
}

pymc3/tests/test_step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .checks import close_to
66
from .models import simple_categorical, mv_simple, mv_simple_discrete, simple_2model, mv_prior_simple
77
from pymc3.sampling import assign_step_methods, sample
8-
from pymc3.model import Model, Deterministic
8+
from pymc3.model import Model
99
from pymc3.step_methods import (NUTS, BinaryGibbsMetropolis, CategoricalGibbsMetropolis,
1010
Metropolis, Slice, CompoundStep, NormalProposal,
1111
MultivariateNormalProposal, HamiltonianMC,

0 commit comments

Comments
 (0)