I was trying to come up with a way to sample from another distribution using the following code but I ran into an error which I’m a little perplexed by. See below if it helps it all. The general idea is to make a step function which just makes a draw from a preexisting array.
import pymc3 as pm
import numpy as np
from pymc3.step_methods.arraystep import BlockedStep
external_vals = np.random.randn(10,2) * 5 + 2
class ExternalSample(BlockedStep):
def __init__(self, external, var):
self.vars = [var]
self.name = var.name
self.external = external
def step(self, point):
row_chosen = np.random.choice(self.external.shape[0])
point[self.name] = self.external[row_chosen]
return point
with pm.Model() as model:
external_pm = pm.Normal('external', shape=2)
y = pm.Normal('y', mu=external_pm, shape=2)
step = [ExternalSample(external_vals, external_pm)]
trace = pm.sample(step=step)