Skip to content

Commit 53ad689

Browse files
fonnesbeckTimOliverMaiercode-review-doctorsoma2000-langOriolAbril
authored
Refactor get_tau_sigma to handle lists (#5747)
* Refactor get_tau_sigma to handle lists * Fixed syntax error * Black formatted * Change assertions to ValueError raises * Prior predictions constant data (#5723) * support return constant_data with prior pred * pre-commit format * added test * code review * Fix issue probably-meant-fstring found at https://codereview.doctor (#5726) * Add coords argument to pymc.set_data (#5588) Co-authored-by: Oriol (ZBook) <[email protected]> * remove MultinomialRV override * ⬆️ UPGRADE: Autoupdate pre-commit config * Group GaussianRandomWalk tests in single class * Infer steps from shape in GaussianRandomWalk * Unpin upper limit on numpydoc Closes #5401 * ⬆️ UPGRADE: Autoupdate pre-commit config * Standardize docstrings of input dists arguments and add warning about cloning * Remove unnecessary tag in Simulator logp * Replace deprecated tag.ignore_logprob * Group compile_pymc tests in own class * Remove remaining uses of default_updates in codebase * Remove redundant/wrong docstrings from GaussianRandomWalk logp * Add moment to GaussianRandomWalk and fix mu/sigma broadcasting bug * Do not create temporary SymbolicDistribution just to retrieve number of RNGs needed Reordered methods for consistency * Move SymbolicDistribution docstring to body of class * Refactor AR distribution * Deprecates AR1 distribution * Implements random and moment methods * Batching works on the left as with other distributions * Rename `pandas_to_array` to `convert_observed_data` * Obtain step information from dims and observed * Make AR steps extend shape beyond initial_dist This is consistent with the meaning of steps in the GaussianRandomWalk and translates directly to the number of scan steps taken Co-authored-by: TimOliverMaier <[email protected]> Co-authored-by: code-review-doctor <[email protected]> Co-authored-by: Somasree Majumder <[email protected]> Co-authored-by: Oriol (ZBook) <[email protected]> Co-authored-by: danhphan <[email protected]> Co-authored-by: twiecki <[email protected]> Co-authored-by: Ricardo <[email protected]> Co-authored-by: Ravin Kumar <[email protected]> Co-authored-by: Michael Osthege <[email protected]>
1 parent dd23c90 commit 53ad689

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pymc/distributions/continuous.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ def get_tau_sigma(tau=None, sigma=None):
226226
if isinstance(sigma, Variable):
227227
sigma_ = check_parameters(sigma, sigma > 0, msg="sigma > 0")
228228
else:
229-
assert np.all(np.asarray(sigma) > 0)
230-
sigma_ = sigma
229+
sigma_ = np.asarray(sigma)
230+
if np.any(sigma_ <= 0):
231+
raise ValueError("sigma must be positive")
231232
tau = sigma_**-2.0
232233

233234
else:
@@ -237,9 +238,9 @@ def get_tau_sigma(tau=None, sigma=None):
237238
if isinstance(tau, Variable):
238239
tau_ = check_parameters(tau, tau > 0, msg="tau > 0")
239240
else:
240-
assert np.all(np.asarray(tau) > 0)
241-
tau_ = tau
242-
241+
tau_ = np.asarray(tau)
242+
if np.any(tau_ <= 0):
243+
raise ValueError("tau must be positive")
243244
sigma = tau_**-0.5
244245

245246
return floatX(tau), floatX(sigma)

pymc/tests/test_distributions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,6 +2399,11 @@ def test_get_tau_sigma(self):
23992399
with pytest.raises(ParameterValueError):
24002400
sigma.eval()
24012401

2402+
sigma = [1, 2]
2403+
assert_almost_equal(
2404+
get_tau_sigma(sigma=sigma), [1.0 / np.array(sigma) ** 2, np.array(sigma)]
2405+
)
2406+
24022407
@pytest.mark.parametrize(
24032408
"value,mu,sigma,nu,logp",
24042409
[

0 commit comments

Comments
 (0)