public class TopNPopularityMetric extends ListOnlyTopNMetric<TopNPopularityMetric.Context>
Metric that measures how popular the items in the TopN list are.
This metric is registered with the type name popularity
.
Modifier and Type | Class and Description |
---|---|
class |
TopNPopularityMetric.Context |
static class |
TopNPopularityMetric.PopResult |
Constructor and Description |
---|
TopNPopularityMetric() |
Modifier and Type | Method and Description |
---|---|
TopNPopularityMetric.Context |
createContext(AlgorithmInstance algorithm,
DataSet dataSet,
RecommenderEngine engine)
Create the context for an experimental condition (algorithm/data set pair).
|
MetricResult |
getAggregateMeasurements(TopNPopularityMetric.Context context)
Get the aggregate results from an accumulator.
|
java.util.Set<java.lang.Class<?>> |
getRequiredRoots()
Get the classes on which this metric depends.
|
MetricResult |
measureUser(Recommender rec,
TestUser user,
int targetLength,
LongList recs,
TopNPopularityMetric.Context context)
Measurement method that only uses the recommend list.
|
measureUser
getAggregateColumnLabels, getColumnLabels
public java.util.Set<java.lang.Class<?>> getRequiredRoots()
Metric
Get the classes on which this metric depends. These will be added to the roots of each algorithm configuration.
getRequiredRoots
in class Metric<TopNPopularityMetric.Context>
@Nullable public TopNPopularityMetric.Context createContext(AlgorithmInstance algorithm, DataSet dataSet, RecommenderEngine engine)
Metric
Create the context for an experimental condition (algorithm/data set pair). The default implementation returns null
.
Note: Contexts must be thread-safe, in that multiple concurrent calls to the appropriate user-measurement function with the same context must be safe. This can be handled either by the context itself, or by the user-measurement function.
createContext
in class Metric<TopNPopularityMetric.Context>
algorithm
- The algorithm.dataSet
- The data set.engine
- The LensKit recommender engine, if applicable. This can be null for an external algorithm that does not provide a LensKit recommender.null
.@Nonnull public MetricResult measureUser(Recommender rec, TestUser user, int targetLength, LongList recs, TopNPopularityMetric.Context context)
ListOnlyTopNMetric
Measurement method that only uses the recommend list.
Thread Safety: This method may be called concurrently by multiple threads with the same recommender and context.
measureUser
in class ListOnlyTopNMetric<TopNPopularityMetric.Context>
rec
- The recommender used to recommend for this user.user
- The user.targetLength
- The target list length.recs
- The list of recommendations.context
- The context.@Nonnull public MetricResult getAggregateMeasurements(TopNPopularityMetric.Context context)
Metric
Get the aggregate results from an accumulator. The default implementation returns MetricResult.empty()
.
getAggregateMeasurements
in class Metric<TopNPopularityMetric.Context>
context
- The context for an experimental condition.