Comments (5)
This issue seems to describe what is the problem: pymc-devs/pymc#5443
And this code snippet gave me the correct answers (using PyMC 5.1.1): pymc-devs/pymc#5443 (comment)
It seems like we need to use .rvs_to_tranforms
to access and remove the log transform, instead of accessing it through .tag.transform
Just be careful, as this will probably also change the underlying model
Hope it helps
from pymc-resources.
I think I hit the same problem. I'm running PyMC 5.0.2. I dug online and got to this. Worked for me but doesn't look efficient (two models).
with pm.Model() as m:
p = pm.Uniform("p", 0, 1) # uniform priors
w = pm.Binomial("w", n=len(data), p=p, observed=data.sum()) # binomial likelihood
mean_q = pm.find_MAP()
#calculating std_dev without trasforming... I think it was in the log space. Unbounded???
with pm.Model() as untransformed_m:
p = pm.Uniform("p", 0, 1,transform=None) # uniform priors
w = pm.Binomial("w", n=len(data), p=p, observed=data.sum(),transform=None) # this seems to be the difference
std_q = ((1 / pm.find_hessian(mean_q, vars=[p])) ** 0.5)[0]
print("Mean, Standard deviation\np {:.2}, {:.2}".format(mean_q["p"], std_q[0]))
from pymc-resources.
Had the same issue! Did you find a solution for that?
Very Best!
from pymc-resources.
Something like the below works for me. Still no fundamental solutions. This is trying to work with actual samples from the posterior (there is some variability because they are just samples). The original method I think is faster and fancier but running into difficulties with how its handled behind the scenes.
data = np.repeat((0, 1), (3, 6))
with pm.Model() as normal_approximation:
p = pm.Uniform("p", 0, 1) # uniform priors
w = pm.Binomial("w", n=len(data), p=p, observed=data.sum()) # binomial likelihood
mean_q = pm.find_MAP()
std_q = ((1 / pm.find_hessian(mean_q, vars=[p])) ** 0.5)[0]
idata = pm.sample() #taking actual samples here with default values
# display summary of quadratic approximation
print("Mean, Standard deviation\np {:.2}, {:.2}".format(mean_q["p"], std_q[0]))
print("SAMPLE:\nMean, Standard deviation\np {:.2}, {:.2}".format(idata.posterior['p'].mean(),idata.posterior['p'].std()))
I'm basing this on a discussion in the pymc forum.
from pymc-resources.
Hi, @LukeBenjaminT. Your solution works. Could you please provide the link of your post on the forum?
Something like the below works for me. Still no fundamental solutions. This is trying to work with actual samples from the posterior (there is some variability because they are just samples). The original method I think is faster and fancier but running into difficulties with how its handled behind the scenes.
data = np.repeat((0, 1), (3, 6)) with pm.Model() as normal_approximation: p = pm.Uniform("p", 0, 1) # uniform priors w = pm.Binomial("w", n=len(data), p=p, observed=data.sum()) # binomial likelihood mean_q = pm.find_MAP() std_q = ((1 / pm.find_hessian(mean_q, vars=[p])) ** 0.5)[0] idata = pm.sample() #taking actual samples here with default values # display summary of quadratic approximation print("Mean, Standard deviation\np {:.2}, {:.2}".format(mean_q["p"], std_q[0])) print("SAMPLE:\nMean, Standard deviation\np {:.2}, {:.2}".format(idata.posterior['p'].mean(),idata.posterior['p'].std()))
I'm basing this on a discussion in the pymc forum.
from pymc-resources.
Related Issues (20)
- Resources/Rethinking_2/Chp_04.ipynb - Question HOT 1
- Chapter 5 Code 5.19: Effect of marriage on divorce A->M->D HOT 1
- Chp_14 potentially incorrect covariance functions HOT 2
- Rethinking_2 environment.yml installs pymc and not pymc3 HOT 2
- Add Bayes Rules Chapter 2 HOT 1
- Fix up env for bayes rules
- Chapter 5 - Code 5.29 should use log(mass) HOT 3
- Chp_02.ipynb, import statement HOT 2
- Conflicting chain size for code block 4.59
- causalgraphicalmodels import error with Python 3.10 HOT 5
- Chapter 5 import error when running pymc model HOT 9
- Chp_11 notebook - models not running - Got error No model on context stack
- Incompatibilities with Python 3.10 for the aesara 2.6.6 and causalgraphicalmodels-0.0.4 packages.
- issue importing pymc3 "cannot import as scalar from numpy"
- Error for code snippet 8.8 - NotImplementedError HOT 3
- Adding exposition about PyMC and Arviz to the Rethinking_2 code.
- Type error - Code 15.12 - pymc v4 HOT 4
- Resources/Rethinking_2/Chp_04.ipynb: The hyperlink in Code 4.26 is broken HOT 1
- Gender Categories in Chapter 4
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-resources.