public class TopNEntropyMetric extends ListOnlyTopNMetric<TopNEntropyMetric.Context>
Metric that measures the entropy of the top N recommendations across all users.
This tell us essentially how large of a range of the items your recommender is covering. It does not return any per-user results.
Small values indicate that the algorithm tends to prefer a small number of items which it recomments to all users. Large values mean that the algorithm recommends many different items (to many different users)
The smallest value happens when the topN list is the same for all users (which would give an entropy of roughly log_2(N)). The largest value happens when each item is recommended the same number of times (for an entropy of roughly log_2(number of items)).
This metric is registered with the type name entropy
.
Modifier and Type | Class and Description |
---|---|
static class |
TopNEntropyMetric.Context |
static class |
TopNEntropyMetric.EntropyResult |
Constructor and Description |
---|
TopNEntropyMetric()
Construct a new length metric.
|
Modifier and Type | Method and Description |
---|---|
TopNEntropyMetric.Context |
createContext(AlgorithmInstance algorithm,
DataSet dataSet,
RecommenderEngine engine)
Create the context for an experimental condition (algorithm/data set pair).
|
MetricResult |
getAggregateMeasurements(TopNEntropyMetric.Context context)
Get the aggregate results from an accumulator.
|
MetricResult |
measureUser(Recommender rec,
TestUser user,
int targetLength,
LongList recommendations,
TopNEntropyMetric.Context context)
Measurement method that only uses the recommend list.
|
measureUser
getAggregateColumnLabels, getColumnLabels, getRequiredRoots
@Nonnull public MetricResult measureUser(Recommender rec, TestUser user, int targetLength, LongList recommendations, TopNEntropyMetric.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<TopNEntropyMetric.Context>
rec
- The recommender used to recommend for this user.user
- The user.targetLength
- The target list length.recommendations
- The list of recommendations.context
- The context.@Nullable public TopNEntropyMetric.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<TopNEntropyMetric.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 getAggregateMeasurements(TopNEntropyMetric.Context context)
Metric
Get the aggregate results from an accumulator. The default implementation returns MetricResult.empty()
.
getAggregateMeasurements
in class Metric<TopNEntropyMetric.Context>
context
- The context for an experimental condition.