Customize Proposal distribution in pm.Metropolis for multivariables

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?

Welcome.

Can I ask what you are trying to do in customizing the step here? Metropolis seems like a poor fit here.

Thanks for your reply!
I would like to implement the algorithm like Adaptive MCMC, which adopts the Metropolis-Hastings step with proposal distribution updated by the previous traces.
First of all, I run the simple MCMC with Metropolis, and obtain the trace named trace0.
Next, l calculate the covariance matrix of trace0.
This matrix then becomes the covariance matrix of the proposal distribution of the next MCMC trial, but it fails.