-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow for batched alpha
in StickBreakingWeights
#6042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
7fde39a
11cd987
afdd31a
d933c07
4a50281
fe7c2b2
2a5df64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
from aeppl.logprob import ParameterValueError | ||
from aesara.tensor.random.utils import broadcast_params | ||
|
||
from pymc.aesaraf import compile_pymc | ||
from pymc.distributions.continuous import get_tau_sigma | ||
from pymc.util import UNSET | ||
|
||
|
@@ -952,6 +953,15 @@ def test_hierarchical_obs_logp(): | |
assert not any(isinstance(o, RandomVariable) for o in ops) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def _compile_stickbreakingweights_logpdf(): | ||
_value = at.vector() | ||
_alpha = at.scalar() | ||
_k = at.iscalar() | ||
_logp = logp(StickBreakingWeights.dist(_alpha, _k), _value) | ||
return compile_pymc([_value, _alpha, _k], _logp) | ||
|
||
|
||
class TestMatchesScipy: | ||
def test_uniform(self): | ||
check_logp( | ||
|
@@ -2279,27 +2289,25 @@ def test_dirichlet_multinomial_vectorized(self, n, a, extra_size): | |
) | ||
|
||
@pytest.mark.parametrize( | ||
"value,alpha,K,logp", | ||
"alpha,K", | ||
[ | ||
(np.array([5, 4, 3, 2, 1]) / 15, 0.5, 4, 1.5126301307277439), | ||
(np.tile(1, 13) / 13, 2, 12, 13.980045245672827), | ||
(np.array([0.001] * 10 + [0.99]), 0.1, 10, -22.971662448814723), | ||
(np.append(0.5 ** np.arange(1, 20), 0.5**20), 5, 19, 94.20462772778092), | ||
( | ||
(np.array([[7, 5, 3, 2], [19, 17, 13, 11]]) / np.array([[17], [60]])), | ||
2.5, | ||
3, | ||
np.array([1.29317672, 1.50126157]), | ||
), | ||
(0.5, 4), | ||
(2, 12), | ||
(np.array([0.5, 1.0, 2.0]), 3), | ||
(np.arange(1, 7, dtype="float64").reshape(2, 3), 5), | ||
], | ||
) | ||
def test_stickbreakingweights_logp(self, value, alpha, K, logp): | ||
with Model() as model: | ||
def test_stickbreakingweights_logp(self, alpha, K, _compile_stickbreakingweights_logpdf): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it acceptable to combine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I separate the test for batched alpha |
||
stickbreakingweights_logpdf = np.vectorize( | ||
_compile_stickbreakingweights_logpdf, signature="(n),(),()->()" | ||
) | ||
value = pm.StickBreakingWeights.dist(alpha, K).eval() | ||
with Model(): | ||
sbw = StickBreakingWeights("sbw", alpha=alpha, K=K, transform=None) | ||
pt = {"sbw": value} | ||
assert_almost_equal( | ||
pm.logp(sbw, value).eval(), | ||
logp, | ||
stickbreakingweights_logpdf(value, alpha, K), | ||
decimal=select_by_precision(float64=6, float32=2), | ||
err_msg=str(pt), | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.