The routine may be called by the names f01saf or nagf_matop_real_nmf.
3Description
The matrix is factorized into the product of an matrix and a matrix , both with non-negative elements. The factorization is approximate, , with and chosen to minimize the functional
You are free to choose any value for , provided . The product will then be a low-rank approximation to , with rank at most .
f01saf finds and using an iterative method known as the Hierarchical Alternating Least Squares algorithm. You may specify initial values for and , or you may provide a seed value for f01saf to generate the initial values using a random number generator.
4References
Cichocki A and Phan A–H (2009) Fast local algorithms for large scale nonnegative matrix and tensor factorizations IEICE Transactions on Fundamentals of Electronics, Communications and Computer SciencesE92–A 708–721
Cichocki A, Zdunek R and Amari S–I (2007) Hierarchical ALS algorithms for nonnegative matrix and 3D tensor factorization Lecture Notes in Computer Science4666 Springer 169–176
Ho N–D (2008) Nonnegative matrix factorization algorithms and applications PhD Thesis Univ. Catholique de Louvain
5Arguments
1: – IntegerInput
On entry: , the number of rows of the matrix . Also the number of rows of the matrix .
Constraint:
.
2: – IntegerInput
On entry: , the number of columns of the matrix . Also the number of columns of the matrix .
Constraint:
.
3: – IntegerInput
On entry: , the number of columns of the matrix ; the number of rows of the matrix . See Section 9.2 for further details.
Constraint:
.
4: – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array a
must be at least
.
On entry: the non-negative matrix .
5: – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f01saf is called.
Constraint:
.
6: – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array w
must be at least
.
On entry:
if , w should be set to an initial iterate for the non-negative matrix factor, .
If , w need not be set. f01saf will generate a random initial iterate.
On exit: the non-negative matrix factor, .
7: – IntegerInput
On entry: the first dimension of the array w as declared in the (sub)program from which f01saf is called.
Constraint:
.
8: – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array h
must be at least
.
On entry:
if , h should be set to an initial iterate for the non-negative matrix factor, .
If , h need not be set. f01saf will generate a random initial iterate.
On exit: the non-negative matrix factor, .
9: – IntegerInput
On entry: the first dimension of the array h as declared in the (sub)program from which f01saf is called.
Constraint:
.
10: – IntegerInput
On entry:
if , the supplied values of and are used for the initial iterate.
If , the value of seed is used to seed a random number generator for the initial iterates and . See Section 9.3 for further details.
11: – Real (Kind=nag_wp)Input
On entry: the convergence tolerance for when the Hierarchical Alternating Least Squares iteration has reached a stationary point. If , is used.
12: – IntegerInput
On entry: specifies the maximum number of iterations to be used. If , is used.
13: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, . Constraint: .
On entry, . Constraint: .
On entry, , and . Constraint: .
On entry, and .
Constraint: .
On entry, and . Constraint: .
On entry, and . Constraint: .
The routine has failed to converge after iterations. The factorization given by w and h may still be a good enough approximation to be useful. Alternatively an improved factorization may be obtained by increasing maxit or using different initial choices of w and h.
An internal error occurred when generating initial values for w and h. Please contact NAG.
On entry, one of more of the elements of a, w or h were negative.
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
The Hierarchical Alternating Least Squares algorithm used by f01saf is locally convergent; it is guaranteed to converge to a stationary point of , but this may not be the global minimum. The iteration is deemed to have converged if the gradient of is less than errtol times the gradient at the initial values of and .
Due to the local convergence property, you may wish to run f01saf multiple times with different starting iterates. This can be done by explicitly providing the starting values of and each time, or by choosing a different random seed for each routine call.
Note that even if f01saf exits with , the factorization given by and may still be a good enough approximation to be useful.
8Parallelism and Performance
f01saf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f01saf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9Further Comments
Each iteration of the Hierarchical Alternating Least Squares algorithm requires floating-point operations.
The real allocatable memory required is .
If is large and sparse, then f01sbf should be used to compute a non-negative matrix factorization.
9.1Uniqueness
Note that non-negative matrix factorization is not unique. For a factorization given by the matrices and , an equally good solution is given by and , where is any real non-negative matrix whose inverse is also non-negative. In f01saf, and are normalized so that the columns of have unit length.
9.2Choice of
The most appropriate choice of the factorization rank, , is often problem dependent. Details of your particular application may help in guiding your choice of , for example, it may be known a priori that the data in naturally falls into a certain number of categories.
Alternatively, trial and error can be used. Compute non-negative matrix factorizations for several different values of (typically with ) and select the one that performs the best.
Finally, it is also possible to use a singular value decomposition of to guide your choice of , by looking for an abrupt decay in the size of the singular values of . The singular value decomposition can be computed using f08kbf.
9.3Generating Random Initial Iterates
If on entry, then f01saf uses the routines g05kffandg05saf, with the NAG basic generator, to populate w and h. For further information on this random number generator see Section 2.1.1 in the G05 Chapter Introduction.
Note that this generator gives a repeatable sequence of random numbers, so if the value of seed is not changed between routine calls, then the same initial iterates will be generated.
10Example
This example finds a non-negative matrix factorization for the matrix