What is the problem of this Aesara error message?

Hello, I am recently doing some Bayesian curve fitting examples. My code works anyway, but… there are a lot of error messages following the result. Could you let me know what is the problem and whether I can believe my result?

Especially, I was wondering what “ERROR (aesara.graph.rewriting.basic): Rewrite failure due to: transform_values” and “NotImplementedError: These Ops should be removed from graphs used for computation.” messages mean…

Code:

num_data = 35

x_data, y_data = create_sampledata(num_data) 

df = pd.DataFrame()
df['x'] = x_data.flatten().tolist()
df['y'] = y_data.flatten().tolist()

n = 5 # number of polynomial coefficients
lmd = 0 

with pm.Model() as model:
    x = pm.MutableData("x", df.x)
  
  w_mu = pm.Normal('w_mu', mu=0., sigma = 1)
  w_sigma = pm.HalfNormal('w_sigma', sigma = 10 )
  w = pm.Normal('w', mu= w_mu, sigma = w_sigma, shape=n)
  mu = pm.Deterministic("mu", sum(((w[i]*(x**i)) for i in range(n))))

  likelihood_sigma = pm.HalfNormal('likelihood_sigma', sigma = 10)
  likelihood = pm.Normal("y", mu = mu, sigma = likelihood_sigma, observed = df.y)

with model:
    step = pm.Metropolis()
    samples = pm.sample()
    pm.plot_trace(samples)

Error Message:

ERROR (aesara.graph.rewriting.basic): Rewrite failure due to: transform_values
ERROR (aesara.graph.rewriting.basic): node: halfnormal_rv{0, (0, 0), floatX, False}(RandomGeneratorSharedVariable(<Generator(PCG64) at 0x2A9ADAC80>), TensorConstant{}, TensorConstant{11}, TensorConstant{0.0}, TensorConstant{10.0})
ERROR (aesara.graph.rewriting.basic): TRACEBACK:
ERROR (aesara.graph.rewriting.basic): Traceback (most recent call last):
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/rewriting/basic.py”, line 1933, in process_node
replacements = node_rewriter.transform(fgraph, node)
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/rewriting/basic.py”, line 1092, in transform
return self.fn(fgraph, node)
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aeppl/transforms.py”, line 158, in transform_values
new_value_var = transformed_variable(
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/op.py”, line 300, in call
compute_test_value(node)
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/op.py”, line 138, in compute_test_value
thunk()
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/op.py”, line 543, in rval
r = p(n, [x[0] for x in i], o)
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aeppl/transforms.py”, line 56, in perform
raise NotImplementedError(
NotImplementedError: These Ops should be removed from graphs used for computation.

ERROR (aesara.graph.rewriting.basic): Rewrite failure due to: transform_values
ERROR (aesara.graph.rewriting.basic): node: halfnormal_rv{0, (0, 0), floatX, False}(RandomGeneratorSharedVariable(<Generator(PCG64) at 0x2A9A09BA0>), TensorConstant{}, TensorConstant{11}, TensorConstant{0.0}, TensorConstant{10.0})
ERROR (aesara.graph.rewriting.basic): TRACEBACK:
ERROR (aesara.graph.rewriting.basic): Traceback (most recent call last):
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/rewriting/basic.py”, line 1933, in process_node

NotImplementedError: These Ops should be removed from graphs used for computation.

Multiprocess sampling (4 chains in 4 jobs)
NUTS: [w_mu, w_sigma, w, likelihood_sigma]

Output exceeds the size limit. Open the full output data in a text editor

Sampling 4 chains for 1_000 tune and 2_000 draw iterations (4_000 + 8_000 draws total) took 115 seconds. There were 2 divergences after tuning. Increase target_accept or reparameterize. There were 17 divergences after tuning. Increase target_accept or reparameterize. There were 30 divergences after tuning. Increase target_accept or reparameterize. There were 3 divergences after tuning. Increase target_accept or reparameterize. ERROR (aesara.graph.rewriting.basic): Rewrite failure due to: transform_values ERROR (aesara.graph.rewriting.basic): node: halfnormal_rv{0, (0, 0), floatX, False}(RandomGeneratorSharedVariable(<Generator(PCG64) at 0x2A9A09BA0>), TensorConstant{}, TensorConstant{11}, TensorConstant{0.0}, TensorConstant{10.0}) ERROR (aesara.graph.rewriting.basic): TRACEBACK: ERROR (aesara.graph.rewriting.basic): Traceback (most recent call last): File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/rewriting/basic.py”, line 1933, in process_node replacements = node_rewriter.transform(fgraph, node) File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/rewriting/basic.py”, line 1092, in transform return self.fn(fgraph, node) File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aeppl/transforms.py”, line 158, in transform_values new_value_var = transformed_variable( File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/op.py”, line 300, in call compute_test_value(node) File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/op.py”, line 138, in compute_test_value thunk() File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/op.py”, line 543, in rval r = p(n, [x[0] for x in i], o) File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aeppl/transforms.py”, line 56, in perform raise NotImplementedError( NotImplementedError: These Ops should be removed from graphs used for computation.

File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aeppl/transforms.py”, line 56, in perform raise NotImplementedError( NotImplementedError: These Ops should be removed from graphs used for computation.

There are a couple of things that could be going on. The first thing I can see is that you are looping through your data and constructing the polynomials on the fly. I would recommend doing this once before the model specification so that these calculations don’t end up in the computational graph. Second, it looks like you are calculating the mean (mu) by summing over all observations. I assume you want to be doing something like pt.sum(w * X.T, axis=1) instead (assuming X is a matrix containing all your predictors). Otherwise, I think I would need to see your data to get much farther. Also, you can try PyMC version 5 as that is now available.

2 Likes

Thanks for your comment so much. Could you explain the first point you mentioned more? In terms of the second point, I may need to find out a way to calculate in a matrix form.

[edited because I left a stray line in the code] The first point was just to create all the polynomial predictors up where you do all your data wrangling. Something like this:

import numpy as np

x = np.array([1,2,3,4,5,6])
X = np.tile(x, (5,1))
X = X.T**np.array([0,1,2,3,4])
X

#array([[   1,    1,    1,    1,    1],
#       [   1,    2,    4,    8,   16],
#       [   1,    3,    9,   27,   81],
#       [   1,    4,   16,   64,  256],
#       [   1,    5,   25,  125,  625],
#       [   1,    6,   36,  216, 1296]])

Then you can do something like the pt.sum(w * X.T, axis=1) I mentioned.

1 Like