public abstract class AbstractIterativeScorer<V,E,T> extends Object implements IterativeContext, VertexScorer<V,T>
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).Modifier and Type | Field and Description |
---|---|
protected com.google.common.base.Function<VEPair<V,E>,? extends Number> |
edge_weights
The edge weights used by this algorithm.
|
protected Hypergraph<V,E> |
graph
The graph on which the calculations are to be made.
|
protected boolean |
hyperedges_are_self_loops |
protected double |
max_delta
The largest change seen so far among all vertex scores.
|
protected int |
max_iterations
Maximum number of iterations to use before terminating.
|
protected boolean |
output_reversed
Indicates whether the output and current values are in a 'swapped' state.
|
protected double |
tolerance
Minimum change from one step to the next; if all changes are ≤ tolerance,
no further updates will occur.
|
protected int |
total_iterations
The total number of iterations used so far.
|
Constructor and Description |
---|
AbstractIterativeScorer(Hypergraph<V,E> g)
Creates an instance for the specified graph
g . |
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.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptDisconnectedGraph(boolean accept)
Specifies whether this instance should accept vertices with no outgoing edges.
|
protected void |
afterStep() |
protected void |
collectDisappearingPotential(V v)
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 to
max_iterations
or if the maximum value change observed is less than tolerance . |
void |
evaluate()
Steps through this scoring algorithm until a termination condition is reached.
|
protected int |
getAdjustedIncidentCount(E e)
Returns the effective number of vertices incident to this edge.
|
protected T |
getCurrentValue(V v)
Gets the current value for this vertex
|
protected Number |
getEdgeWeight(V v,
E e)
Gets the edge weight for
e in the context of its (incident) vertex v . |
com.google.common.base.Function<VEPair<V,E>,? extends Number> |
getEdgeWeights()
Returns the Function that this instance uses to associate edge weights with each edge.
|
int |
getIterations()
Returns the number of iterations that this instance has used so far.
|
int |
getMaxIterations()
Returns the maximum number of iterations that this instance will use.
|
protected T |
getOutputValue(V v)
Gets the output value for this vertex.
|
double |
getTolerance()
Gets the size of the largest change (difference between the current and previous values)
for any vertex that can be tolerated.
|
T |
getVertexScore(V v) |
protected void |
initialize()
Initializes the internal state for this instance.
|
boolean |
isDisconnectedGraphOK()
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 edge
|
void |
setHyperedgesAreSelfLoops(boolean arg)
Specifies whether hyperedges are to be treated as self-loops.
|
void |
setMaxIterations(int max_iterations)
Sets the maximum number of times that
evaluate will call step . |
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 |
swapOutputForCurrent() |
protected abstract double |
update(V v)
Updates the value for
v . |
protected void |
updateMaxDelta(V v,
double diff) |
protected int max_iterations
protected double tolerance
protected Hypergraph<V,E> graph
protected int total_iterations
protected com.google.common.base.Function<VEPair<V,E>,? extends Number> edge_weights
protected boolean output_reversed
protected boolean hyperedges_are_self_loops
protected double max_delta
public AbstractIterativeScorer(Hypergraph<V,E> g, com.google.common.base.Function<? super E,? extends Number> edge_weights)
g
- the graph for which the instance is to be creatededge_weights
- the edge weights for this instancepublic AbstractIterativeScorer(Hypergraph<V,E> g)
g
.
NOTE: This constructor does not set the internal
edge_weights
variable. If this variable is used by
the subclass which invoked this constructor, it must be initialized
by that subclass.g
- the graph for which the instance is to be createdprotected void setOutputValue(V v, T value)
v
- the vertex whose output value is to be setvalue
- the value to setprotected T getOutputValue(V v)
v
- the vertex whose output value is to be retrievedprotected T getCurrentValue(V v)
v
- the vertex whose current value is to be retrievedprotected void setCurrentValue(V v, T value)
v
- the vertex whose current value is to be setvalue
- the current value to setprotected void initialize()
public void evaluate()
public boolean done()
max_iterations
or if the maximum value change observed is less than tolerance
.done
in interface IterativeContext
true
if this iterative process is finished, and false
otherwise.public void step()
step
in interface IterativeContext
protected void swapOutputForCurrent()
protected abstract double update(V v)
v
.v
- the vertex whose value is to be updatedprotected void updateMaxDelta(V v, double diff)
protected void afterStep()
public T getVertexScore(V v)
getVertexScore
in interface VertexScorer<V,T>
v
- the vertex whose score is requestedpublic int getMaxIterations()
evaluate
will use
prior to terminatingpublic int getIterations()
public void setMaxIterations(int max_iterations)
evaluate
will call step
.max_iterations
- the maximumpublic double getTolerance()
evaluate
will terminate.public void setTolerance(double tolerance)
tolerance
- the size of the largest change that evaluate() will permitpublic com.google.common.base.Function<VEPair<V,E>,? extends Number> getEdgeWeights()
public void setEdgeWeights(com.google.common.base.Function<? super E,? extends Number> edge_weights)
edge_weights
- the Function to use to associate an edge weight with each edgeUniformDegreeWeight
protected Number getEdgeWeight(V v, E e)
e
in the context of its (incident) vertex v
.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 returnede
in the context of its (incident) vertex v
protected void collectDisappearingPotential(V v)
v
- the vertex whose potential is being collectedpublic void acceptDisconnectedGraph(boolean accept)
accept
- true if this instance should accept vertices with no outgoing edges, false otherwisepublic boolean isDisconnectedGraphOK()
public void setHyperedgesAreSelfLoops(boolean arg)
arg
- if true
, hyperedges are treated as self-loopsprotected int getAdjustedIncidentCount(E e)
graph.getIncidentCount(e)
; otherwise it is
graph.getIncidentCount(e) - 1
.e
- the edge whose incident edge count is requestedCopyright © 2015. All rights reserved.