Package org.carrot2.math.matrix
Class LocalNonnegativeMatrixFactorization
java.lang.Object
org.carrot2.math.matrix.LocalNonnegativeMatrixFactorization
- All Implemented Interfaces:
IterativeMatrixFactorization
,MatrixFactorization
Performs matrix factorization using the Local Non-negative Matrix Factorization algorithm with
minimization of the Kullback-Leibler divergence between A and UV' and multiplicative updating.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.carrot2.math.mahout.matrix.DoubleMatrix2D
Input matrixprotected double[]
Sorting aggregatesprotected double
Current approximation errorprotected double[]
Approximation errors during subsequent iterationsprotected static int
protected static final int
protected static final boolean
protected static final SeedingStrategy
protected static double
protected int
Iteration counterprotected int
The desired number of base vectorsprotected int
The maximum number of iterations the algorithm is allowed to runprotected boolean
Order base vectors according to their 'activity'?protected SeedingStrategy
Seeding strategyprotected double
If the percentage decrease in approximation error becomes smaller thanstopThreshold
, the algorithm will stop.protected org.carrot2.math.mahout.matrix.DoubleMatrix2D
Base vector result matrixprotected org.carrot2.math.mahout.matrix.DoubleMatrix2D
Coefficient result matrix -
Constructor Summary
ConstructorsConstructorDescriptionLocalNonnegativeMatrixFactorization
(org.carrot2.math.mahout.matrix.DoubleMatrix2D A) Creates the LocalNonnegativeMatrixFactorization object for matrix A. -
Method Summary
Modifier and TypeMethodDescriptionvoid
compute()
Computes the factorization.double[]
Returns column aggregates for a sorted factorization, andnull
for an unsorted factorization.double
Returns approximation error achieved after the last iteration of the algorithm or -1 if the approximation error is not available.double[]
int
Returns the number of iterations the algorithm has completed.int
getK()
Returns the number of base vectors k .int
Returns the maximum number of iterations the algorithm is allowed to run.Returns currentSeedingStrategy
.double
Returns the algorithmsstopThreshold
.org.carrot2.math.mahout.matrix.DoubleMatrix2D
getU()
Returns the U matrix (base vectors matrix).org.carrot2.math.mahout.matrix.DoubleMatrix2D
getV()
Returns the V matrix (coefficient matrix)boolean
Returnstrue
when the factorization is set to generate an ordered basis.protected void
order()
Orders U and V matrices according to the 'activity' of base vectors.void
setK
(int k) Sets the number of base vectors k .void
setMaxIterations
(int maxIterations) Sets the maximum number of iterations the algorithm is allowed to run.void
setOrdered
(boolean ordered) Set totrue
to generate an ordered basis.void
setSeedingStrategy
(SeedingStrategy seedingStrategy) Sets newSeedingStrategy
.void
setStopThreshold
(double stopThreshold) Sets the algorithmsstopThreshold
.toString()
protected boolean
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.carrot2.math.matrix.MatrixFactorization
getU, getV
-
Field Details
-
k
protected int kThe desired number of base vectors -
DEFAULT_K
protected static int DEFAULT_K -
maxIterations
protected int maxIterationsThe maximum number of iterations the algorithm is allowed to run -
DEFAULT_MAX_ITERATIONS
protected static final int DEFAULT_MAX_ITERATIONS- See Also:
-
stopThreshold
protected double stopThresholdIf the percentage decrease in approximation error becomes smaller thanstopThreshold
, the algorithm will stop. Note: calculation of approximation error is quite costly. Setting the threshold to -1 turns off approximation error calculation and hence makes the algorithm do the maximum number of iterations. -
DEFAULT_STOP_THRESHOLD
protected static double DEFAULT_STOP_THRESHOLD -
seedingStrategy
Seeding strategy -
DEFAULT_SEEDING_STRATEGY
-
ordered
protected boolean orderedOrder base vectors according to their 'activity'? -
DEFAULT_ORDERED
protected static final boolean DEFAULT_ORDERED- See Also:
-
approximationError
protected double approximationErrorCurrent approximation error -
approximationErrors
protected double[] approximationErrorsApproximation errors during subsequent iterations -
iterationsCompleted
protected int iterationsCompletedIteration counter -
aggregates
protected double[] aggregatesSorting aggregates -
A
protected org.carrot2.math.mahout.matrix.DoubleMatrix2D AInput matrix -
U
protected org.carrot2.math.mahout.matrix.DoubleMatrix2D UBase vector result matrix -
V
protected org.carrot2.math.mahout.matrix.DoubleMatrix2D VCoefficient result matrix
-
-
Constructor Details
-
LocalNonnegativeMatrixFactorization
public LocalNonnegativeMatrixFactorization(org.carrot2.math.mahout.matrix.DoubleMatrix2D A) Creates the LocalNonnegativeMatrixFactorization object for matrix A. Before accessing results, perform computations by calling thecompute()
method.- Parameters:
A
- matrix to be factorized
-
-
Method Details
-
compute
public void compute()Computes the factorization. -
toString
-
setK
public void setK(int k) Sets the number of base vectors k .- Parameters:
k
- the number of base vectors
-
getK
public int getK()Returns the number of base vectors k . -
updateApproximationError
protected boolean updateApproximationError()- Returns:
- true if the decrease in the approximation error is smaller than the
stopThreshold
-
order
protected void order()Orders U and V matrices according to the 'activity' of base vectors. -
getSeedingStrategy
Returns currentSeedingStrategy
. -
setSeedingStrategy
Sets newSeedingStrategy
. -
getMaxIterations
public int getMaxIterations()Returns the maximum number of iterations the algorithm is allowed to run. -
setMaxIterations
public void setMaxIterations(int maxIterations) Sets the maximum number of iterations the algorithm is allowed to run. -
getStopThreshold
public double getStopThreshold()Returns the algorithmsstopThreshold
. If the percentage decrease in approximation error becomes smaller thanstopThreshold
, the algorithm will stop. -
setStopThreshold
public void setStopThreshold(double stopThreshold) Sets the algorithmsstopThreshold
. If the percentage decrease in approximation error becomes smaller thanstopThreshold
, the algorithm will stop.Note: calculation of approximation error is quite costly. Setting the threshold to -1 turns off calculation of the approximation error and hence makes the algorithm do the maximum allowed number of iterations.
-
getApproximationError
public double getApproximationError()Description copied from interface:IterativeMatrixFactorization
Returns approximation error achieved after the last iteration of the algorithm or -1 if the approximation error is not available.- Specified by:
getApproximationError
in interfaceIterativeMatrixFactorization
- Returns:
- approximation error or -1
-
getApproximationErrors
public double[] getApproximationErrors() -
getIterationsCompleted
public int getIterationsCompleted()Description copied from interface:IterativeMatrixFactorization
Returns the number of iterations the algorithm has completed.- Specified by:
getIterationsCompleted
in interfaceIterativeMatrixFactorization
- Returns:
- the number of iterations the algorithm has completed
-
isOrdered
public boolean isOrdered()Returnstrue
when the factorization is set to generate an ordered basis. -
setOrdered
public void setOrdered(boolean ordered) Set totrue
to generate an ordered basis. -
getAggregates
public double[] getAggregates()Returns column aggregates for a sorted factorization, andnull
for an unsorted factorization. -
getU
public org.carrot2.math.mahout.matrix.DoubleMatrix2D getU()Description copied from interface:MatrixFactorization
Returns the U matrix (base vectors matrix).- Specified by:
getU
in interfaceMatrixFactorization
- Returns:
- U matrix
-
getV
public org.carrot2.math.mahout.matrix.DoubleMatrix2D getV()Description copied from interface:MatrixFactorization
Returns the V matrix (coefficient matrix)- Specified by:
getV
in interfaceMatrixFactorization
- Returns:
- V matrix
-