pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.68k stars 2.01k forks source link

BUG: AttributeError: '_FutureWarningValidatingScratchpad' object has no attribute 'test_value' #6452

Open RichardScottOZ opened 1 year ago

RichardScottOZ commented 1 year ago

Describe the issue:

New to trying out pymc3

trying this:

Reproduceable code example:

import pymc as pm
with pm.Model() as model:
    # Define the model variables
    alpha = pm.Normal('alpha', 0, 1)
    beta = pm.Normal('beta', 0, 1)
    sigma = pm.Normal('sigma', 0, 20)
    # Define the model equation
    y_pred = np.zeros(len(returns))
    y_pred[0] = returns[0]
    for i in range(1, len(returns)):
        y_pred[i] = sigma.tag.test_value * (1-alpha.tag.test_value-beta.tag.test_value) + alpha.tag.test_value * returns[i-1]**2 + beta.tag.test_value * y_pred[i-1]
    garch_eq = pm.Deterministic('garch_eq', y_pred)
    # Specify the likelihood function
    likelihood = pm.Normal('y', mu=garch_eq, tau=1.0/sigma.tag.test_value**2, observed=returns)
    # Run the model
    mcmc = pm.MCMC(model)
    mcmc.sample(iter=50000, burn=20000)

Error message:

Traceback (most recent call last)
Cell In[127], line 10
      8 y_pred[0] = returns[0]
      9 for i in range(1, len(returns)):
---> 10     y_pred[i] = sigma.tag.test_value * (1-alpha.tag.test_value-beta.tag.test_value) + alpha.tag.test_value * returns[i-1]**2 + beta.tag.test_value * y_pred[i-1]
     11 garch_eq = pm.Deterministic('garch_eq', y_pred)
     12 # Specify the likelihood function

File ~\AppData\Local\Continuum\anaconda3\envs\copper\lib\site-packages\pymc\util.py:505, in _FutureWarningValidatingScratchpad.__getattribute__(self, name)
    500         else:
    501             warnings.warn(
    502                 f"The tag attribute {name} is deprecated. Use {alternative} instead",
    503                 FutureWarning,
    504             )
--> 505 return super().__getattribute__(name)

File ~\AppData\Local\Continuum\anaconda3\envs\copper\lib\site-packages\pytensor\graph\utils.py:284, in Scratchpad.__getattribute__(self, name)
    283 def __getattribute__(self, name):
--> 284     return super().__getattribute__(name)

PyMC version information:

pymc 5.0.1 hd8ed1ab_0 conda-forge pymc-base 5.0.1 pyhd8ed1ab_0 conda-forge pytensor 2.8.11 py38hd636df3_1 conda-forge pytensor-base 2.8.11 py38haa244fe_1 conda-forge python 3.8.15 h4de0772_0_cpython conda-forge

Windows 10 Conda

Context for the issue:

just a test: test_vallue seems to get exist

image

michaelosthege commented 1 year ago

Your example looks like pymc2 which is severely outdated. Make sure to check the documentation at https://pymc.io

RichardScottOZ commented 1 year ago

Ok - said link currently not working, FYI.

RichardScottOZ commented 1 year ago

Right _ had looked at the 5.01 docs Friday - there's apparently a GARCH11 built-in, but didn't find any examples of such - are there any you are aware of?

ricardoV94 commented 1 year ago

Acting on tags won't have any effect on PyMC model.

For the GARCH11, maybe the tests provide an example? https://github.com/pymc-devs/pymc/blob/457421b621087ad9ff50bde5aaa02e9256e35a40/tests/distributions/test_timeseries.py#L724-L772

Seems to be doing something similar to what you were trying? Would be good to add a docstring example though