Skip to content

Commit

Permalink
Blacken changed files.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpgoldman authored and Spaak committed Nov 27, 2020
1 parent 99d3213 commit 81f71b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
8 changes: 2 additions & 6 deletions pymc3/distributions/dist_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Created on Mar 7, 2011
@author: johnsalvatier
'''
"""
import numpy as np
import scipy.linalg
import theano.tensor as tt
Expand Down Expand Up @@ -409,11 +409,7 @@ def incomplete_beta_cfe(a, b, x, small):
qkm1 = one
r = one

def _step(
_i,
pkm1, pkm2, qkm1, qkm2,
k1, k2, k3, k4, k5, k6, k7, k8, r
):
def _step(_i, pkm1, pkm2, qkm1, qkm2, k1, k2, k3, k4, k5, k6, k7, k8, r):
xk = -(x * k1 * k2) / (k3 * k4)
pk = pkm1 + pkm2 * xk
qk = qkm1 + qkm2 * xk
Expand Down
18 changes: 9 additions & 9 deletions pymc3/distributions/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,7 @@ def draw_values(params, point=None, size=None):
if (next_, size) in drawn:
# If the node already has a givens value, add it to givens
givens[next_.name] = (next_, drawn[(next_, size)])
elif isinstance(next_, (theano_constant,
tt.sharedvar.SharedVariable)):
elif isinstance(next_, (theano_constant, tt.sharedvar.SharedVariable)):
# If the node is a theano.tensor.TensorConstant or a
# theano.tensor.sharedvar.SharedVariable, its value will be
# available automatically in _compile_theano_function so
Expand Down Expand Up @@ -750,9 +749,13 @@ def draw_values(params, point=None, size=None):
# The node failed, so we must add the node's parents to
# the stack of nodes to try to draw from. We exclude the
# nodes in the `params` list.
stack.extend([node for node in named_nodes_parents[next_]
if node is not None and
getattr(node, "name", None) not in givens])
stack.extend(
[
node
for node in named_nodes_parents[next_]
if node is not None and getattr(node, "name", None) not in givens
]
)

# the below makes sure the graph is evaluated in order
# test_distributions_random::TestDrawValues::test_draw_order fails without it
Expand All @@ -774,10 +777,7 @@ def draw_values(params, point=None, size=None):
evaluated[param_idx] = drawn[(param, size)]
else:
try: # might evaluate in a bad order,
value = _draw_value(param,
point=point,
givens=givens.values(),
size=size)
value = _draw_value(param, point=point, givens=givens.values(), size=size)
evaluated[param_idx] = drawn[(param, size)] = value
givens[param.name] = (param, value)
except theano.gof.fg.MissingInputError:
Expand Down
26 changes: 15 additions & 11 deletions pymc3/tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,15 @@ def test_bounded_dist(self):
prior_trace = pm.sample_prior_predictive(5)
assert prior_trace["x"].shape == (5, 3, 1)


# Added this test because the NormalMixture distribution did not support
# component shape identification, causing prior predictive sampling to
# error out.
def test_prior_sampling_mixture():
old_faithful_df = pd.read_csv(pm.get_data('old_faithful.csv'))
old_faithful_df['std_waiting'] = (old_faithful_df.waiting - old_faithful_df.waiting.mean()) / old_faithful_df.waiting.std()
old_faithful_df = pd.read_csv(pm.get_data("old_faithful.csv"))
old_faithful_df["std_waiting"] = (
old_faithful_df.waiting - old_faithful_df.waiting.mean()
) / old_faithful_df.waiting.std()
N = old_faithful_df.shape[0]
K = 30

Expand All @@ -931,15 +934,16 @@ def stick_breaking(beta):
return result / tt.sum(result, axis=-1, keepdims=True)

with pm.Model() as model:
alpha = pm.Gamma('alpha', 1., 1.)
beta = pm.Beta('beta', 1., alpha, shape=K)
w = pm.Deterministic('w', stick_breaking(beta))

tau = pm.Gamma('tau', 1., 1., shape=K)
lambda_ = pm.Gamma('lambda_', 10., 1., shape=K)
mu = pm.Normal('mu', 0, tau=lambda_ * tau, shape=K)
obs = pm.NormalMixture('obs', w, mu, tau=lambda_ * tau,
observed=old_faithful_df.std_waiting.values)
alpha = pm.Gamma("alpha", 1.0, 1.0)
beta = pm.Beta("beta", 1.0, alpha, shape=K)
w = pm.Deterministic("w", stick_breaking(beta))

tau = pm.Gamma("tau", 1.0, 1.0, shape=K)
lambda_ = pm.Gamma("lambda_", 10.0, 1.0, shape=K)
mu = pm.Normal("mu", 0, tau=lambda_ * tau, shape=K)
obs = pm.NormalMixture(
"obs", w, mu, tau=lambda_ * tau, observed=old_faithful_df.std_waiting.values
)

pm.sample_prior_predictive()

Expand Down

0 comments on commit 81f71b5

Please sign in to comment.