NAG FL Interface
f01sbf (real_nmf_rcomm)
1
Purpose
f01sbf computes a non-negative matrix factorization for a real non-negative by matrix . It uses reverse communication for evaluating matrix products, so that the matrix is not accessed explicitly.
2
Specification
Fortran Interface
Subroutine f01sbf ( |
irevcm, m, n, k, w, ldw, h, ldh, ht, ldht, seed, errtol, comm, icomm, ifail) |
Integer, Intent (In) |
:: |
m, n, k, ldw, ldh, ldht, seed |
Integer, Intent (Inout) |
:: |
irevcm, icomm(9), ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
errtol |
Real (Kind=nag_wp), Intent (Inout) |
:: |
w(ldw,*), h(ldh,*), ht(ldht,*), comm((2*m+n)*k+3) |
|
C Header Interface
#include <nag.h>
void |
f01sbf_ (Integer *irevcm, const Integer *m, const Integer *n, const Integer *k, double w[], const Integer *ldw, double h[], const Integer *ldh, double ht[], const Integer *ldht, const Integer *seed, const double *errtol, double comm[], Integer icomm[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
f01sbf_ (Integer &irevcm, const Integer &m, const Integer &n, const Integer &k, double w[], const Integer &ldw, double h[], const Integer &ldh, double ht[], const Integer &ldht, const Integer &seed, const double &errtol, double comm[], Integer icomm[], Integer &ifail) |
}
|
The routine may be called by the names f01sbf or nagf_matop_real_nmf_rcomm.
3
Description
The matrix
is factorized into the product of an
by
matrix
and a
by
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 .
f01sbf 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 f01sbf to generate the initial values using a random number generator.
f01sbf does not explicitly need to access the elements of ; it only requires the result of matrix multiplications of the form or . A reverse communication interface is used, in which control is returned to the calling program whenever a matrix product is required.
4
References
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 Sciences E92–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 Science 4666 Springer 169–176
Ho N–D (2008) Nonnegative matrix factorization algorithms and applications PhD Thesis Univ. Catholique de Louvain
5
Arguments
Note: this routine uses
reverse communication. Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the argument
irevcm. Between intermediate exits and re-entries,
all arguments other than w and
ht must remain unchanged.
-
1:
– Integer
Input/Output
-
On initial entry: must be set to .
On intermediate exit:
specifies what action you must take before re-entering
f01sbf with
irevcm unchanged. The value of
irevcm should be interpreted as follows:
-
Indicates the start of a new iteration. No action is required by you, but w and h are available for printing, and a limit on the number of iterations can be applied.
-
Indicates that before re-entry to f01sbf, the product must be computed and stored in ht.
-
Indicates that before re-entry to f01sbf, the product must be computed and stored in w.
Note: any values you return to f01sbf as part of the reverse communication procedure should not include floating-point NaN (Not a Number) or infinity values, since these are not handled by f01sbf. If your code does inadvertently return any NaNs or infinities, f01sbf is likely to produce unexpected results.
-
2:
– Integer
Input
-
On entry: , the number of rows of the matrix . Also the number of rows of the matrix .
Constraint:
.
-
3:
– Integer
Input
-
On entry: , the number of columns of the matrix . Also the number of columns of the matrix .
Constraint:
.
-
4:
– Integer
Input
-
On entry:
, the number of columns of the matrix
. Also, the number of rows of the matrix
. See
Section 9.2 for further details.
Constraint:
.
-
5:
– Real (Kind=nag_wp) array
Input/Output
-
Note: the second dimension of the array
w
must be at least
.
On initial entry:
- if , w should be set to an initial iterate for the non-negative matrix factor, .
- If , w need not be set. f01sbf will generate a random initial iterate.
On intermediate exit:
if
or
,
w contains the current iterate of the
non-negative matrix
.
On intermediate re-entry:
- if , w must contain , where is stored in .
- If , or , w must not be changed.
On final exit:
w contains the
non-negative matrix
.
-
6:
– Integer
Input
-
On entry: the first dimension of the array
w as declared in the (sub)program from which
f01sbf is called.
Constraint:
.
-
7:
– Real (Kind=nag_wp) array
Input/Output
-
Note: the second dimension of the array
h
must be at least
.
On initial entry:
- if , h should be set to an initial iterate for the non-negative matrix factor, .
- If , h need not be set. f01sbf will generate a random initial iterate.
On intermediate exit:
if
,
h contains the current iterate of the
non-negative matrix
.
On intermediate re-entry:
h must not be changed.
On final exit:
h contains the
non-negative matrix
.
-
8:
– Integer
Input
-
On entry: the first dimension of the array
h as declared in the (sub)program from which
f01sbf is called.
Constraint:
.
-
9:
– Real (Kind=nag_wp) array
Input/Output
-
Note: the second dimension of the array
ht
must be at least
.
On initial entry:
ht need not be set.
On intermediate exit:
if
,
ht contains the
non-negative matrix
, which is required in order to from
.
On intermediate re-entry: if
,
ht must contain
.
If
,
or
,
ht must not be changed.
On final exit:
ht is undefined.
-
10:
– Integer
Input
-
On entry: the first dimension of the array
ht as declared in the (sub)program from which
f01sbf is called.
Constraint:
.
-
11:
– Integer
Input
-
On initial 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.
-
12:
– 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.
-
13:
– Real (Kind=nag_wp) array
Communication Array
-
-
14:
– Integer array
Communication Array
-
-
15:
– Integer
Input/Output
-
On initial entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On final exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error 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 initial entry, .
Constraint: .
On intermediate re-entry, .
Constraint: , or .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, , and .
Constraint: .
-
On entry, and .
Constraint: .
-
On entry, and .
Constraint: .
-
On entry, and .
Constraint: .
-
An internal error occurred when generating initial values for
w and
h. Please contact
NAG.
-
On entry, one of more of the elements of
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.
7
Accuracy
The Hierarchical Alternating Least Squares algorithm used by
f01sbf 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 f01sbf 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 each time.
Note that even if f01sbf exits with , the factorization given by and may still be a good enough approximation to be useful.
8
Parallelism and Performance
f01sbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f01sbf 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.
f01sbf is designed to be used when is large and sparse. Whenever a matrix multiplication is required, the routine will return control to the calling program so that the multiplication can be done in the most efficient way possible. Note that and will not, in general, be sparse even if is sparse.
If
is small and dense, then
f01saf can be used to compute
and
without the use of a reverse communication interface.
9.1
Uniqueness
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 f01sbf, and are normalized so that the columns of have unit length.
9.2
Choice 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
f12fbf.
9.3
Generating Random Initial Iterates
If
on entry, then
f01sbf uses the routines
g05kff and
g05saf, 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.
9.4
Use in Conjunction with NAG Library Routines
To compute the non-negative matrix factorization, the following skeleton code can normally be used:
revcm: Do
Call f01sbf(irevcm,m,n,k,w,ldw,h,ldh,ht,ldht, &
seed,errtol,comm,icomm,ifail)
If (irevcm == 0) Then
Exit revcm
Else If (irevcm == 1) Then
.. Print W and H if required and check number of iterations ..
Else If (irevcm == 2) Then
.. Compute A^TW and store in ht..
Else If (irevcm == 3) Then
.. Compute AH^T and store in w ..
End If
End Do revcm
The code used to compute the matrix products will vary depending on the way
is stored. If all the elements of
are stored explicitly, then
f06yaf) can be used. If
is triangular, then
f06yff should be used. If
is symmetric, then
f06ycf should be used. For sparse
stored in coordinate storage format
f11xaf and
f11xef can be used. Alternatively, if
is stored in compressed column format
f11mkf can be used.
10
Example
This example finds a non-negative matrix factorization for the matrix
10.1
Program Text
10.2
Program Data
10.3
Program Results