How to stack same rows of prior distributions inside the with model effectively

No worries - I am glad to help! Here’s a snippet that I think illustrates how to solve your problem. I recommend you play around with values of beta and inspect the resulting numeric values to make sure that it does what you want. The main thing I do here is reshaping X_fixed to get an extra dimension that I can use for broadcasting.

import theano.tensor as tt
import numpy as np

d1 = 10 # Number of rows in X_fixed
d2 = 6  # Number of columns in X_fixed. This must be an even number.
n_pairs_cols = int(d2/2) # Number of pairs of columns.

# Create toy data
X_fixed = np.arange(d1*d2).reshape([d1,d2],order='F')
beta = np.ones([2])

# Add an extra axis corresponding to distinct pairs of columns
X_reshaped = tt.reshape(X_fixed,(d1,n_pairs_cols,2))

# apply elementwise multiplication and sum over the 
# last axis to aggregate by pairs
dot_prod = (X_reshaped * beta).sum(axis=-1)
print(dot_prod.shape.eval())
print(dot_prod.eval())
4 Likes