org.neo4j.graphalgo.impl.centrality
Class EigenvectorCentralityArnoldi

java.lang.Object
  extended by org.neo4j.graphalgo.impl.centrality.EigenvectorCentralityArnoldi
All Implemented Interfaces:
EigenvectorCentrality

public class EigenvectorCentralityArnoldi
extends Object
implements EigenvectorCentrality

Computing eigenvector centrality with the "Arnoldi iteration". Convergence is dependent of the eigenvalues of the input adjacency matrix (the network). If the two largest eigenvalues are u1 and u2, a small factor u2/u1 will give a faster convergence (i.e. faster computation). NOTE: Currently only works on Doubles.

Author:
Patrik Larsson

Field Summary
protected  CostEvaluator<Double> costEvaluator
           
protected  boolean doneCalculation
           
protected  Set<Node> nodeSet
           
protected  double precision
           
protected  Direction relationDirection
           
protected  Set<Relationship> relationshipSet
           
protected  int totalIterations
           
protected  Map<Node,Double> values
           
 
Constructor Summary
EigenvectorCentralityArnoldi(Direction relationDirection, CostEvaluator<Double> costEvaluator, Set<Node> nodeSet, Set<Relationship> relationshipSet, double precision)
           
 
Method Summary
 void calculate()
          Internal calculate method that will do the calculation.
 Double getCentrality(Node node)
          This can be used to retrieve the result for every node.
 int getMaxIterations()
           
 int getTotalIterations()
           
protected  double normalize(Map<Node,Double> vector)
          Normalizes a vector represented as a Map.
protected  void processRelationship(Map<Node,Double> newValues, Relationship relationship, boolean backwards)
          Internal method used in the "matrix multiplication" in each iteration.
 void reset()
          This resets the calculation if we for some reason would like to redo it.
protected  int runInternalArnoldi(int iterations)
          This runs the Arnoldi decomposition in a specified number of steps.
 int runIterations(int maxNrIterations)
          This runs a number of iterations in the computation and stops when enough precision has been reached.
 void setMaxIterations(int maxIterations)
          Limit the maximum number of iterations to run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

relationDirection

protected Direction relationDirection

costEvaluator

protected CostEvaluator<Double> costEvaluator

nodeSet

protected Set<Node> nodeSet

relationshipSet

protected Set<Relationship> relationshipSet

precision

protected double precision

doneCalculation

protected boolean doneCalculation

values

protected Map<Node,Double> values

totalIterations

protected int totalIterations
Constructor Detail

EigenvectorCentralityArnoldi

public EigenvectorCentralityArnoldi(Direction relationDirection,
                                    CostEvaluator<Double> costEvaluator,
                                    Set<Node> nodeSet,
                                    Set<Relationship> relationshipSet,
                                    double precision)
Parameters:
relationDirection - The direction in which the paths should follow the relationships.
costEvaluator -
nodeSet - The set of nodes the calculation should be run on.
relationshipSet - The set of relationships that should be processed.
precision - Precision factor (ex. 0.01 for 1% error). Note that this is not the error from the correct values, but the amount of change tolerated in one iteration.
See Also:
CostEvaluator
Method Detail

getCentrality

public Double getCentrality(Node node)
This can be used to retrieve the result for every node. Will return null if the node is not contained in the node set initially given, or doesn't receive a result because no relationship points to it.

Specified by:
getCentrality in interface EigenvectorCentrality
Parameters:
node -
Returns:

reset

public void reset()
This resets the calculation if we for some reason would like to redo it.

Specified by:
reset in interface EigenvectorCentrality

calculate

public void calculate()
Internal calculate method that will do the calculation. This can however be called externally to manually trigger the calculation.The calculation is done the first time this method is run. Upon successive requests, the old result is returned, unless the calculation is reset via reset()

Specified by:
calculate in interface EigenvectorCentrality

runIterations

public int runIterations(int maxNrIterations)
This runs a number of iterations in the computation and stops when enough precision has been reached. A maximum number of iterations to perform is supplied. NOTE: For maxNrIterations > 0 at least one iteration will be run, regardless if good precision has already been reached or not. This method also ignores the global limit defined by maxIterations.

Parameters:
maxNrIterations - The maximum number of iterations to run.
Returns:
the number of iterations performed. if this is lower than the given maxNrIterations the desired precision has been reached.

runInternalArnoldi

protected int runInternalArnoldi(int iterations)
This runs the Arnoldi decomposition in a specified number of steps.

Parameters:
iterations - The number of steps to perform, i.e. the dimension of the H matrix.
Returns:
The number of iterations actually performed. This can be less than the input argument if the starting vector is not linearly dependent on that many eigenvectors.

processRelationship

protected void processRelationship(Map<Node,Double> newValues,
                                   Relationship relationship,
                                   boolean backwards)
Internal method used in the "matrix multiplication" in each iteration.


normalize

protected double normalize(Map<Node,Double> vector)
Normalizes a vector represented as a Map.

Parameters:
vector -
Returns:
the initial length of the vector.

getTotalIterations

public int getTotalIterations()
Returns:
the number of iterations made.

getMaxIterations

public int getMaxIterations()
Returns:
the maxIterations

setMaxIterations

public void setMaxIterations(int maxIterations)
Limit the maximum number of iterations to run. Per default, the maximum iterations are set to Integer.MAX_VALUE, which should be limited to 50-100 normally.

Parameters:
maxIterations - the maxIterations to set


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.