-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Lincoln Index - Three parameter model #62
Comments
Here is the entire script leading up to the problem: Priorsparams N, p0, p1, reuse prior_Nqs = np.linspace(0, 1, num=51) Assemble into joint prior w/ 3-dimput first two into DataFramejoint2 = make_joint(prior_p0, prior_N) Stack and put result into a Pmfjoint2_pmf = Pmf(joint2.stack()) Use make_joint again to add in 3rd paramjoint3 = make_joint(prior_p1, joint2_pmf) joint3.head(3) result is a DataFrame w/ values of N & p0 in a multi-index that goes down the rowsand values of p1 in an index that goes across the columnsapply stack againjoint3_pmf = Pmf(joint3.stack()) joint3_pmf.shape Loop that computes the likelihoodslikelihood = joint3_pmf.copy() for N, p0, p1 in joint3_pmf.index: |
Hi. To make sure I understand the question, are you reporting an error in my code or asking for help debugging? |
Hi - I used to code as it was written in the book and received an error; however, I'm not sure if there is a code error or a different issue and wanted to see if you had a suggestion as to why the code won't work as written. |
Here's the notebook where you can run the code (which works for me): https://colab.research.google.com/github/AllenDowney/ThinkBayes2/blob/master/notebooks/chap15.ipynb In the notebook you can print some of the intermediate values, or check the shape of the arrays/DataFrames. That should help with debugging. |
Shapes of the arrays match what was expected in the book. As do the heads up until joint3_pmf. At that point, the triplet doesn't show up, only a pair. It seems there is some issue with make_joint, Pmf, and stack, which has worked fine until now. |
When you run the code in the notebook I linked, does it work? |
Yes, it does. I understand the problem is on my end. Do you have any thoughts as to why this issue emerged in this instance of the three-parameter, but never before? |
If you display |
Yes - here's the first row: MultiIndex([((0.0, 0.0), 32) |
MultiIndex([((0.0, 0.0), 32), |
Yup, that's a sequence of pairs, where the first of each pair is a pair, so that's not the same as a sequence of triples.
So either there's a difference between your code and mine or a difference between your environment and mine. I think it's unlikely to be an environment issue, so I'd look for a difference in the code.
|
Thank you Allen - I will go through the code again. After running into the issue, I re-wrote the code and still had the problem and then copied it directly, but still no joy. |
Maybe put it in a Colab notebook. That would eliminate the environmental explanation. In the process, you might find the problem. If not, you could share the notebook with me. |
I will do that. |
Here's the script: Three parameter modelPriorsparams N, p0, p1, reuse prior_Nprior_Nqs = np.arange(32, 350, step=5) prior_p0, prior_p1qs = np.linspace(0, 1, num=51) prior_p0.head(3) Assemble into joint prior w/ 3-dimput first two into DataFramejoint2 = make_joint(prior_p0, prior_N) Stack and put result into a Pmfjoint2_pmf = Pmf(joint2.stack()) Use make_joint again to add in 3rd paramjoint3 = make_joint(prior_p1, joint2_pmf) joint3.head(10) result is a DataFrame w/ values of N & p0 in a multi-index that goes down the rowsand values of p1 in an index that goes across the columnsapply stack againjoint3_pmf = Pmf(joint3.stack()) joint3_pmf.shape Loop that computes the likelihoodslikelihood = joint3_pmf.copy() from scipy.stats import multinomial for N, p0, p1 in joint3_pmf.index: |
It's an environment issue, works in Jupyter but not Spyder unfortunately. |
What's interesting is that this does not work in Jupyter but does work in Spyder. The following was copied directly - no modification. Result is that the contour plot won't render. However, Spyder did not have this issue. observed = k01 + k10 + k11 for N, p in joint_pmf.index: TypeError Traceback (most recent call last) TypeError: 'numpy.float64' object does not support item assignment |
I am receiving the following error when I attempt to compute the likelihood in the three parameter model:
for N, p0, p1 in joint3_pmf.index:
ValueError: not enough values to unpack (expected 3, got 2)
I think the issue is that when I attempt to use make_joint using p1 and the joint2_pmf, I do not get the triplet, but rather only the pair, mean p1 is not attaching and thus the multi-index only has 2 items instead of three.
Do you have any suggestions about how best to fix?
Thank you
The text was updated successfully, but these errors were encountered: