Package it.unimi.dsi.law.big.rank
Class SpectralRanking
java.lang.Object
it.unimi.dsi.law.big.rank.SpectralRanking
- Direct Known Subclasses:
PageRank
public abstract class SpectralRanking extends Object
A big version of
SpectralRanking
.- Author:
- Sebastiano Vigna
- See Also:
SpectralRanking
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SpectralRanking.IterationNumberStoppingCriterion
A stopping criterion that stops whenever the number of iterations exceeds a given bound.static class
SpectralRanking.NormStoppingCriterion
A stopping criterion that evaluatesnormDelta()
, and stops if this value is smaller than a given threshold.static interface
SpectralRanking.StoppingCriterion
A a strategy that decides when a computation should be stopped. -
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_ITER
Default maximum number of iterations (note that this value is used as a default by main methods).static Norm
DEFAULT_NORM
The default norm (Norm.L_INFINITY
).static double
DEFAULT_THRESHOLD
Default threshold (note that this value is used as a default by main methods).ImmutableGraph
graph
The graph.int
iteration
The current step (0 after initialization).Logger
logger
A logger defined by the implementing subclasses.long
n
The number of nodes ofgraph
, cached.double[][]
rank
The current rank vector.protected static double
STOCHASTIC_TOLERANCE
The admitted tolerance in the verification that a vector is a stochastic one. -
Constructor Summary
Constructors Constructor Description SpectralRanking(ImmutableGraph graph, Logger logger)
Creates a new instance. -
Method Summary
Modifier and Type Method Description static SpectralRanking.StoppingCriterion
and(SpectralRanking.StoppingCriterion stop1, SpectralRanking.StoppingCriterion stop2)
Composes two stopping criteria, producing a single stopping criterion (the computation stops iff both conditions become true; lazy boolean evaluation is applied).protected byte[][]
approximateNormVector(DoubleIterator doubleIterator)
Returns a compact logarithmic approximation of a norm vector.Properties
buildProperties(String graphBasename)
Returns aProperties
object that contains all parameters used by the computation.void
clear()
Clears all data and releases resources by nullingrank
(i.e., results we no longer be available).void
init()
Initializes the rank vector, zeroesiteration
and logs basic data.protected static boolean
isStochastic(DoubleBigList v)
Commodity method checking whether a vector is stochastic (nonnegative entries summing up to one withinSTOCHASTIC_TOLERANCE
).double
normDelta()
Returns the norm of an estimation of the distance to the limit of the iterative process: depending on the implementation, this can be an actual bound or, for example, just the difference between the last two approximations.static SpectralRanking.StoppingCriterion
or(SpectralRanking.StoppingCriterion stop1, SpectralRanking.StoppingCriterion stop2)
Composes two stopping criteria, producing a single stopping criterion (the computation stops iff either condition becomes true; lazy boolean evaluation is applied).abstract void
step()
Performs one computation step.void
stepUntil(SpectralRanking.StoppingCriterion stoppingCriterion)
Callsinit()
and steps until a given stopping criterion is met.
-
Field Details
-
DEFAULT_THRESHOLD
public static final double DEFAULT_THRESHOLDDefault threshold (note that this value is used as a default by main methods).- See Also:
- Constant Field Values
-
DEFAULT_MAX_ITER
public static final int DEFAULT_MAX_ITERDefault maximum number of iterations (note that this value is used as a default by main methods).- See Also:
- Constant Field Values
-
DEFAULT_NORM
The default norm (Norm.L_INFINITY
). -
STOCHASTIC_TOLERANCE
protected static final double STOCHASTIC_TOLERANCEThe admitted tolerance in the verification that a vector is a stochastic one. A stochastic vector is nonnegative and has ℓ1 norm equal to 1 ±STOCHASTIC_TOLERANCE
.- See Also:
- Constant Field Values
-
graph
The graph. -
n
public final long nThe number of nodes ofgraph
, cached. -
logger
A logger defined by the implementing subclasses. -
rank
public double[][] rankThe current rank vector. -
iteration
public int iterationThe current step (0 after initialization).
-
-
Constructor Details
-
SpectralRanking
Creates a new instance.- Parameters:
graph
- the graph.logger
- a logger.
-
-
Method Details
-
and
public static SpectralRanking.StoppingCriterion and(SpectralRanking.StoppingCriterion stop1, SpectralRanking.StoppingCriterion stop2)Composes two stopping criteria, producing a single stopping criterion (the computation stops iff both conditions become true; lazy boolean evaluation is applied).- Parameters:
stop1
- a stopping criterion.stop2
- a stopping criterion.- Returns:
- a criterion that decides to stop as soon as both criteria are satisfied.
-
or
public static SpectralRanking.StoppingCriterion or(SpectralRanking.StoppingCriterion stop1, SpectralRanking.StoppingCriterion stop2)Composes two stopping criteria, producing a single stopping criterion (the computation stops iff either condition becomes true; lazy boolean evaluation is applied).- Parameters:
stop1
- a stopping criterion.stop2
- a stopping criterion.- Returns:
- a criterion that decides to stop as soon as one of the two criteria is satisfied.
-
isStochastic
Commodity method checking whether a vector is stochastic (nonnegative entries summing up to one withinSTOCHASTIC_TOLERANCE
).This method uses Kahan's summation algorithm.
- Parameters:
v
- the vector to check.- Returns:
- true if the vector is stochastic.
-
buildProperties
Returns aProperties
object that contains all parameters used by the computation.Implementing subclasses should extends this method by calling
super()
and setting additional properties on the resultingProperties
.- Parameters:
graphBasename
- basename of the graph- Returns:
- a properties object that represent all the parameters used to calculate the ranking.
-
init
Initializes the rank vector, zeroesiteration
and logs basic data. Please extend this method to handle additional attributes.- Throws:
IOException
-
step
Performs one computation step.- Throws:
IOException
-
normDelta
public double normDelta()Returns the norm of an estimation of the distance to the limit of the iterative process: depending on the implementation, this can be an actual bound or, for example, just the difference between the last two approximations.This method must be implemented by concrete subclasses if you want to use
SpectralRanking.NormStoppingCriterion
.- Returns:
- the norm of an estimation of the distance to the limit.
- Throws:
IllegalStateException
- if called before the first iteration.UnsupportedOperationException
- if it is not possible to compute a norm.
-
stepUntil
Callsinit()
and steps until a given stopping criterion is met. The criterion is checked a posteriori (i.e., after each step); this means that at least one step is performed.- Parameters:
stoppingCriterion
- the stopping criterion to be used.- Throws:
IOException
-
clear
public void clear()Clears all data and releases resources by nullingrank
(i.e., results we no longer be available). Please extend this method to handle additional attributes. -
approximateNormVector
Returns a compact logarithmic approximation of a norm vector.- Parameters:
doubleIterator
- an iterator enumerating a norm vector.- Returns:
- an array of bytes containing the opposite of a lower bound on the binary logarithm of the doubles returned by the iterator.
-