public final class PopularRepresentativeItems extends AbstractALSResource {
@GET
@Produces({CSVMessageBodyWriter.TEXT_CSV, MediaType.APPLICATION_JSON})
public List<String> get() {
ALSServingModel model = getALSServingModel();
int features = model.getFeatures();
List<String> items = new ArrayList<>(features);
float[] unitVector = new float[features];
for (int i = 0; i < features; i++) {
unitVector[i] = 1.0f;
List<Pair<String,Double>> topIDDot = model.topN(new DotsFunction(unitVector), 1, null);
items.add(topIDDot.isEmpty() ? null : topIDDot.get(0).getFirst());
unitVector[i] = 0.0f; // reset
}
return items;
}