예제 #1
0
    /**
     * Constructor.
     *
     * @param user user whose model is created.
     */
    public FeatureUserIntentModel(U user) {
      Object2DoubleOpenHashMap<F> auxProb = new Object2DoubleOpenHashMap<>();
      auxProb.defaultReturnValue(0.0);

      int[] norm = {0};
      totalData
          .getUserPreferences(user)
          .forEach(
              iv -> {
                featureData
                    .getItemFeatures(iv.id)
                    .forEach(
                        fv -> {
                          auxProb.addTo(fv.id, 1.0);
                          norm[0]++;
                        });
              });

      if (norm[0] == 0) {
        norm[0] = featureData.numFeatures();
        featureData.getAllFeatures().sequential().forEach(f -> auxProb.put(f, 1.0));
      }

      auxProb
          .object2DoubleEntrySet()
          .forEach(
              e -> {
                e.setValue(e.getDoubleValue() / norm[0]);
              });

      this.prob = auxProb;
    }
    @Override
    public ItemAspectModel<I, F> getItemAspectModel(List<Tuple2od<I>> items) {
      Object2DoubleOpenHashMap<F> probNorm = new Object2DoubleOpenHashMap<>();
      items.forEach(
          iv -> {
            getItemIntents(iv.v1)
                .forEach(
                    f -> {
                      if (iv.v2 > probNorm.getOrDefault(f, 0.0)) {
                        probNorm.put(f, iv.v2);
                      }
                    });
          });

      return (iv, f) -> (Math.pow(2, iv.v2 / probNorm.getDouble(f)) - 1) / 2.0;
    }
예제 #3
0
 @Override
 public double p(F f) {
   return prob.getDouble(f);
 }
예제 #4
0
 @Override
 public Set<F> getIntents() {
   return prob.keySet();
 }