Class AbstractIterativeScorer<V,E,T>
java.lang.Object
edu.uci.ics.jung.algorithms.scoring.AbstractIterativeScorer<V,E,T>
- All Implemented Interfaces:
VertexScorer<V,
,T> IterativeContext
- Direct Known Subclasses:
AbstractIterativeScorerWithPriors
,VoltageScorer
public abstract class AbstractIterativeScorer<V,E,T>
extends Object
implements IterativeContext, VertexScorer<V,T>
An abstract class for algorithms that assign scores to vertices based on iterative methods.
Generally, any (concrete) subclass will function by creating an instance, and then either calling
evaluate
(if the user wants to iterate until the algorithms is 'done') or
repeatedly call step
(if the user wants to observe the values at each step).-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
A flag representing whether this instance tolerates disconnected graphs.The map in which the current values are stored.The edge weights used by this algorithm.protected Hypergraph
<V, E> The graph on which the calculations are to be made.protected boolean
protected double
The largest change seen so far among all vertex scores.protected int
Maximum number of iterations to use before terminating.The map in which the output values are stored.protected boolean
Indicates whether the output and current values are in a 'swapped' state.protected double
Minimum change from one step to the next; if all changes are ≤ tolerance, no further updates will occur.protected int
The total number of iterations used so far. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance for the specified graphg
.AbstractIterativeScorer
(Hypergraph<V, E> g, com.google.common.base.Function<? super E, ? extends Number> edge_weights) Creates an instance for the specified graph and edge weights. -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptDisconnectedGraph
(boolean accept) Specifies whether this instance should accept vertices with no outgoing edges.protected void
protected void
Collects the 'potential' from v (its current value) if it has no outgoing edges; this can then be redistributed among the other vertices as a means of normalization.boolean
done()
Returns true if the total number of iterations is greater than or equal tomax_iterations
or if the maximum value change observed is less thantolerance
.void
evaluate()
Steps through this scoring algorithm until a termination condition is reached.protected int
Returns the effective number of vertices incident to this edge.protected T
getCurrentValue
(V v) Gets the current value for this vertexprotected Number
getEdgeWeight
(V v, E e) Gets the edge weight fore
in the context of its (incident) vertexv
.Returns the Function that this instance uses to associate edge weights with each edge.int
Returns the number of iterations that this instance has used so far.int
Returns the maximum number of iterations that this instance will use.protected T
getOutputValue
(V v) Gets the output value for this vertex.double
Gets the size of the largest change (difference between the current and previous values) for any vertex that can be tolerated.getVertexScore
(V v) protected void
Initializes the internal state for this instance.boolean
Returns true if this instance accepts vertices with no outgoing edges, and false otherwise.protected void
setCurrentValue
(V v, T value) Sets the current value for this vertex.void
setEdgeWeights
(com.google.common.base.Function<? super E, ? extends Number> edge_weights) Sets the Function that this instance uses to associate edge weights with each edgevoid
setHyperedgesAreSelfLoops
(boolean arg) Specifies whether hyperedges are to be treated as self-loops.void
setMaxIterations
(int max_iterations) Sets the maximum number of times thatevaluate
will callstep
.protected void
setOutputValue
(V v, T value) Sets the output value for this vertex.void
setTolerance
(double tolerance) Sets the size of the largest change (difference between the current and previous values) for any vertex that can be tolerated.void
step()
Performs one step of this algorithm; updates the state (value) for each vertex.protected void
protected abstract double
Updates the value forv
.protected void
updateMaxDelta
(V v, double diff)
-
Field Details
-
max_iterations
protected int max_iterationsMaximum number of iterations to use before terminating. Defaults to 100. -
tolerance
protected double toleranceMinimum change from one step to the next; if all changes are ≤ tolerance, no further updates will occur. Defaults to 0.001. -
graph
The graph on which the calculations are to be made. -
total_iterations
protected int total_iterationsThe total number of iterations used so far. -
edge_weights
The edge weights used by this algorithm. -
output_reversed
protected boolean output_reversedIndicates whether the output and current values are in a 'swapped' state. Intended for internal use only. -
output
The map in which the output values are stored. -
current_values
The map in which the current values are stored. -
accept_disconnected_graph
private boolean accept_disconnected_graphA flag representing whether this instance tolerates disconnected graphs. Instances that do not accept disconnected graphs may have unexpected behavior on disconnected graphs; they are not guaranteed to do an explicit check. Defaults to true. -
hyperedges_are_self_loops
protected boolean hyperedges_are_self_loops -
max_delta
protected double max_deltaThe largest change seen so far among all vertex scores.
-
-
Constructor Details
-
AbstractIterativeScorer
public AbstractIterativeScorer(Hypergraph<V, E> g, com.google.common.base.Function<? super E, ? extends Number> edge_weights) Creates an instance for the specified graph and edge weights.- Parameters:
g
- the graph for which the instance is to be creatededge_weights
- the edge weights for this instance
-
AbstractIterativeScorer
Creates an instance for the specified graphg
. NOTE: This constructor does not set the internaledge_weights
variable. If this variable is used by the subclass which invoked this constructor, it must be initialized by that subclass.- Parameters:
g
- the graph for which the instance is to be created
-
-
Method Details
-
setOutputValue
Sets the output value for this vertex.- Parameters:
v
- the vertex whose output value is to be setvalue
- the value to set
-
getOutputValue
Gets the output value for this vertex.- Parameters:
v
- the vertex whose output value is to be retrieved- Returns:
- the output value for this vertex
-
getCurrentValue
Gets the current value for this vertex- Parameters:
v
- the vertex whose current value is to be retrieved- Returns:
- the current value for this vertex
-
setCurrentValue
Sets the current value for this vertex.- Parameters:
v
- the vertex whose current value is to be setvalue
- the current value to set
-
initialize
protected void initialize()Initializes the internal state for this instance. -
evaluate
public void evaluate()Steps through this scoring algorithm until a termination condition is reached. -
done
public boolean done()Returns true if the total number of iterations is greater than or equal tomax_iterations
or if the maximum value change observed is less thantolerance
.- Specified by:
done
in interfaceIterativeContext
- Returns:
true
if this iterative process is finished, andfalse
otherwise.
-
step
public void step()Performs one step of this algorithm; updates the state (value) for each vertex.- Specified by:
step
in interfaceIterativeContext
-
swapOutputForCurrent
protected void swapOutputForCurrent() -
update
Updates the value forv
.- Parameters:
v
- the vertex whose value is to be updated- Returns:
- the updated value
-
updateMaxDelta
-
afterStep
protected void afterStep() -
getVertexScore
- Specified by:
getVertexScore
in interfaceVertexScorer<V,
E> - Parameters:
v
- the vertex whose score is requested- Returns:
- the algorithm's score for this vertex
-
getMaxIterations
public int getMaxIterations()Returns the maximum number of iterations that this instance will use.- Returns:
- the maximum number of iterations that
evaluate
will use prior to terminating
-
getIterations
public int getIterations()Returns the number of iterations that this instance has used so far.- Returns:
- the number of iterations that this instance has used so far
-
setMaxIterations
public void setMaxIterations(int max_iterations) Sets the maximum number of times thatevaluate
will callstep
.- Parameters:
max_iterations
- the maximum
-
getTolerance
public double getTolerance()Gets the size of the largest change (difference between the current and previous values) for any vertex that can be tolerated. Once all changes are less than this value,evaluate
will terminate.- Returns:
- the size of the largest change that evaluate() will permit
-
setTolerance
public void setTolerance(double tolerance) Sets the size of the largest change (difference between the current and previous values) for any vertex that can be tolerated.- Parameters:
tolerance
- the size of the largest change that evaluate() will permit
-
getEdgeWeights
Returns the Function that this instance uses to associate edge weights with each edge.- Returns:
- the Function that associates an edge weight with each edge
-
setEdgeWeights
public void setEdgeWeights(com.google.common.base.Function<? super E, ? extends Number> edge_weights) Sets the Function that this instance uses to associate edge weights with each edge- Parameters:
edge_weights
- the Function to use to associate an edge weight with each edge- See Also:
-
getEdgeWeight
Gets the edge weight fore
in the context of its (incident) vertexv
.- Parameters:
v
- the vertex incident to e as a context in which the edge weight is to be calculatede
- the edge whose weight is to be returned- Returns:
- the edge weight for
e
in the context of its (incident) vertexv
-
collectDisappearingPotential
Collects the 'potential' from v (its current value) if it has no outgoing edges; this can then be redistributed among the other vertices as a means of normalization.- Parameters:
v
- the vertex whose potential is being collected
-
acceptDisconnectedGraph
public void acceptDisconnectedGraph(boolean accept) Specifies whether this instance should accept vertices with no outgoing edges.- Parameters:
accept
- true if this instance should accept vertices with no outgoing edges, false otherwise
-
isDisconnectedGraphOK
public boolean isDisconnectedGraphOK()Returns true if this instance accepts vertices with no outgoing edges, and false otherwise.- Returns:
- true if this instance accepts vertices with no outgoing edges, otherwise false
-
setHyperedgesAreSelfLoops
public void setHyperedgesAreSelfLoops(boolean arg) Specifies whether hyperedges are to be treated as self-loops. If they are, then potential will flow along a hyperedge a vertex to itself, just as it does to all other vertices incident to that hyperedge.- Parameters:
arg
- iftrue
, hyperedges are treated as self-loops
-
getAdjustedIncidentCount
Returns the effective number of vertices incident to this edge. If the graph is a binary relation or if hyperedges are treated as self-loops, the value returned isgraph.getIncidentCount(e)
; otherwise it isgraph.getIncidentCount(e) - 1
.- Parameters:
e
- the edge whose incident edge count is requested- Returns:
- the edge count, adjusted based on how hyperedges are treated
-