Code Monkey home page Code Monkey logo

Comments (2)

fonnesbeck avatar fonnesbeck commented on July 4, 2024

Can you try running this with the most recent version of PyMC (v5)?

from pymc-resources.

chiyu1203 avatar chiyu1203 commented on July 4, 2024

Can you try running this with the most recent version of PyMC (v5)?

Hello! I have tried the most recent version PyMC (v5). This time, I bumped into another error in an earlier cell so I am not sure if that would fix 5.34
Below is the new error I saw in 5.19

data["Divorce_std"] = standardize(data["Divorce"])
data["Marriage_std"] = standardize(data["Marriage"])
data["MedianAgeMarriage_std"] = standardize(data["MedianAgeMarriage"])

# Use Aesara shared variables so we can change them later
marriage_shared = shared(data["Marriage_std"].values)
age_shared = shared(data["MedianAgeMarriage_std"].values)

with pm.Model() as m5_3_A:
    # A -> D <- M
    sigma = pm.Exponential("sigma", 1)
    bA = pm.Normal("bA", 0, 0.5)
    bM = pm.Normal("bM", 0, 0.5)

    a = pm.Normal("a", 0, 0.2)
    mu = pm.Deterministic("mu", a + bA * age_shared + bM * marriage_shared)
    divorce = pm.Normal("divorce", mu, sigma, observed=data["Divorce_std"].values)

    # A -> M
    sigma_M = pm.Exponential("sigma_m", 1)
    bAM = pm.Normal("bAM", 0, 0.5)
    aM = pm.Normal("aM", 0, 0.2)
    mu_M = pm.Deterministic("mu_m", aM + bAM * age_shared)
    marriage = pm.Normal("marriage", mu_M, sigma_M, observed=data["Marriage_std"].values)

    m5_3_A_trace = pm.sample()

NotImplementedError Traceback (most recent call last)
Cell In[33], line 16
13 bM = pm.Normal("bM", 0, 0.5)
15 a = pm.Normal("a", 0, 0.2)
---> 16 mu = pm.Deterministic("mu", a + bA * age_shared + bM * marriage_shared)
17 divorce = pm.Normal("divorce", mu, sigma, observed=data["Divorce_std"].values)
19 # A -> M

File ~\anaconda3\envs\pymc_env\Lib\site-packages\aesara\tensor\var.py:207, in _tensor_py_operators.rmul(self, other)
206 def rmul(self, other):
--> 207 return at.math.mul(other, self)

File ~\anaconda3\envs\pymc_env\Lib\site-packages\aesara\graph\op.py:297, in Op.call(self, *inputs, **kwargs)
255 r"""Construct an Apply node using :meth:Op.make_node and return its outputs.
256
257 This method is just a wrapper around :meth:Op.make_node.
(...)
294
295 """
296 return_list = kwargs.pop("return_list", False)
--> 297 node = self.make_node(*inputs, **kwargs)
299 if config.compute_test_value != "off":
300 compute_test_value(node)

File ~\anaconda3\envs\pymc_env\Lib\site-packages\aesara\tensor\elemwise.py:484, in Elemwise.make_node(self, *inputs)
478 def make_node(self, *inputs):
479 """
480 If the inputs have different number of dimensions, their shape
481 is left-completed to the greatest number of dimensions with 1s
482 using DimShuffle.
483 """
--> 484 inputs = [as_tensor_variable(i) for i in inputs]
485 out_dtypes, out_shapes, inputs = self.get_output_info(DimShuffle, *inputs)
486 outputs = [
487 TensorType(dtype=dtype, shape=shape)()
488 for dtype, shape in zip(out_dtypes, out_shapes)
489 ]

File ~\anaconda3\envs\pymc_env\Lib\site-packages\aesara\tensor\elemwise.py:484, in (.0)
478 def make_node(self, *inputs):
479 """
480 If the inputs have different number of dimensions, their shape
481 is left-completed to the greatest number of dimensions with 1s
482 using DimShuffle.
483 """
--> 484 inputs = [as_tensor_variable(i) for i in inputs]
485 out_dtypes, out_shapes, inputs = self.get_output_info(DimShuffle, *inputs)
486 outputs = [
487 TensorType(dtype=dtype, shape=shape)()
488 for dtype, shape in zip(out_dtypes, out_shapes)
489 ]

File ~\anaconda3\envs\pymc_env\Lib\site-packages\aesara\tensor_init_.py:49, in as_tensor_variable(x, name, ndim, **kwargs)
17 def as_tensor_variable(
18 x: TensorLike, name: Optional[str] = None, ndim: Optional[int] = None, **kwargs
19 ) -> "TensorVariable":
20 """Convert x into an equivalent TensorVariable.
21
22 This function can be used to turn ndarrays, numbers, ScalarType instances,
(...)
47
48 """
---> 49 return _as_tensor_variable(x, name, ndim, **kwargs)

File ~\anaconda3\envs\pymc_env\Lib\functools.py:909, in singledispatch..wrapper(*args, **kw)
905 if not args:
906 raise TypeError(f'{funcname} requires at least '
907 '1 positional argument')
--> 909 return dispatch(args[0].class)(*args, **kw)

File ~\anaconda3\envs\pymc_env\Lib\site-packages\aesara\tensor_init_.py:56, in _as_tensor_variable(x, name, ndim, **kwargs)
52 @singledispatch
53 def _as_tensor_variable(
54 x: TensorLike, name: Optional[str], ndim: Optional[int], **kwargs
55 ) -> "TensorVariable":
---> 56 raise NotImplementedError(f"Cannot convert {x!r} to a tensor variable.")

NotImplementedError: Cannot convert bA to a tensor variable.

Last but not least, this is my computer setting:
Window11, anaconda, pymc v5
conda create -c conda-forge -n pymc_env "pymc>=5"
Libraries required for this notebook were installed as below:
pip install notebook, patsy, causalgraphicalmodels, daft, theano
conda install -c conda-forge watermark, seaborn, tqdm, aesara==2.8.7
Initially, I was hoping to install all the libraries according to the environment yaml file for pymc v4. However, there was some verion conflicts so I ended up installing some of the libraries via pip.
Please feel free to let me know if you have any thought.

from pymc-resources.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.