I have a set of users who rate a number of items. I have the features of the items as well as their rating, and I’d like to find the preference of each user for the identified features. Also, I would like to find an aggregated preferences. For this, I did as follows:
- I defined a vector w_star as the aggregated preferences (follows a Dirichlet dist.)
- I defined a vector w_i for each user, and assume that it is around w_star
- I used the cutting plane idea in the ordinal regression to compute the cutting planes as well as the preferences w.r.t to features.
- I ordered the input features X and the associated rating y according to the users, and the indices are stored in another variable intrvl. So, for example, the features and the rating of the first user is stored in indices intrvl:intrvl.
Here is the model I developed in Numpyro by using for loop:
def PyroOrdinalHierarchical(X, y, nYlevels, intrvl, feature_no, user_no):
w_star = numpyro.sample('w_star', dist.Dirichlet(.01 * np.ones(feature_no))) gamma_star = numpyro.sample("gamma_star", dist.Gamma(0.01, 0.01)) for i in range(user_no): c_y = numpyro.sample("c_y" + str(i), dist.TransformedDistribution(dist.Normal(0, 1).expand([nYlevels - 1]), dist.transforms.OrderedTransform())) numpyro.sample('c_y_smp'+str(i), dist.Normal(0,1), obs=c_y) w = numpyro.sample("w" + str(i), dist.Dirichlet(gamma_star*w_star)) idx = range(intrvl[i],intrvl[i+1]) eta = X[idx] @ w numpyro.sample('Y'+ str(i), dist.OrderedLogistic(eta, c_y), obs=y[idx])
The model is very slow, I guess mainly because I used for loop and not numpyro.plate. But I do not know if I can develop this model by using plate since I need to have access to the index of the user.
Any help is highly appreciated!