import pymc as pm
import numpy as np
import theano.tensor as tt
# Set values for the prior parameters
gamma_mode = 0.5
gamma_variance = 2.0
t_star_mode = 15.0
t_star_variance = 100.0
s_star = 0.88
lambda_ = -np.log(s_star)
# Definition of prior for gamma
aux1 = 2.0 + (gamma_mode**2.0) / gamma_variance
a = 0.5 * (aux1 + np.sqrt(aux1**2.0 - 4.0))
b = gamma_mode / (a - 1.0)
b1 = 1.0 / b
# Definition of prior for t_star
aux2 = 2.0 + (t_star_mode**2.0) / t_star_variance
ap = 0.5 * (aux2 + np.sqrt(aux2**2.0 - 4.0))
bp = t_star_mode / (ap - 1.0)
b2 = 1.0 / bp
# Define the model
model = pm.Model()
# Observed data (censored)
t = np.array([25.62191781, 25.35616438, 25.34246575, 25.29589041, 24.61643836,
24.34794521, 24.30410959,
24.06027397, 23.81643836, 23.50410959, 23.2109589, 23.14520548,
22.97808219, 22.70410959,
21.90684932, 21.81917808, 21.36986301, 20, 19.5260274])
# Function to calculate log complementary cdf of Weibull distribution
def weibull_lccdf(x, t_star, gamma):
return -(lambda_ * (x / t_star) ** gamma)
with model:
# Definition of priors for gamma and t_star
gamma = pm.Gamma('gamma', alpha=a, beta=1/b)
t_star = pm.Gamma('t_star', alpha=ap, beta=1/bp)
# Bus survivor calculation
surv = pm.Deterministic('surv', tt.exp(-lambda_ * (tt.arange(1, 26) / t_star) ** gamma))
# Define likelihood
y_cens = pm.Potential("y_cens", weibull_lccdf(t, t_star, gamma))
# Sample from the model
trace = pm.sample(draws=10000, tune=1000)
summary = pm.summary(trace)
print(summary)
When executing this model i have this error:
AttributeError Traceback (most recent call last)
<ipython-input-3-e5d7e600a407> in <module>
1 import pymc as pm
2 import numpy as np
----> 3 import theano.tensor as tt
4
5 # Set values for the prior parameters
~\Anaconda3\lib\site-packages\theano\__init__.py in <module>
81 __api_version__ = 1
82
---> 83 from theano import scalar, tensor
84 from theano.compile import (
85 In,
~\Anaconda3\lib\site-packages\theano\scalar\__init__.py in <module>
----> 1 from .basic import *
2 from .basic_scipy import *
~\Anaconda3\lib\site-packages\theano\scalar\basic.py in <module>
2458
2459
-> 2460 convert_to_bool = Cast(bool, name="convert_to_bool")
2461 convert_to_int8 = Cast(int8, name="convert_to_int8")
2462 convert_to_int16 = Cast(int16, name="convert_to_int16")
~\Anaconda3\lib\site-packages\theano\scalar\basic.py in __init__(self, o_type, name)
2410 super().__init__(specific_out(o_type), name=name)
2411 self.o_type = o_type
-> 2412 self.ctor = getattr(np, o_type.dtype)
2413
2414 def __str__(self):
~\AppData\Roaming\Python\Python38\site-packages\numpy\__init__.py in __getattr__(attr)
303
304 if attr in __former_attrs__:
--> 305 raise AttributeError(__former_attrs__[attr])
306
307 # Importing Tester requires importing all of UnitTest which is not a
AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
Can you please let me know what should I do ?