aloctavodia / BAP3

Figures and code examples from Bayesian Analysis with Python (third edition)
http://bap.com.ar/
112 stars 29 forks source link

Not sure what pz is? #9

Closed sharpclarke closed 3 months ago

sharpclarke commented 3 months ago

Sorry if this is the wrong place for this, as it's probably not an error as much as a misunderstanding. But I have followed all the installation instructions and have activated a bap3 environment in conda, and when I try to write commands that use "pz" such as "pz.BetaBinomal()" I am getting an error. I have scoured Google and ChatGPT in search of answers but just can't get this code to run correctly. Am I missing something?

aloctavodia commented 3 months ago

pz stands for preliz. Usually all imports are in the first cell of each notebook. You will see the line "import preliz as pz".

What error are you getting?

sharpclarke commented 3 months ago

Thank you very much for your quick reply. I didn't see the import code in the book itself, but now that I go to the code in the github I can see it. That addresses my main error - now I just need to figure out how to use the bap3 environment in a Jupyter notebook but I can figure that out! Thanks again.

aloctavodia commented 3 months ago

On Linux or Mac you run "conda activate bap3" from a terminal and then run "jupyter notebook". Not sure on Windows, but I think you can run the same commands if you first find and run the "Anaconda prompt" from the start menu.

Some IDES support notebooks. For instance VsCode supports notebooks (after installing a python plugin).

sharpclarke commented 3 months ago

Thank you so much. That worked. I am self-taught and have previously only used terminal to run my python programs (not Jupyter) so just learning something new. Thanks for all your hard work on this.

sharpclarke commented 3 months ago

Hi Osvaldo, sorry to bother you again. I am on Chapter 2 and tried to create my first model using the code:

with pm.Model() as our_first_model: theta = pm.Beta('theta', alpha=1., beta=1.) # Specifies the prior y = pm.Bernoulli('y', p=theta, observed=data) # Specifies the likelihood idata = pm.sample(1000)

I have the right imports. I am getting a litany of errors (pages of messages) starting with this:

WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

You can find the C code in this temporary file: /var/folders/mf/bvt1s84s18b36l4wbn86s2lc0000gn/T/pytensor_compilation_error_fosqurhy ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding ERROR (pytensor.graph.rewriting.basic): node: DropDims{axis=0}([4]) ERROR (pytensor.graph.rewriting.basic): TRACEBACK: ERROR (pytensor.graph.rewriting.basic): Traceback (most recent call last): File "/opt/anaconda3/envs/bap3/lib/python3.11/site-packages/pytensor/graph/rewriting/basic.py", line 1922, in process_node replacements = node_rewriter.transform(fgraph, node)

There are pages and pages of error notices with "7 errors generated" at the bottom. I'm really stuck after doing some more Googling and can't seem to figure out why I can't run the code. I have activated the bap3 environment in conda.

Is it possible I made errors while installing packages (using pip initially then moving to conda install)? And if so, how do I fix this?

Again, appreciate your time if you have a moment to help.

aloctavodia commented 3 months ago

yeah, it seems you made a mistake while installing packages. You can try deleting the env and starting fresh. Or uninstalling pymc and pytensor, and installing them again. Just to be sure attempt to uninstall the packages using both pip and conda.

sharpclarke commented 3 months ago

Thanks again. I tried both (uninstalling pymc and pytensor with pip and conda, as well as deleting the bap3 env I was using). Then I only used the recommended installation from the book (conda env create -f bap3.yml using the file from the github). It's giving the same error.

Not sure if this means something, but when I use "conda activate bap3" I get this error:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

It still shifts from base to bap3 so I assumed it was not impacting the environment but maybe it is.

I apologize for all the issues here. I am very motivated to get this to work.

On Mon, Mar 11, 2024 at 12:42 PM Osvaldo A Martin @.***> wrote:

yeah, it seems you made a mistake while installing packages. You can try deleting the env and starting fresh. Or uninstalling pymc and pytensor, and installing them again. Just to be sure attempt to uninstall the packages using both pip and conda.

— Reply to this email directly, view it on GitHub https://github.com/aloctavodia/BAP3/issues/9#issuecomment-1989188312, or unsubscribe https://github.com/notifications/unsubscribe-auth/BG3B3BGG6CZVKPHRX63NLUDYXX3I7AVCNFSM6AAAAABEPK6DSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBZGE4DQMZRGI . You are receiving this because you authored the thread.Message ID: @.***>

sharpclarke commented 3 months ago

I figured it out!

In case it's helpful to anyone reading this: I had to install xcode on my mac.

On Mon, Mar 11, 2024 at 1:05 PM SharpClarke @.***> wrote:

Thanks again. I tried both (uninstalling pymc and pytensor with pip and conda, as well as deleting the bap3 env I was using). Then I only used the recommended installation from the book (conda env create -f bap3.yml using the file from the github). It's giving the same error.

Not sure if this means something, but when I use "conda activate bap3" I get this error:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

It still shifts from base to bap3 so I assumed it was not impacting the environment but maybe it is.

I apologize for all the issues here. I am very motivated to get this to work.

On Mon, Mar 11, 2024 at 12:42 PM Osvaldo A Martin < @.***> wrote:

yeah, it seems you made a mistake while installing packages. You can try deleting the env and starting fresh. Or uninstalling pymc and pytensor, and installing them again. Just to be sure attempt to uninstall the packages using both pip and conda.

— Reply to this email directly, view it on GitHub https://github.com/aloctavodia/BAP3/issues/9#issuecomment-1989188312, or unsubscribe https://github.com/notifications/unsubscribe-auth/BG3B3BGG6CZVKPHRX63NLUDYXX3I7AVCNFSM6AAAAABEPK6DSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBZGE4DQMZRGI . You are receiving this because you authored the thread.Message ID: @.***>