public abstract class Metric<X> extends Object
Interface for common aspects of metrics, which are used to measure individual or per-user results. Each metric can measure results or users, and contribute aggregate values to the global aggregate measurement table.
This class should not be extended directly; rather, one of its subclasses should be extended. This hierarchy uses abstract classes instead of interfaces for two reasons: first, to provide useful default behavior, and second, because implementing multiple types of metrics in a single class is likely to be erroneous.
Metrics use contexts to track and accumulate data for experimental conditions. For each experimental condition (algorithm / data set pair), the evaluator will do the following:
createContext(AlgorithmInstance, DataSet, Recommender)
.getAggregateMeasurements(Object)
and add them
to the global output file.The context will generally consist of accumulators for the aggregate results reported by a metric over the entire experimental condition, such as the average of all user measurements. It may also contain additional relevant information, such as anything needed from the algorithm and data set for the measurements, or additional output tables for recording extra data.
Metrics may be used from multiple threads. LensKit may use multiple threads with the same context.
Modifier | Constructor and Description |
---|---|
protected |
Metric(List<String> labels,
List<String> aggLabels) |
Modifier and Type | Method and Description |
---|---|
X |
createContext(AlgorithmInstance algorithm,
DataSet dataSet,
Recommender recommender)
Create the context for an experimental condition (algorithm/data set pair).
|
List<String> |
getAggregateColumnLabels()
Get labels for the aggregate columns output by this metric.
|
MetricResult |
getAggregateMeasurements(X context)
Get the aggregate results from an accumulator.
|
List<String> |
getColumnLabels()
Get the labels for the per-user or per-result columns output by this metric.
|
Set<Class<?>> |
getRequiredRoots()
Get the classes on which this metric depends.
|
public List<String> getAggregateColumnLabels()
Get labels for the aggregate columns output by this metric.
public List<String> getColumnLabels()
Get the labels for the per-user or per-result columns output by this metric.
public Set<Class<?>> getRequiredRoots()
Get the classes on which this metric depends. These will be added to the roots of each algorithm configuration.
@Nullable public X createContext(AlgorithmInstance algorithm, DataSet dataSet, Recommender recommender)
Create the context for an experimental condition (algorithm/data set pair). The default implementation returns null
.
algorithm
- The algorithm.dataSet
- The data set.recommender
- The LensKit recommender, if applicable. This can be null for an external algorithm that does not provide a LensKit recommender.null
.@Nonnull public MetricResult getAggregateMeasurements(X context)
Get the aggregate results from an accumulator. The default implementation returns MetricResult.empty()
.
context
- The context for an experimental condition.