Problems running the Probabilistic Matrix Factorization example from the docs

Hi Everyone!! I am new to PyMC and Im looking to implement a model similar to the the following example from the docs.

Probabilistic matrix factorization

I’m getting a type error while building the model. I’m running the notebooks as it is in the page in colab, with no modifications. The problem is in the definition for the rating prior, but I cant understand exactly what is going wrong and how to fix it.

Any help would be appreciated!

Summary
INFO:root:building the PMF model
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-d6e9dbffb6ce> in <cell line: 17>()
     15 
     16 
---> 17 pmf = PMF(train, DIM, ALPHA, std=0.05)

7 frames
<ipython-input-12-08080fd9169d> in __init__(self, train, dim, alpha, std, bounds)
     68                 initval=rng.standard_normal(size=(m, dim)) * std,
     69             )
---> 70             R = pm.Normal(
     71                 "R",
     72                 mu=(U @ V.T)[~nan_mask],

/usr/local/lib/python3.10/dist-packages/pymc/distributions/distribution.py in __new__(cls, name, rng, dims, initval, observed, total_size, transform, *args, **kwargs)
    314         rv_out = cls.dist(*args, **kwargs)
    315 
--> 316         rv_out = model.register_rv(
    317             rv_out,
    318             name,

/usr/local/lib/python3.10/dist-packages/pymc/model.py in register_rv(self, rv_var, name, observed, total_size, dims, transform, initval)
   1310             # `rv_var` is potentially changed by `make_obs_var`,
   1311             # for example into a new graph for imputation of missing data.
-> 1312             rv_var = self.make_obs_var(rv_var, observed, dims, transform, total_size)
   1313 
   1314         return rv_var

/usr/local/lib/python3.10/dist-packages/pymc/model.py in make_obs_var(self, rv_var, data, dims, transform, total_size)
   1350             if test_value is not None:
   1351                 # We try to reuse the old test value
-> 1352                 rv_var.tag.test_value = np.broadcast_to(test_value, rv_var.shape)
   1353             else:
   1354                 rv_var.tag.test_value = data

/usr/local/lib/python3.10/dist-packages/numpy/core/overrides.py in broadcast_to(*args, **kwargs)

/usr/local/lib/python3.10/dist-packages/numpy/lib/stride_tricks.py in broadcast_to(array, shape, subok)
    411            [1, 2, 3]])
    412     """
--> 413     return _broadcast_to(array, shape, subok=subok, readonly=True)
    414 
    415 

/usr/local/lib/python3.10/dist-packages/numpy/lib/stride_tricks.py in _broadcast_to(array, shape, subok, readonly)
    343     if not shape and array.shape:
    344         raise ValueError('cannot broadcast a non-scalar to a scalar array')
--> 345     if any(size < 0 for size in shape):
    346         raise ValueError('all elements of broadcast shape must be non-'
    347                          'negative')

/usr/local/lib/python3.10/dist-packages/pytensor/tensor/var.py in __bool__(self)
     70             return True
     71         else:
---> 72             raise TypeError("Variables do not support boolean operations.")
     73 
     74     def __invert__(self):

TypeError: Variables do not support boolean operations.

Welcome!

I think this may be an issue with the version of PyMC/PyTensor currently available on Colab. That notebook seems to be working ok with the latest versions on my machine. This may be related to this which was fixed in 5.9.2. Colab is currently running 5.7.2 (the current version is 5.10.2, FYI). So if you can run it locally, that may solve your issue.

1 Like

thank you! indeed running it offline has worked fine!

1 Like