Great, thanks for the response! Now I’m getting somewhere. When I evaluate each of the variables, here is what I am getting:
#Print the shape of each evaluated variable:
[print(f"variable: {var}'s shape = {var.eval().shape}") for var in [sigma, chol_alpha_beta, alpha_beta, alpha, beta, mu, y_hat]]
Which yields this:
variable: sigma's shape = ()
variable: AdvancedSetSubtensor.0's shape = (2, 2)
variable: alpha_beta's shape = (100, 2)
variable: alpha's shape = (100,)
variable: beta's shape = (100,)
variable: Add.0's shape = (100,)
Already, it seems odd that sigma would have a shape of (). Why would that be? Shouldn’t it be (1,)? And it looks like alpha_beta is (100, 2) as expected, so where is this (100, 2, 3) matrix coming from?
But when it tries to evaluate the likelihood, I get the same ValueError as earlier (Including the whole traceback, just in case someone has some insight for me):
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/compile/function/types.py:970, in Function.__call__(self, *args, **kwargs)
968 try:
969 outputs = (
--> 970 self.vm()
971 if output_subset is None
972 else self.vm(output_subset=output_subset)
973 )
974 except Exception:
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/graph/op.py:549, in Op.make_py_thunk.<locals>.rval(p, i, o, n, params)
545 @is_thunk_type
546 def rval(
547 p=p, i=node_input_storage, o=node_output_storage, n=node, params=None
548 ):
--> 549 r = p(n, [x[0] for x in i], o)
550 for o in node.outputs:
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/tensor/random/op.py:340, in RandomVariable.perform(self, node, inputs, outputs)
338 rng_var_out[0] = rng
--> 340 smpl_val = self.rng_fn(rng, *(args + [size]))
342 if (
343 not isinstance(smpl_val, np.ndarray)
344 or str(smpl_val.dtype) != out_var.type.dtype
345 ):
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/tensor/random/op.py:129, in RandomVariable.rng_fn(self, rng, *args, **kwargs)
128 """Sample a numeric random variate."""
--> 129 return getattr(rng, self.name)(*args, **kwargs)
File numpy/random/_generator.pyx:1220, in numpy.random._generator.Generator.normal()
File _common.pyx:600, in numpy.random._common.cont()
File _common.pyx:505, in numpy.random._common.cont_broadcast_2()
File _common.pyx:384, in numpy.random._common.check_array_constraint()
ValueError: scale < 0
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
Cell In[1098], line 75
72 #likelihood
73 y_hat = pm.Normal('y_hat', mu, sigma=sigma, observed=y_t)
---> 75 [print(f"variable: {var}'s shape = {var.eval().shape}") for var in [sigma, chol_alpha_beta, alpha_beta, alpha, beta, mu, y_hat]]
Cell In[1098], line 75, in <listcomp>(.0)
72 #likelihood
73 y_hat = pm.Normal('y_hat', mu, sigma=sigma, observed=y_t)
---> 75 [print(f"variable: {var}'s shape = {var.eval().shape}") for var in [sigma, chol_alpha_beta, alpha_beta, alpha, beta, mu, y_hat]]
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/graph/basic.py:630, in Variable.eval(self, inputs_to_values)
627 self._fn_cache[inputs] = function(inputs, self)
628 args = [inputs_to_values[param] for param in inputs]
--> 630 rval = self._fn_cache[inputs](*args)
632 return rval
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/compile/function/types.py:983, in Function.__call__(self, *args, **kwargs)
981 if hasattr(self.vm, "thunks"):
982 thunk = self.vm.thunks[self.vm.position_of_error]
--> 983 raise_with_op(
984 self.maker.fgraph,
985 node=self.vm.nodes[self.vm.position_of_error],
986 thunk=thunk,
987 storage_map=getattr(self.vm, "storage_map", None),
988 )
989 else:
990 # old-style linkers raise their own exceptions
991 raise
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/link/utils.py:531, in raise_with_op(fgraph, node, thunk, exc_info, storage_map)
526 warnings.warn(
527 f"{exc_type} error does not allow us to add an extra error message"
528 )
529 # Some exception need extra parameter in inputs. So forget the
530 # extra long error message in that case.
--> 531 raise exc_value.with_traceback(exc_trace)
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/compile/function/types.py:970, in Function.__call__(self, *args, **kwargs)
967 t0_fn = time.perf_counter()
968 try:
969 outputs = (
--> 970 self.vm()
971 if output_subset is None
972 else self.vm(output_subset=output_subset)
973 )
974 except Exception:
975 restore_defaults()
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/graph/op.py:549, in Op.make_py_thunk.<locals>.rval(p, i, o, n, params)
545 @is_thunk_type
546 def rval(
547 p=p, i=node_input_storage, o=node_output_storage, n=node, params=None
548 ):
--> 549 r = p(n, [x[0] for x in i], o)
550 for o in node.outputs:
551 compute_map[o][0] = True
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/tensor/random/op.py:340, in RandomVariable.perform(self, node, inputs, outputs)
336 rng = copy(rng)
338 rng_var_out[0] = rng
--> 340 smpl_val = self.rng_fn(rng, *(args + [size]))
342 if (
343 not isinstance(smpl_val, np.ndarray)
344 or str(smpl_val.dtype) != out_var.type.dtype
345 ):
346 smpl_val = _asarray(smpl_val, dtype=out_var.type.dtype)
File ~/Desktop/research_river_imagery/research-river-imagery/venv/lib/python3.11/site-packages/pytensor/tensor/random/op.py:129, in RandomVariable.rng_fn(self, rng, *args, **kwargs)
127 def rng_fn(self, rng, *args, **kwargs) -> Union[int, float, np.ndarray]:
128 """Sample a numeric random variate."""
--> 129 return getattr(rng, self.name)(*args, **kwargs)
File numpy/random/_generator.pyx:1220, in numpy.random._generator.Generator.normal()
File _common.pyx:600, in numpy.random._common.cont()
File _common.pyx:505, in numpy.random._common.cont_broadcast_2()
File _common.pyx:384, in numpy.random._common.check_array_constraint()
ValueError: scale < 0
Apply node that caused the error: normal_rv{0, (0, 0), floatX, False}(RandomGeneratorSharedVariable(<Generator(PCG64) at 0x218320D60>), [100], 11, Composite{((i0 * i1) + i2)}.0, sigma)
Toposort index: 14
Inputs types: [RandomGeneratorType, TensorType(int64, shape=(1,)), TensorType(int64, shape=()), TensorType(float64, shape=(100,)), TensorType(float64, shape=())]
Inputs shapes: ['No shapes', (1,), (), (100,), ()]
Inputs strides: ['No strides', (8,), (), (8,), ()]
Inputs values: [Generator(PCG64) at 0x218320D60, array([100]), array(11), 'not shown', array(-2.43463247)]
Outputs clients: [[], ['output']]
EDIT: Re-running that list comprehension sometimes successfully evaluates y_hat: y_hat.eval().shape = (100,). And sometimes, it prints this before throwing the ValueError, with some variables having a name of None. What the hell is going on?
variable: sigma's shape = ()
variable: None's shape = (2, 2)
variable: alpha_beta's shape = (100, 2)
variable: alpha's shape = (100,)
variable: beta's shape = (100,)
variable: None's shape = (100,)