Class SwapGreedyReranker<U,I>
java.lang.Object
es.uam.eps.ir.relison.links.recommendation.reranking.global.swap.SwapReranker<U,I>
es.uam.eps.ir.relison.links.recommendation.reranking.global.swap.SwapGreedyReranker<U,I>
- Type Parameters:
U
- type of the users.I
- type of the items.
- All Implemented Interfaces:
GlobalReranker<U,I>
- Direct Known Subclasses:
SwapLambdaReranker
public abstract class SwapGreedyReranker<U,I> extends SwapReranker<U,I>
Abstract greedy implementation of the swap reranking strategy for optimizing global properties
of the system.
-
Field Summary
Fields Modifier and Type Field Description protected int
cutOff
The definitive size of the recommendation ranking (i.e.Fields inherited from class es.uam.eps.ir.relison.links.recommendation.reranking.global.swap.SwapReranker
globalvalue
-
Constructor Summary
Constructors Constructor Description SwapGreedyReranker(int cutOff)
Constructor. -
Method Summary
Modifier and Type Method Description protected static int[]
getBasePerm(int n)
Obtains the base permutation of size n.private es.uam.eps.ir.ranksys.core.Recommendation<U,I>
permuteRecommendation(es.uam.eps.ir.ranksys.core.Recommendation<U,I> rec, int[] perm)
Permutes a recommendation.protected int[]
rerankPermutation(es.uam.eps.ir.ranksys.core.Recommendation<U,I> rec, int maxLength)
Obtains a permutation for a ranking that greedily optimizes the global metric.protected es.uam.eps.ir.ranksys.core.Recommendation<U,I>
rerankRecommendation(es.uam.eps.ir.ranksys.core.Recommendation<U,I> rec, int maxLength)
Reranks the recommendation for a user.protected int
selectItem(U user, it.unimi.dsi.fastutil.ints.IntSortedSet remainingI, org.ranksys.core.util.tuples.Tuple2od<I> compared, java.util.List<org.ranksys.core.util.tuples.Tuple2od<I>> list)
Select the next item to add.protected abstract void
update(U user, org.ranksys.core.util.tuples.Tuple2od<I> updated, org.ranksys.core.util.tuples.Tuple2od<I> old)
Updates the value of the global metric.protected abstract double
value(org.ranksys.core.util.tuples.Tuple2od<I> get)
Computes the value for a item.protected abstract double
valuetop(org.ranksys.core.util.tuples.Tuple2od<I> get)
Computes the value for the top users.Methods inherited from class es.uam.eps.ir.relison.links.recommendation.reranking.global.swap.SwapReranker
rerankRecommendations, update
-
Field Details
-
cutOff
protected final int cutOffThe definitive size of the recommendation ranking (i.e. the number of user-item pairs we consider that we add to the system.
-
-
Constructor Details
-
SwapGreedyReranker
public SwapGreedyReranker(int cutOff)Constructor.- Parameters:
cutOff
- the definitive size of the recommendation ranking.
-
-
Method Details
-
rerankRecommendation
protected es.uam.eps.ir.ranksys.core.Recommendation<U,I> rerankRecommendation(es.uam.eps.ir.ranksys.core.Recommendation<U,I> rec, int maxLength)Description copied from class:SwapReranker
Reranks the recommendation for a user.- Specified by:
rerankRecommendation
in classSwapReranker<U,I>
- Parameters:
rec
- the original recommendation.maxLength
- maximum length of the definitive ranking.- Returns:
- the new recommendation.
-
rerankPermutation
protected int[] rerankPermutation(es.uam.eps.ir.ranksys.core.Recommendation<U,I> rec, int maxLength)Obtains a permutation for a ranking that greedily optimizes the global metric.- Parameters:
rec
- the recommendation ranking.maxLength
- the maximum number of items to consider.- Returns:
- a permutation of the indexes.
-
permuteRecommendation
private es.uam.eps.ir.ranksys.core.Recommendation<U,I> permuteRecommendation(es.uam.eps.ir.ranksys.core.Recommendation<U,I> rec, int[] perm)Permutes a recommendation.- Parameters:
rec
- the original recommendation.perm
- the permutation of the data.- Returns:
- the new recommendation.
-
getBasePerm
protected static int[] getBasePerm(int n)Obtains the base permutation of size n.- Parameters:
n
- size of the permutation.- Returns:
- an array containing the indexes.
-
selectItem
protected int selectItem(U user, it.unimi.dsi.fastutil.ints.IntSortedSet remainingI, org.ranksys.core.util.tuples.Tuple2od<I> compared, java.util.List<org.ranksys.core.util.tuples.Tuple2od<I>> list)Select the next item to add.- Parameters:
user
- the target user of the recommendation.remainingI
- elements outside the top kcompared
- the element we want to compare with the elements out of the top N.list
- list of values for all the elements- Returns:
- the selected item if we have to swap elements, -1 if not.
-
update
protected abstract void update(U user, org.ranksys.core.util.tuples.Tuple2od<I> updated, org.ranksys.core.util.tuples.Tuple2od<I> old)Updates the value of the global metric.- Parameters:
user
- the user whose recommendation we are reranking.updated
- the new item.old
- the old item.
-
value
Computes the value for a item.- Parameters:
get
- the item whose value we want to compute- Returns:
- the value
-
valuetop
Computes the value for the top users.- Parameters:
get
- item between the top.- Returns:
- the value for the top users.
-