You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(tweedie-post): fix CustomDist random arg, add xtensor/pytensor explanation
- Change CustomDist to
per Ricardo's review (dist expects a PyTensor expression, not numpy)
- Add docstring to tweedie_logp_series explaining why plain PyTensor
ops are used (xtensor named axes fail under PyMC 6.0 broadcasting)
- Clean up leftover @classmethod dist corruption in code block
- Update text references from 'dist' / 'tweedie_dist' to 'random' / 'tweedie_random'
With the log-pdf and random sampler in hand, building the model is straightforward. We place weakly informative priors on the parameters and wrap both functions into a `CustomDist`: the log-pdf for MCMC inference and the random sampler for posterior predictive checks.
129
136
130
137
```python title="Tweedie CustomDist wrapper"
131
-
classTweedie:
132
-
@staticmethod
133
-
deftweedie_dist(mu, phi, p, size):
134
-
return tweedie_random(mu, phi, p, size=size)
138
+
import pymc as pm
139
+
from pymc import CustomDist
135
140
141
+
classTweedie:
136
142
def__new__(cls, name, mu, phi, p, **kwargs):
137
143
return CustomDist(
138
144
name, mu, phi, p,
139
-
dist=cls.tweedie_dist,
140
145
logp=tweedie_logp_series,
146
+
random=tweedie_random,
141
147
class_name="Tweedie",
142
148
**kwargs,
143
149
)
@@ -245,7 +251,7 @@ The (φ, p) joint distribution reveals no pathological tradeoff:
245
251
246
252
The 95% credible ellipse is well-centered on the true (MLE) values with moderate positive correlation: higher φ means slightly higher p, but the correlation is weak (≈ 0.3). This is the expected pattern — a larger dispersion naturally pairs with a slightly higher power parameter since both push in the same direction (more variance). The key point is that the posterior is **not** degenerate along the φ-p diagonal, confirming both parameters are separately identifiable from the data.
247
253
248
-
Posterior predictive checks (PPC) are a critical validation step in Bayesian workflow. Because the `Tweedie` wrapper provides `tweedie_dist` as the `dist` argument to `CustomDist`, PyMC handles posterior predictive sampling automatically:
254
+
Posterior predictive checks (PPC) are a critical validation step in Bayesian workflow. Because the `Tweedie` wrapper provides `tweedie_random` as the `random` argument to `CustomDist`, PyMC handles posterior predictive sampling automatically:
249
255
250
256
```python title="Posterior predictive check — using pm.sample_posterior_predictive"
251
257
with model:
@@ -267,7 +273,7 @@ obs_stats = {
267
273
}
268
274
```
269
275
270
-
The key point: `tweedie_dist` defined in the `Tweedie` class is what `sample_posterior_predictive` uses under the hood to generate draws — no manual thinning or re-sampling needed.
276
+
The key point: `tweedie_random` defined in the `Tweedie` class is what `sample_posterior_predictive` uses under the hood to generate draws — no manual thinning or re-sampling needed.
0 commit comments