I’m a beginner in pymc, sorry this problem seems simple but it’s been bothering me for many days. The problem is summarized as follows: I want to include my observations in the model, I found out by studying chapter 2.1.3 in the book Bayesian Methods for Hackers that I can use the distribution with the value=data, observed= True
parameters in the distribution. But I found out that these parameters are no longer available in the latest pymc version, so I used observed=data
as my observation for one parameter in the model, but this poses a problem; it returns a tensor with data.shape, which is not what I expected, as I need to get a single value as an input to the model. Any hint on how to solve this?
with pm.Model() as model:
eps_1 = pm.Uniform('eps_1', lower=3.0, upper=10.0, shape=1)
eps_2 = pm.Uniform('eps_2', lower=3.0, upper=10.0, shape=1)
d1 = pm.Uniform('d1', lower=0.1, upper=5, shape=1)
a = pm.Normal('a', initval=20, observed=observed_a)
d2 = a/pt.sqrt(eps_1)
eps = pt.concatenate([[2.0], eps_1, eps_2])
thickness = pt.concatenate([d1, d2])
simulated_data = simulator_op(eps, loss, thickness)
pm.Normal('obs', mu=simulated_data, observed=observed_data)
trace = pm.sample(2000, tune=1000, progressbar=True, return_inferencedata=True)
where simulator_op
is the instance of the Op
class I defined that accepts three 1D vectors as input and returns a float type value. observed_a is the observation of a parameter for simulator_op; observed_data is the observation of the final result.
The error is obvious that the shape of the last parameter thickness is wrong; it should be (2,)
IndexError: index 3 is out of bounds for axis 0 with size 3
Apply node that caused the error: Simulator1DOp(Join.0, [0.0001 0. ... 0.1 ], Join.0)
Toposort index: 16
Inputs types: [TensorType(float64, shape=(3,)), TensorType(float64, shape=(3,)), TensorType(float64, shape=(10001,))]
Inputs shapes: [(3,), (3,), (10001,)]
Inputs strides: [(8,), (8,), (8,)]
Inputs values: [array([2. , 6.5, 6.5]), array([0.0001, 0.01 , 0.1 ]), 'not shown']
Outputs clients: [[ExpandDims{axis=0}(Simulator1DOp.0)]]