@Shareable @DefaultNull public final class PreferenceDomain extends Object implements Serializable
An object describing the domain of preference data, used in ratings and predictions.
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID |
Constructor and Description |
---|
PreferenceDomain(double min,
double max)
Create a continuous bounded preference domain.
|
PreferenceDomain(double min,
double max,
double prec)
Create a discrete bounded preference domain.
|
Modifier and Type | Method and Description |
---|---|
double |
clampValue(double v)
Clamp a value to this preference domain.
|
Long2DoubleSortedMap |
clampVector(Map<Long,Double> scores) |
void |
clampVector(MutableSparseVector vec) |
boolean |
equals(Object o) |
static PreferenceDomain |
fromString(String spec)
Parse a preference domain from a string specification.
|
double |
getMaximum()
The maximum preference value.
|
double |
getMinimum()
The minimum preference value.
|
double |
getPrecision()
The precision of preference values.
|
int |
hashCode() |
boolean |
hasPrecision()
Query whether this preference domain has a precision.
|
static PreferenceDomainBuilder |
newBuilder()
Create a new preference domain builder.
|
String |
toString() |
public static final long serialVersionUID
public PreferenceDomain(double min, double max, double prec)
Create a discrete bounded preference domain.
min
- The minimum preference value.max
- The maximum preference value.prec
- The preference precision (if 0 or Double.NaN
, the domain is continuous).public PreferenceDomain(double min, double max)
Create a continuous bounded preference domain.
min
- The minimum preference value.max
- The maximum preference value.public double getMinimum()
The minimum preference value.
public double getMaximum()
The maximum preference value.
public boolean hasPrecision()
Query whether this preference domain has a precision.
true
if the domain has a precision for discrete rating values, false
if it is continuous.public double getPrecision()
The precision of preference values. This is the precision with which data is collected from the user — in a 1-5, half-star rating system, it will be 0.5.
hasPrecision()
public double clampValue(double v)
Clamp a value to this preference domain.
v
- The value to clamp.public void clampVector(MutableSparseVector vec)
public Long2DoubleSortedMap clampVector(Map<Long,Double> scores)
@Nonnull public static PreferenceDomain fromString(@Nonnull String spec)
Parse a preference domain from a string specification.
Continuous preference domains are specified as [min, max]
; discrete domains as min:max[/prec/
. For example, a 0.5-5.0 half-star rating scale is represented as [0.5, 5.0]/0.5
.
spec
- The string specifying the preference domain.spec
.IllegalArgumentException
- if spec
is not a valid domain specification.public static PreferenceDomainBuilder newBuilder()
Create a new preference domain builder.