/** * Create a new preference domain quantizer. * * @see PreferenceDomain#PreferenceDomain(double, double, double) */ @SuppressWarnings("unused") public PreferenceDomainQuantizer(double min, double max, double prec) { this(new PreferenceDomain(min, max, prec)); }
@Override public PreferenceDomain build() { Preconditions.checkState(!Double.isNaN(minimum), "no minimum preference specified"); Preconditions.checkState(!Double.isNaN(maximum), "no maximum preference specified"); return new PreferenceDomain(minimum, maximum, precision); } }
/** * Parse a preference domain from a string specification. * <p> * Continuous preference domains are specified as {@code [min, max]}; discrete domains * as {@code min:max[/prec/}. For example, a 0.5-5.0 half-star rating scale is represented * as {@code [0.5, 5.0]/0.5}. * * @param spec The string specifying the preference domain. * @return The preference domain represented by {@code spec}. * @throws IllegalArgumentException if {@code spec} is not a valid domain specification. */ @Nonnull public static PreferenceDomain fromString(@Nonnull String spec) { Matcher m = specRE.matcher(spec); if (!m.matches()) { throw new IllegalArgumentException("invalid domain specification"); } double min = Double.parseDouble(m.group(1)); double max = Double.parseDouble(m.group(2)); String precs = m.group(3); if (precs != null) { double prec = Double.parseDouble(precs); return new PreferenceDomain(min, max, prec); } else { return new PreferenceDomain(min, max); } }
@Before public void setUp() { domain = new PreferenceDomain(0.5, 5.0, 0.5); }
/** * Create a new preference domain quantizer. * * @see PreferenceDomain#PreferenceDomain(double, double, double) */ @SuppressWarnings("unused") public PreferenceDomainQuantizer(double min, double max, double prec) { this(new PreferenceDomain(min, max, prec)); }
@SuppressWarnings("deprecation") @Before public void setup() throws RecommenderBuildException { List<Rating> rs = new ArrayList<>(); rs.add(Rating.create(1, 5, 2)); rs.add(Rating.create(1, 7, 4)); rs.add(Rating.create(8, 4, 5)); rs.add(Rating.create(8, 5, 4)); StaticDataSource source = StaticDataSource.fromList(rs); dao = source.get(); LenskitConfiguration config = new LenskitConfiguration(); config.bind(ItemScorer.class).to(SlopeOneItemScorer.class); config.bind(PreferenceDomain.class).to(new PreferenceDomain(1, 5)); // factory.setComponent(UserVectorNormalizer.class, IdentityVectorNormalizer.class); config.bind(BaselineScorer.class, ItemScorer.class) .to(UserMeanItemScorer.class); config.bind(UserMeanBaseline.class, ItemScorer.class) .to(ItemMeanRatingItemScorer.class); engine = LenskitRecommenderEngine.build(config, dao); }
@Before public void setUp() throws Exception { ItemScorer scorer = PrecomputedItemScorer.newBuilder() .addScore(40, 1, 4.0) .addScore(40, 2, 5.5) .addScore(40, 3, -1) .build(); PreferenceDomain domain = new PreferenceDomain(1, 5, 1); pred = new SimpleRatingPredictor(scorer, domain); unclamped = new SimpleRatingPredictor(scorer, null); }
@Override public PreferenceDomain build() { Preconditions.checkState(!Double.isNaN(minimum), "no minimum preference specified"); Preconditions.checkState(!Double.isNaN(maximum), "no maximum preference specified"); return new PreferenceDomain(minimum, maximum, precision); } }
/** * Parse a preference domain from a string specification. * <p> * Continuous preference domains are specified as {@code [min, max]}; discrete domains * as {@code min:max[/prec/}. For example, a 0.5-5.0 half-star rating scale is represented * as {@code [0.5, 5.0]/0.5}. * * @param spec The string specifying the preference domain. * @return The preference domain represented by {@code spec}. * @throws IllegalArgumentException if {@code spec} is not a valid domain specification. */ @Nonnull public static PreferenceDomain fromString(@Nonnull String spec) { Matcher m = specRE.matcher(spec); if (!m.matches()) { throw new IllegalArgumentException("invalid domain specification"); } double min = Double.parseDouble(m.group(1)); double max = Double.parseDouble(m.group(2)); String precs = m.group(3); if (precs != null) { double prec = Double.parseDouble(precs); return new PreferenceDomain(min, max, prec); } else { return new PreferenceDomain(min, max); } }