I have the following model, where I have a feature space X
of shape (NxTxK) which should be multiplied elementwise by alpha
or beta
depending on the sign of the value in phi
which is also (NxTxK). The parameters alpha
and beta
are drawn from a prior distribution.
With numpy, the syntax would be: X = np.where(phi == 1, X*alpha, X*beta)
.
So far I used the following code which however gave me an error message.
with pm.Model() as model:
alpha = pm.Beta(name="alpha", alpha=0.5, beta=0.5)
beta = pm.Beta(name="beta", alpha=0.5, beta=0.5)
X= pm.Deterministic(name="X", var=pm.math.where(pm.math.eq(phi, 1), X* alpha, X * beta))
b= pm.Normal(name="b", mu=0, sigma=1, shape=n_vars_1)
eps = pm.InverseGamma(name="eps", alpha=9.0, beta=4.0)
y_hat = pm.Deterministic(name="y_hat", var=pm.math.sum(X * b, axis=2)
y_like = pm.Normal(name="y_like", mu=y_hat, sd=eps, observed=y)