-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
Description
Discussed in #7618
Originally posted by yk4978 December 18, 2024
I am encountering an error when trying to sample from a PyMC model. In the model, I am defining a set of Bernoulli
variables with conditional probabilities based on another parent Bernoulli
variable A
. The model definition itself works fine, but when I attempt to sample and calculate the posterior, I get the following error:
AttributeError: 'Scratchpad' object has no attribute 'ufunc'
Here is the code I am using:
import pymc as pm
n = 40
with pm.Model() as model:
A = pm.Bernoulli('A', p=0.001)
for i in range(n):
if i < n // 2:
pm.Bernoulli(f"A{i}", p=pm.math.switch(A, 0.6, 0.01), observed=1)
else:
pm.Bernoulli(f"A{i}", p=pm.math.switch(A, 0.6, 0.01))
trace = pm.sample(1000, return_inferencedata=False, cores=1)
probs = sum(trace['A']) / len(trace['A'])
print(f"probs: {probs}")
Can anyone help me identify what might be causing this error and suggest a possible solution?
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
ricardoV94 commentedon Jan 31, 2025
@yk4978 I've seen that when PyTensor fails to fuse long graphs. Did you see any warnings prior to the failure?
How did you install pymc? And can you try on the latest version?