Comments (5)
@NathanielF would you like to have a look at this? Or do you want me to see if I can fix it?
from pymc-examples.
Feel free to have a look @erik-werner ! Thanks for bringing it up
from pymc-examples.
Just a note here @erik-werner
Had a quick look. I think the code you want to run is :
def make_model(priors, model_spec=1, constrained_uniform=False, logit=True):
with pm.Model() as model:
if constrained_uniform:
cutpoints = constrainedUniform(K, 0, K)
else:
sigma = pm.Exponential("sigma", priors["sigma"])
cutpoints = pm.Normal(
"cutpoints",
mu=priors["mu"],
sigma=sigma,
transform=pm.distributions.transforms.univariate_ordered,
)
if model_spec == 1:
beta = pm.Normal("beta", priors["beta"][0], priors["beta"][1], size=1)
mu = pm.Deterministic("mu", beta[0] * df.salary)
elif model_spec == 2:
beta = pm.Normal("beta", priors["beta"][0], priors["beta"][1], size=2)
mu = pm.Deterministic("mu", beta[0] * df.salary + beta[1] * df.work_sat)
elif model_spec == 3:
beta = pm.Normal("beta", priors["beta"][0], priors["beta"][1], size=3)
mu = pm.Deterministic(
"mu", beta[0] * df.salary + beta[1] * df.work_sat + beta[2] * df.work_from_home
)
if logit:
y_ = pm.OrderedLogistic("y", cutpoints=cutpoints, eta=mu, observed=df.explicit_rating)
else:
y_ = pm.OrderedProbit("y", cutpoints=cutpoints, eta=mu, observed=df.explicit_rating)
if not logit:
idata = pm.sample(idata_kwargs={"log_likelihood": True})
else:
idata = pm.sample(nuts_sampler="numpyro", idata_kwargs={"log_likelihood": True})
idata.extend(pm.sample_posterior_predictive(idata))
return idata, model
priors = {"sigma": 1, "beta": [0, 1], "mu": np.linspace(0, K, K - 1)}
idata1, model1 = make_model(priors, model_spec=1)
idata2, model2 = make_model(priors, model_spec=2)
idata3, model3 = make_model(priors, model_spec=3)
idata4, model4 = make_model(priors, model_spec=3, constrained_uniform=True)
idata5, model5 = make_model(priors, model_spec=3, constrained_uniform=True, logit=False)
Models 1 and 2 are kind of underspecified so you will get divergences. The interesting contrasts are between the models 3 and 4 where we use the constrained uniform on the cutpoints. If you fix the fifth model to use the default sampler rather than numpyro you should be able to run the probit fit.
This is also arguably an interesting contrast just to see how the parameter values shift...
I think i wouldn't remove models 1 and 2 but i'd add text discussing how a better specified model avoids the issues with divergences that you've highlighted
from pymc-examples.
@NathanielF These were basically my conclusions as well 🙂
One more thing: It seems like the divergences for models 1&2 occur when sigma
is very close to 0, so in principle one could probably get rid of most divergences with a non-centered parametrisation. But that doesn't combine well with the ordered transform.
I wonder why the numpyro sampler cannot handle the probit model.
Anyway, since you have a better overview of the whole flow, and seem to have an idea about what to write, it would be great if you'd like to update the notebook.
from pymc-examples.
Sure thing @erik-werner. Will do.
On numpyro i think it has to do with the lack of parity between the jax implementation of ercf function in scipy.
Thanks again for bringing the issue to my attention.
from pymc-examples.
Related Issues (20)
- Notebook Profiling needs to update to v5
- Slight Mis-Interpretation of Discrete Choice Theory HOT 2
- Broken link in MLDA example notebook HOT 1
- Broken link in MLDA intro page HOT 1
- Propensity Score Non-Parametric Models HOT 1
- Should you buy a house battery? HOT 2
- wrapping jax example code cell 22 returns error HOT 14
- Notebook Proposal : Time Series Modeling with HSGP: Baby Births Example HOT 2
- Do operator example still mentions PyMC-Experimental HOT 4
- pre-commit-ci fails HOT 6
- Divergences in Bayesian Non-parametric Causal Inference PyMC 5.10+
- Errors in "Introduction to Variational Inference with PyMC" notebook HOT 1
- Proposal: Add HSGP reference and examples
- Bug copying URL on iPhone HOT 1
- Bug in "Variational Inference: Bayesian Neural Networks" notebook HOT 2
- Highlight backends in "faster sampler nb"
- Math rendering issue in golf putting example HOT 4
- Update data container notebook to reflect changes to `pm.Data` HOT 1
- Broken link in Weibull Accelerated Failure Time Model notebook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymc-examples.