Hi all!
I’m now working on customizing my Proposal distribution in pm.Metropolis for multivariables.
Below is a test (PyMC5).
with pm.Model() as Model:
x = np.array([1, 2, 3, 4, 5])
y = np.array([2.02, 2.96, 4.05, 4.99, 5.96])
a = pm.Normal('a', mu = 5, sigma = 1)
b = pm.Normal('b', mu = 5, sigma = 1)
model = a * x + b
step0 = pm.Metropolis()
ypred = pm.Normal('ypred', mu = model, sigma = 0.01, observed = y)
trace0 = pm.sample(draws = 1000, tune = 1000, step = step0, chains = 4, return_inferencedata = False)
step = pm.Metropolis(S = pm.trace_cov(trace0))
trace = pm.sample(draws = 1000, tune = 1000, step = step, chains = 4, return_inferencedata = False)
trace_to_data = pm.to_inference_data(trace)
print(az.summary(trace_to_data, round_to = 4))
az.plot_trace(trace_to_data, combined = True)
The code is successful until “step = pm.Metropolis(S = pm.trace_cov(trace0))”,
but an error ocuurs during “trace = pm.sample(draws = 1000, tune = 1000, step = step, chains = 4, return_inferencedata = False)”, saying that “ValueError: cannot reshape array of size 2 into shape ()”
Does anyone solve this problem?