Performance speedup for updating posterior with new data

Is there a way of doing such update for vectorised Normal RV?

Here is code example for what i’d like to do :slight_smile:

DRAWS = 1000
TUNE = 100

Xw1 = np.random.normal(0,25,1000)
Xw2 = np.random.normal(0,25,1000)
Xw3 = np.random.normal(0,25,1000)
n, p = 1, .5
a = 0.5
b = np.array([0.8,-0.25,0.1])
y = 1*(logistic(a+b[0]*Xw1+b[1]*Xw2+b[2]*Xw3)>0.5)

data = pd.DataFrame({
    "Xw1" : Xw1,
    "Xw2" : Xw2,
    "Xw3" : Xw3,
    "y" : y
})

labels = ["Xw1","Xw2","Xw3"]

X = data[labels].to_numpy()
y = data["y"].to_numpy()

with pm.Model() as logistic_model:
    alpha = pm.Normal("alpha",mu=0.0,sigma=10)
    betas = pm.Normal("betas", mu=0.0, sigma=10, shape=X.shape[1]) #<--- for the next training/inference i'd like set posteriors from first data points as priors to new data points 

    # set predictors as shared variable to change them for PPCs:
    predictors = pm.Data("predictors", X)
    p = pm.Deterministic("p", pm.math.invlogit(alpha + predictors@betas))

    outcome = pm.Bernoulli("outcome", p=p, observed=y)

    trace = pm.sample(draws=DRAWS,
                      tune=TUNE, 
                      cores=2,
                      return_inferencedata=True) # draw posterior samples using NUTS sampling

I’m not a fan of naming beta coefficients one by one, makes models hard to change, right?