Class AbstractRanker<V,E>
- java.lang.Object
-
- edu.uci.ics.jung.algorithms.util.IterativeProcess
-
- edu.uci.ics.jung.algorithms.importance.AbstractRanker<V,E>
-
- All Implemented Interfaces:
IterativeContext
- Direct Known Subclasses:
BetweennessCentrality,RandomWalkSTBetweenness,RelativeAuthorityRanker,WeightedNIPaths
public abstract class AbstractRanker<V,E> extends IterativeProcess
Abstract class for algorithms that rank nodes or edges by some "importance" metric. Provides a common set of services such as:- storing rank scores
- getters and setters for rank scores
- computing default edge weights
- normalizing default or user-provided edge transition weights
- normalizing rank scores
- automatic cleanup of decorations
- creation of Ranking list
- print rankings in sorted order by rank
By default, all rank scores are removed from the vertices (or edges) being ranked.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.Object,java.util.Map<E,java.lang.Number>>edgeRankScoresprotected java.util.Map<java.lang.Object,java.util.Map<V,java.lang.Number>>vertexRankScores
-
Constructor Summary
Constructors Constructor Description AbstractRanker()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidassignDefaultEdgeTransitionWeights()protected voidfinalizeIterations()Perform eventual clean-up operations (must be implement by subclass when needed).doublegetEdgeRankScore(E e)doublegetEdgeRankScore(E e, java.lang.Object key)java.util.Map<java.lang.Object,java.util.Map<E,java.lang.Number>>getEdgeRankScores()java.util.Map<E,java.lang.Number>getEdgeRankScores(java.lang.Object key)protected doublegetEdgeWeight(E e)java.util.Map<E,java.lang.Number>getEdgeWeights()protected edu.uci.ics.jung.graph.Graph<V,E>getGraph()java.util.List<Ranking<?>>getRankings()Retrieves the list of ranking instances in descending sorted order by rank score If the algorithm is ranking edges, the instances will be of typeEdgeRanking, otherwise if the algorithm is ranking nodes the instances will be of typeNodeRankingabstract java.lang.ObjectgetRankScoreKey()The user datum key used to store the rank score.java.util.List<java.lang.Double>getRankScores(int topKRankings)Return a list of the top k rank scores.protected intgetVertexCount()doublegetVertexRankScore(V v)Given an edge or node, returns the corresponding rank score.doublegetVertexRankScore(V v, java.lang.Object key)java.util.Map<java.lang.Object,java.util.Map<V,java.lang.Number>>getVertexRankScores()java.util.Map<V,java.lang.Number>getVertexRankScores(java.lang.Object key)protected java.util.Collection<V>getVertices()protected voidinitialize(edu.uci.ics.jung.graph.Graph<V,E> graph, boolean isNodeRanker, boolean isEdgeRanker)booleanisRankingEdges()Returnstrueif this ranker ranks edges, andfalseotherwise.booleanisRankingNodes()Returnstrueif this ranker ranks nodes, andfalseotherwise.protected voidnormalizeEdgeTransitionWeights()protected voidnormalizeRankings()protected voidonFinalize(java.lang.Object e)voidprintRankings(boolean verbose, boolean printScore)Print the rankings to standard out in descending order of rank scoreprotected voidremoveEdgeRankScore(E e)protected voidremoveEdgeRankScore(E e, java.lang.Object key)protected voidremoveVertexRankScore(V v)protected voidremoveVertexRankScore(V v, java.lang.Object key)voidreset()protected voidsetEdgeRankScore(E e, double rankValue)protected voidsetEdgeRankScore(E e, double rankValue, java.lang.Object key)protected voidsetEdgeWeight(E e, double weight)voidsetEdgeWeights(java.util.Map<E,java.lang.Number> edgeWeights)voidsetNormalizeRankings(boolean normalizeRankings)Allows the user to specify whether or not s/he wants the rankings to be normalized.voidsetRemoveRankScoresOnFinalize(boolean removeRankScoresOnFinalize)Instructs the ranker whether or not it should remove the rank scores from the nodes (or edges) once the ranks have been computed.protected voidsetVertexRankScore(V v, double rankValue)protected voidsetVertexRankScore(V v, double rankValue, java.lang.Object key)-
Methods inherited from class edu.uci.ics.jung.algorithms.util.IterativeProcess
done, evaluate, getDesiredPrecision, getIterations, getMaximumIterations, getPrecision, hasConverged, initializeIterations, relativePrecision, setDesiredPrecision, setMaximumIterations, setPrecision, step
-
-
-
-
Method Detail
-
initialize
protected void initialize(edu.uci.ics.jung.graph.Graph<V,E> graph, boolean isNodeRanker, boolean isEdgeRanker)
-
getVertexRankScores
public java.util.Map<java.lang.Object,java.util.Map<V,java.lang.Number>> getVertexRankScores()
- Returns:
- all rankScores
-
getEdgeRankScores
public java.util.Map<java.lang.Object,java.util.Map<E,java.lang.Number>> getEdgeRankScores()
-
getVertexRankScores
public java.util.Map<V,java.lang.Number> getVertexRankScores(java.lang.Object key)
- Returns:
- the rankScores
-
getEdgeRankScores
public java.util.Map<E,java.lang.Number> getEdgeRankScores(java.lang.Object key)
-
getVertices
protected java.util.Collection<V> getVertices()
-
getVertexCount
protected int getVertexCount()
-
reset
public void reset()
- Overrides:
resetin classIterativeProcess
-
isRankingNodes
public boolean isRankingNodes()
Returnstrueif this ranker ranks nodes, andfalseotherwise.
-
isRankingEdges
public boolean isRankingEdges()
Returnstrueif this ranker ranks edges, andfalseotherwise.
-
setRemoveRankScoresOnFinalize
public void setRemoveRankScoresOnFinalize(boolean removeRankScoresOnFinalize)
Instructs the ranker whether or not it should remove the rank scores from the nodes (or edges) once the ranks have been computed.- Parameters:
removeRankScoresOnFinalize-trueif the rank scores are to be removed,falseotherwise
-
onFinalize
protected void onFinalize(java.lang.Object e)
-
getRankScoreKey
public abstract java.lang.Object getRankScoreKey()
The user datum key used to store the rank score.- Returns:
- the key
-
finalizeIterations
protected void finalizeIterations()
Description copied from class:IterativeProcessPerform eventual clean-up operations (must be implement by subclass when needed).- Overrides:
finalizeIterationsin classIterativeProcess
-
getRankings
public java.util.List<Ranking<?>> getRankings()
Retrieves the list of ranking instances in descending sorted order by rank score If the algorithm is ranking edges, the instances will be of typeEdgeRanking, otherwise if the algorithm is ranking nodes the instances will be of typeNodeRanking- Returns:
- the list of rankings
-
getRankScores
public java.util.List<java.lang.Double> getRankScores(int topKRankings)
Return a list of the top k rank scores.- Parameters:
topKRankings- the value of k to use- Returns:
- list of rank scores
-
getVertexRankScore
public double getVertexRankScore(V v)
Given an edge or node, returns the corresponding rank score. This is a default implementation of getRankScore which assumes the decorations are of type MutableDouble. This method only returns legal values ifsetRemoveRankScoresOnFinalize(false)was called prior toevaluate().- Returns:
- the rank score value
-
getVertexRankScore
public double getVertexRankScore(V v, java.lang.Object key)
-
getEdgeRankScore
public double getEdgeRankScore(E e)
-
getEdgeRankScore
public double getEdgeRankScore(E e, java.lang.Object key)
-
setVertexRankScore
protected void setVertexRankScore(V v, double rankValue, java.lang.Object key)
-
setEdgeRankScore
protected void setEdgeRankScore(E e, double rankValue, java.lang.Object key)
-
setVertexRankScore
protected void setVertexRankScore(V v, double rankValue)
-
setEdgeRankScore
protected void setEdgeRankScore(E e, double rankValue)
-
removeVertexRankScore
protected void removeVertexRankScore(V v, java.lang.Object key)
-
removeEdgeRankScore
protected void removeEdgeRankScore(E e, java.lang.Object key)
-
removeVertexRankScore
protected void removeVertexRankScore(V v)
-
removeEdgeRankScore
protected void removeEdgeRankScore(E e)
-
getEdgeWeight
protected double getEdgeWeight(E e)
-
setEdgeWeight
protected void setEdgeWeight(E e, double weight)
-
setEdgeWeights
public void setEdgeWeights(java.util.Map<E,java.lang.Number> edgeWeights)
-
getEdgeWeights
public java.util.Map<E,java.lang.Number> getEdgeWeights()
- Returns:
- the edgeWeights
-
assignDefaultEdgeTransitionWeights
protected void assignDefaultEdgeTransitionWeights()
-
normalizeEdgeTransitionWeights
protected void normalizeEdgeTransitionWeights()
-
normalizeRankings
protected void normalizeRankings()
-
printRankings
public void printRankings(boolean verbose, boolean printScore)Print the rankings to standard out in descending order of rank score- Parameters:
verbose- iftrue, include information about the actual rank order as well as the original position of the vertex before it was rankedprintScore- iftrue, include the actual value of the rank score
-
setNormalizeRankings
public void setNormalizeRankings(boolean normalizeRankings)
Allows the user to specify whether or not s/he wants the rankings to be normalized. In some cases, this will have no effect since the algorithm doesn't allow normalization as an option- Parameters:
normalizeRankings-
-
-