I am learning the pymc package from the book “Bayesian Methods for Hackers: Probabilistic Programming and Bayesian Inference”. While executing some codes shown in the picture, I got errors. Does anybody know where is the problem? Is it because of the package installation or version? The code outputs

For installation of pymc packages, I followed the instruction of Installation — PyMC 5.1.1 documentation

Python Codes:

```
import pymc as pm
with pm.Model() as model:
lambda_1 = pm.Exponential("lambda_1", 1)
lambda_2 = pm.Exponential("lambda_2", 1)
tau = pm.DiscreteUniform("tau", lower=0, upper=10)
lambda_1.value
```

```
AttributeError Traceback (most recent call last)
Cell In[4], line 6
3 lambda_2 = pm.Exponential("lambda_2", 1) # prior on second behavior
4 tau = pm.DiscreteUniform("tau", lower=0, upper=10)
----> 6 lambda_1.value
AttributeError: 'TensorVariable' object has no attribute 'value'
```

```
@pm.Deterministic
def lambda_(tau=tau, lambda_1=lambda_1, lambda_2=lambda_2):
out = np.zeros(n_data_points)
out[:tau] = lambda_1 # lambda before tau is lambda 1
out[tau:] = lambda_2 # lambda after tau is lambda 2
return out
```

```
TypeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 @pm.Deterministic
2 def lambda_(tau=tau, lambda_1=lambda_1, lambda_2=lambda_2):
3 out = np.zeros(n_data_points)
4 out[:tau] = lambda_1 # lambda before tau is lambda 1
TypeError: Deterministic() missing 1 required positional argument: 'var'
```

hello @azadeh_fallah ! as you can see the error occurred because pymc.exponential has no attribute called value pymc.Exponential — PyMC 5.1.1 documentation here is the link to documentation for further details.

Hi @Aniket_Pancharia. Yes, that is right, but in the book **.value** is used. You can see that in the link below:

1 Like

Be aware that notebook is using PyMC version **2.0**. The current version is 5.x. So you should not expect much of what is used in that notebook to work with a current installation.

[edit] Versions of some of the notebooks from that book written in PyMC version 3.0 can be found here. Those will be somewhat more useful, but you should still expect some breakage.

1 Like

I tried to install older versions of pymc like 2.3.4 but I could not.

Could you please guide me on how to access the source of pymc==2.3.4?

I would like to add the alternative channel to my anaconda navigator.

Have you tried `pip install pymc==2.3.4`

as documented here?

Yes, but since the source is unavailable, the anaconda prompt can not install it. So, I tried a lot to install any version of pymc 2.x. Finally, I found this way as a solution:

- Create an env using the anaconda environment tab with python 3.8.16.
- Simply install pymc 2.3.8 (still use the anaconda environment tab).

Thank you so much for your previous guide.

2 Likes

@azadeh_fallah you should try out the newer version of pymc since it has more tools and updates plus there is a smaller chance of failure in it too due to all the updated features and documentation supporting it . So please give it a try.

1 Like

Yes, that is right, But I could not find the corresponding code of this book (Chapter 3 of the book) with the new version of pymc.

I did not get any examples of MCMC modelling with it.