NnmfPack  2.1
Functions
bdiv_cpu.h File Reference

Header file for using the betadivergence cuda functions with CPU. More...

Go to the source code of this file.

Functions

int dbdiv_cpu (const int m, const int n, const int k, const double *A, double *W, double *H, const double beta, const int uType, const int nIter)
 dbdiv_cpu is a wrapper that calls the adequate function to performs NNMF using betadivergence using double precision with CPU More...
 
int sbdiv_cpu (const int m, const int n, const int k, const float *A, float *W, float *H, const float beta, const int uType, const int nIter)
 
int dbdivg_cpu (const int m, const int n, const int k, const double *A, double *W, double *H, const double beta, const int uType, const int nIter)
 dbdivg_cpu performs the NNMF using beta-divergence when beta is != 1 and !=2, using double precision. More...
 
int sbdivg_cpu (const int m, const int n, const int k, const float *A, float *W, float *H, const float beta, const int uType, const int nIter)
 sbdivg_cpu performs NNMF using betadivergence for general case (beta <> 1 and 2) using simple precision More...
 
int dbdivone_cpu (const int m, const int n, const int k, const double *A, double *W, double *H, const int uType, const int nIter)
 dbdivone_cpu performs NNMF using beta-divergence when beta=1, using double precision More...
 
int sbdivone_cpu (const int m, const int n, const int k, const float *A, float *W, float *H, const int uType, const int nIter)
 sbdivone_cpu performs NNMF using betadivergence when beta=1 using simple precision More...
 
void dupdate1H_x86 (const int n, const double *X, double *__restrict__ H)
 This function computes double precision H(i)=H(i)*B(i)/C(i) where matrices B and C are stored in the same buffer (called X). All B 1st and after C. More...
 
void supdate1H_x86 (const int n, const float *X, float *__restrict__ H)
 This function computes simple precision H(i)=H(i)*B(i)/C(i) where matrices B and C are stored in the same buffer (called X). All B 1st and after C. More...
 
void dupdate1W_x86 (const int m, const int n, const double *X, double *__restrict__ W)
 
void supdate1W_x86 (const int m, const int n, const float *X, float *__restrict__ W)
 This function computes double precision W[i]=W[i]*D[i]/E[i] where matrices D and E are stored in the same buffer (called X) according beta-divergence general case (see dbdivg_x86(...)) More...
 
void dkernelH_x86 (const int m, const int n, const double *L, const double *A, double *__restrict__ R, const double expo)
 
void skernelH_x86 (const int m, const int n, const float *L, const float *A, float *__restrict__ R, const float expo)
 This function computes simple precision R(i)=(L(i)^expo)*A[i] and R(i+m*n)=L[i]*(L(i)^expo) Note "expo" is a real number expo < 0 or expo > 0. More...
 
void dkernelW_x86 (const int m, const int n, const double *L, const double *A, double *__restrict__ R, const double expo)
 This function computes double precision R(pos)=L(i)^expo)*A(i) and R(pos+m)=L(i)*(L(i)^expo) Note expo is a real number expo < 0 or expo > 0. More...
 
void skernelW_x86 (const int m, const int n, const float *L, const float *A, float *__restrict__ R, const float expo)
 This function computes simple precision R(pos)=L(i)^expo)*A(i) and R(pos+m)=L(i)*(L(i)^expo) Note expo is a real number expo < 0 or expo > 0. More...
 
void dupdate2H_x86 (const int m, const int n, const double *X, const double *B, double *__restrict__ H)
 This function computes double precision H(i)=H(i)*(B(i)/y(j)) More...
 
void supdate2H_x86 (const int m, const int n, const float *X, const float *B, float *__restrict__ H)
 This function performs the simple H(i)=H(i)*(B(i)/y(j)) More...
 
void dupdate2W_x86 (const int m, const int n, const double *X, const double *B, double *__restrict__ W)
 This function performs double precision W(i)=W(i)*(B(i)/y(j)) More...
 
void supdate2W_x86 (const int m, const int n, const float *X, const float *B, float *__restrict__ W)
 This function computes simple precision W(i)=W(i)*(B(i)/y(j)) More...
 
void derrorbd0_x86 (const int n, const double *x, double *__restrict__ y)
 This function performs auxiliar double precision operations when error is computed using betadivergence error formula and beta = 0. More...
 
void serrorbd0_x86 (const int n, const float *x, float *__restrict__ y)
 This function performs auxiliar simple precision operations when error is computed using betadivergence error formula and beta = 0. More...
 
void derrorbd1_x86 (const int n, const double *x, double *__restrict__ y)
 This function performs auxiliar double precision operations when error is computed using betadivergence error formula and beta = 1. More...
 
void serrorbd1_x86 (const int n, const float *x, float *__restrict__ y)
 This function performs auxiliar simple precision operations when error is computed using betadivergence error formula and beta = 1. More...
 
void derrorbdg_x86 (const int n, const double *x, double *__restrict__ y, const double beta)
 This function performs auxiliar double precision operations when error is computed using betadivergence error formula with (beta != 0) and (beta != 1) More...
 
void serrorbdg_x86 (const int n, const float *x, float *__restrict__ y, const float beta)
 This function performs auxiliar simple precision operations when error is computed using betadivergence error formula with (beta != 0) and (beta != 1) More...
 
double derrorbd_x86 (const int m, const int n, const int k, const double *A, const double *W, const double *H, const double betadiv)
 This function returns double precision error when error is computed using betadivergence error formula. More...
 
float serrorbd_x86 (const int m, const int n, const int k, const float *A, const float *W, const float *H, const float betadiv)
 This function returns simple precision error when error is computed using betadivergence error formula. More...
 

Detailed Description

Header file for using the betadivergence cuda functions with CPU.

Author
Information Retrieval and Parallel Computing Group (IRPCG)
University of Oviedo, Spain
Interdisciplinary Computation and Communication Group (INCO2)
Universitat Politecnica de Valencia, Spain.
Contact: nnmfp.nosp@m.ack@.nosp@m.gmail.nosp@m..com
Date
04/11/14

Definition in file bdiv_cpu.h.

Function Documentation

◆ dbdiv_cpu()

int dbdiv_cpu ( const int  m,
const int  n,
const int  k,
const double *  A,
double *  W,
double *  H,
const double  beta,
const int  uType,
const int  nIter 
)

dbdiv_cpu is a wrapper that calls the adequate function to performs NNMF using betadivergence using double precision with CPU

Parameters
m(input) Number of rows of matrix A and matrix W
n(input) Number of columns of matrix A and matrix H
k(input) Number of columns of matrix W and rows of H
A(input) Double precision input matrix of (m * n) number of elements stored using 1D column-major
W(inout) Double precision input/output matrix of (m * k) number of elements stored using 1D column-major
H(inout) Double precision input/output matrix of (k * n) number of elements stored using 1D column-major
beta(input) Double precision value. The parameter beta of betadivergence method
uType(input) It can be UpdateAll (W and H are updated), UpdateW (only H is updated) or UpdateH (only W is updated)
nIter(input) Number of iterations
Returns
: 0 if all is OK, -1 otherwise

Definition at line 1059 of file bdiv_cpu.c.

◆ dbdivg_cpu()

int dbdivg_cpu ( const int  m,
const int  n,
const int  k,
const double *  A,
double *  W,
double *  H,
const double  expo,
const int  uType,
int  nIter 
)

dbdivg_cpu performs the NNMF using beta-divergence when beta is != 1 and !=2, using double precision.

The algorithm is
  repit nIter times
    STEP 1
      L=W*H
      L1=L(.^)(beta-2)
      L2=L1(.*)A
      L1=L1(.*)L
      B=W'L2
      C=W'*L1
      H=H(.
)B(./)C

    STEP 2
      L=W*H
      L1=L(.^)(beta-2)
      L2=L1(.*)A
      L1=L1(.*)L
      D=L2*H'
      E=L1*H'
      W=W(.*)D(./)E
  end repit
End algorithm

In real live L1 and L2 are (m*n) matrices used in STEP 1 and 2. For performance reasons only one 1D colum-mayor buffer, named R in next code, of size 2*m*n is used In STEP 1, first part of R (m*n positions) is L2 and the second part is L1. In STEP 2, fisrt column of R (2*m positions) is composed by the first column of L2 following first column of L1. Second column of R (2*m positions) is composed by the sencond column of L2 following second column of L1. 3rd column of R ... and so on

In real live B and C are (k*n) matrices used in STEP 1, and D and E are (m*k) matrices used in STEP 2. B/C and D/E are independent. However we do not have L1 and L2, we have R, and we can do B=W'*L2 and C=W'*L1 (or D=L2*H' and E=L1*H') at the same time. For this reason only one matrix is declared to save space. This is matrix M with size 2*max(m,n)*k

Parameters
m(input) Number of rows of matrix A and matrix W
n(input) Number of columns of matrix A and matrix H
k(input) Number of columns of matrix W and rows of H
A(input) Double precision input matrix of (m * n) number of elements stored using 1D column-major
W(inout) Double precision input/output matrix of (m * k) number of elements stored using 1D column-major
H(inout) Double precision input/output matrix of (k * n) number of elements stored using 1D column-major
expo(input) Double precision value. The exponent beta of betadivergence method
uType(input) It can be UpdateAll (W and H are updated), UpdateW (only H is updated) or UpdateH (only W is updated)
nIter(input) Number of iterations

It returns 0 if all is OK.

Definition at line 87 of file bdiv_cpu.c.

◆ dbdivone_cpu()

int dbdivone_cpu ( const int  m,
const int  n,
const int  k,
const double *  A,
double *  W,
double *  H,
const int  uType,
const int  nIter 
)

dbdivone_cpu performs NNMF using beta-divergence when beta=1, using double precision

The algorithm is
  repit nIter times
    STEP 1
      y(i)=sum(W(j,i) for all j in range) for all i in range
      L=W*H
      L=A(./)L
      B=W'L
      B(i,j)=B(i,j) / y(i) for all B elements
      H=H(.
)B

    STEP 2
      y(i)=sum(H(i,j) for all j in range) for all i in range
      L=W*H
      L=A(./)L
      D=L*H'
      B(i,j)=B(i,j) / y(j) for all B elements
      W=W(.*)D
    end repit
End algorithm

In real live B is a (k*n) matrix used in STEP 1, and D is a (m*k) matrix used in STEP 2. B and D are independent. For this reason only 1 matrix of size max(m,n)*k is declared/used

Parameters
m(input) Number of rows of matrix A and matrix W
n(input) Number of columns of matrix A and matrix H
k(input) Number of columns of matrix W and rows of H
A(input) Double precision input matrix of (m * n) number of elements stored using 1D column-major
W(inout) Double precision input/output matrix of (m * k) number of elements stored using 1D column-major
H(inout) Double precision input/output matrix of (k * n) number of elements stored using 1D column-major
uType(input) It can be UpdateAll (W and H are updated), UpdateW (only H is updated) or UpdateH (only W is updated)
nIter(input) Number of iterations

It returns 0 if all is OK.

Definition at line 566 of file bdiv_cpu.c.

◆ derrorbd0_x86()

void derrorbd0_x86 ( const int  n,
const double *  x,
double *__restrict__  y 
)

This function performs auxiliar double precision operations when error is computed using betadivergence error formula and beta = 0.

Parameters
n(input) Number of elements of x and y
x(input) Double precision input vector/matrix
y(inout) Double precision input/output vector/matrix

Definition at line 1569 of file bdiv_cpu.c.

◆ derrorbd1_x86()

void derrorbd1_x86 ( const int  n,
const double *  x,
double *__restrict__  y 
)

This function performs auxiliar double precision operations when error is computed using betadivergence error formula and beta = 1.

Parameters
n(input) Number of elements of x and y
x(input) Double precision input vector/matrix
y(inout) Double precision input/output vector/matrix

Definition at line 1635 of file bdiv_cpu.c.

◆ derrorbd_x86()

double derrorbd_x86 ( const int  m,
const int  n,
const int  k,
const double *  A,
const double *  W,
const double *  H,
const double  beta 
)

This function returns double precision error when error is computed using betadivergence error formula.

Parameters
m(input) Number of rows of A and W
n(input) Number of columns of A and H
k(input) Number of columns/rows of W/H
A(input) Double precision input matrix A
W(input) Double precision input matrix W
H(input) Double precision input matrix H
beta(input) Double precision beta value

Definition at line 1782 of file bdiv_cpu.c.

◆ derrorbdg_x86()

void derrorbdg_x86 ( const int  n,
const double *  x,
double *__restrict__  y,
const double  beta 
)

This function performs auxiliar double precision operations when error is computed using betadivergence error formula with (beta != 0) and (beta != 1)

Parameters
n(input) Number of elements of x and y
x(input) Double precision input vector/matrix
y(inout) Double precision input/output vector/matrix
beta(input) Double precision value of beta

Definition at line 1702 of file bdiv_cpu.c.

◆ dkernelH_x86()

void dkernelH_x86 ( const int  m,
const int  n,
const double *  L,
const double *  A,
double *__restrict__  R,
const double  expo 
)

Definition at line 1116 of file bdiv_cpu.c.

◆ dkernelW_x86()

void dkernelW_x86 ( const int  m,
const int  n,
const double *  L,
const double *  A,
double *__restrict__  R,
const double  expo 
)

This function computes double precision R(pos)=L(i)^expo)*A(i) and R(pos+m)=L(i)*(L(i)^expo) Note expo is a real number expo < 0 or expo > 0.

Parameters
m(input) Number of rows of L, A and R matrices
n(input) Number of columns of L, A and R matrices
L(input) Double precision input matrix (1D column-major)
A(input) Double precision input matrix (1D column-major)
R(output) Double precision output matrix (1D column-major)
expo(input) the "power of" for function pow(). It is a double precision value

Definition at line 1204 of file bdiv_cpu.c.

◆ dupdate1H_x86()

void dupdate1H_x86 ( const int  n,
const double *  X,
double *__restrict__  H 
)

This function computes double precision H(i)=H(i)*B(i)/C(i) where matrices B and C are stored in the same buffer (called X). All B 1st and after C.

Parameters
n(input) Number of elements of H
X(input) Simple precision input matrix (1D column-major)
H(inout) Simple precision input/output matrix (1D column-major)

Definition at line 1293 of file bdiv_cpu.c.

◆ dupdate1W_x86()

void dupdate1W_x86 ( const int  m,
const int  n,
const double *  X,
double *__restrict__  W 
)

Definition at line 1359 of file bdiv_cpu.c.

◆ dupdate2H_x86()

void dupdate2H_x86 ( const int  m,
const int  n,
const double *  y,
const double *  B,
double *__restrict__  H 
)

This function computes double precision H(i)=H(i)*(B(i)/y(j))

Parameters
m(input) Number of rows of B and H, and number of elements of vector y
n(input) Number of columns of B and A
y(input) Double precision vector with the sum of W columns
B(input) Double precision input matrix (1D column-major)
H(inout) Double precision input/output matrix (1D column-major)

Definition at line 1435 of file bdiv_cpu.c.

◆ dupdate2W_x86()

void dupdate2W_x86 ( const int  m,
const int  n,
const double *  y,
const double *  B,
double *__restrict__  W 
)

This function performs double precision W(i)=W(i)*(B(i)/y(j))

Parameters
m(input) Number of rows of W and B,
n(input) Number of columns of W and B, and number of elements of vector y
y(input) Double precision vector with the sum of H rows
B(input) Double precision input matrix (1D column-major)
W(inout) Double precision input/output matrix (1D column-major)

Definition at line 1503 of file bdiv_cpu.c.

◆ sbdiv_cpu()

int sbdiv_cpu ( const int  m,
const int  n,
const int  k,
const float *  A,
float *  W,
float *  H,
const float  beta,
const int  uType,
const int  nIter 
)

Definition at line 1089 of file bdiv_cpu.c.

◆ sbdivg_cpu()

int sbdivg_cpu ( const int  m,
const int  n,
const int  k,
const float *  A,
float *  W,
float *  H,
const float  expo,
const int  uType,
int  nIter 
)

sbdivg_cpu performs NNMF using betadivergence for general case (beta <> 1 and 2) using simple precision

Parameters
m(input) Number of rows of matrix A and matrix W
n(input) Number of columns of matrix A and matrix H
k(input) Number of columns of matrix W and rows of H
A(input) Simple precision input matrix of (m * n) number of elements stored using 1D column-major
W(inout) Simple precision input/output matrix of (m * k) number of elements stored using 1D column-major
H(inout) Simple precision input/output matrix of (k * n) number of elements stored using 1D column-major
expo(input) Simple precision value. The exponent beta of betadivergence method
uType(input) It can be UpdateAll (W and H are updated), UpdateW (only H is updated) or UpdateH (only W is updated)
nIter(input) Number of iterations
Returns
: 0 if all is OK, -1 otherwise

Definition at line 313 of file bdiv_cpu.c.

◆ sbdivone_cpu()

int sbdivone_cpu ( const int  m,
const int  n,
const int  k,
const float *  A,
float *  W,
float *  H,
const int  uType,
const int  nIter 
)

sbdivone_cpu performs NNMF using betadivergence when beta=1 using simple precision

Parameters
m(input) Number of rows of matrix A and matrix W
n(input) Number of columns of matrix A and matrix H
k(input) Number of columns of matrix W and rows of H
A(input) Simple precision input matrix of (m * n) number of elements stored using 1D column-major
W(inout) Simple precision input/output matrix of (m * k) number of elements stored using 1D column-major
H(inout) Simple precision input/output matrix of (k * n) number of elements stored using 1D column-major
uType(input) It can be UpdateAll (W and H are updated), UpdateW (only H is updated) or UpdateH (only W is updated)
nIter(input) Number of iterations
Returns
: 0 if all is OK, -1 otherwise

Definition at line 813 of file bdiv_cpu.c.

◆ serrorbd0_x86()

void serrorbd0_x86 ( const int  n,
const float *  x,
float *__restrict__  y 
)

This function performs auxiliar simple precision operations when error is computed using betadivergence error formula and beta = 0.

Parameters
n(input) Number of elements of x and y
x(input) Simple precision input vector/matrix
y(inout) Simple precision input/output vector/matrix

Definition at line 1602 of file bdiv_cpu.c.

◆ serrorbd1_x86()

void serrorbd1_x86 ( const int  n,
const float *  x,
float *__restrict__  y 
)

This function performs auxiliar simple precision operations when error is computed using betadivergence error formula and beta = 1.

Parameters
n(input) Number of elements of x and y
x(input) Simple precision input vector/matrix
y(inout) Simple precision input/output vector/matrix

Definition at line 1668 of file bdiv_cpu.c.

◆ serrorbd_x86()

float serrorbd_x86 ( const int  m,
const int  n,
const int  k,
const float *  A,
const float *  W,
const float *  H,
const float  beta 
)

This function returns simple precision error when error is computed using betadivergence error formula.

Parameters
m(input) Number of rows of A and W
n(input) Number of columns of A and H
k(input) Number of columns/rows of W/H
A(input) Simple precision input matrix A
W(input) Simple precision input matrix W
H(input) Simple precision input matrix H
beta(input) Simple precision beta value

Definition at line 1849 of file bdiv_cpu.c.

◆ serrorbdg_x86()

void serrorbdg_x86 ( const int  n,
const float *  x,
float *__restrict__  y,
const float  beta 
)

This function performs auxiliar simple precision operations when error is computed using betadivergence error formula with (beta != 0) and (beta != 1)

Parameters
n(input) Number of elements of x and y
x(input) Simple precision input vector/matrix
y(inout) Simple precision input/output vector/matrix
beta(input) Simple precision value of beta

Definition at line 1741 of file bdiv_cpu.c.

◆ skernelH_x86()

void skernelH_x86 ( const int  m,
const int  n,
const float *  L,
const float *  A,
float *__restrict__  R,
const float  expo 
)

This function computes simple precision R(i)=(L(i)^expo)*A[i] and R(i+m*n)=L[i]*(L(i)^expo) Note "expo" is a real number expo < 0 or expo > 0.

Parameters
m(input) Number of rows of L, A and R matrices
n(input) Number of columns of L, A and R matrices
L(input) Simpel precision input matrix (1D column-major)
A(input) Simpel precision input matrix (1D column-major)
R(output) Simpel precision output matrix (1D column-major)
expo(input) the "power of" for function pow(). It is a simple precision value

Definition at line 1160 of file bdiv_cpu.c.

◆ skernelW_x86()

void skernelW_x86 ( const int  m,
const int  n,
const float *  L,
const float *  A,
float *__restrict__  R,
const float  expo 
)

This function computes simple precision R(pos)=L(i)^expo)*A(i) and R(pos+m)=L(i)*(L(i)^expo) Note expo is a real number expo < 0 or expo > 0.

Parameters
m(input) Number of rows of A
n(input) Number of columns of A
L(input) Simple precision input matrix (1D column-major)
A(input) Simple precision input matrix (1D column-major)
R(output) Simple precision output matrix (1D column-major)
expo(input) the "power of" for function pow(). It is a simple precision value

Definition at line 1250 of file bdiv_cpu.c.

◆ supdate1H_x86()

void supdate1H_x86 ( const int  n,
const float *  X,
float *__restrict__  H 
)

This function computes simple precision H(i)=H(i)*B(i)/C(i) where matrices B and C are stored in the same buffer (called X). All B 1st and after C.

Parameters
n(input) Number of elements of H
X(input) Simple precision input matrix (1D column-major)
H(inout) Simple precision input/output matrix (1D column-major)

Definition at line 1325 of file bdiv_cpu.c.

◆ supdate1W_x86()

void supdate1W_x86 ( const int  m,
const int  n,
const float *  X,
float *__restrict__  W 
)

This function computes double precision W[i]=W[i]*D[i]/E[i] where matrices D and E are stored in the same buffer (called X) according beta-divergence general case (see dbdivg_x86(...))

Parameters
m(input) Number of rows of W
n(input) Number of columns of W
X(input) Simple precision input matrix (1D column-major)
W(inout) Simple precision input/output matrix (1D column-major)

Definition at line 1397 of file bdiv_cpu.c.

◆ supdate2H_x86()

void supdate2H_x86 ( const int  m,
const int  n,
const float *  y,
const float *  B,
float *__restrict__  H 
)

This function performs the simple H(i)=H(i)*(B(i)/y(j))

Parameters
m(input) Number of rows of B and H, and number of elements of vector y
n(input) Number of columns of B and A
y(input) Simple precision vector with the sum of W columns
B(input) Simple precision input matrix (1D column-major)
H(inout) Simple precision input/output matrix (1D column-major)

Definition at line 1469 of file bdiv_cpu.c.

◆ supdate2W_x86()

void supdate2W_x86 ( const int  m,
const int  n,
const float *  y,
const float *  B,
float *__restrict__  W 
)

This function computes simple precision W(i)=W(i)*(B(i)/y(j))

Parameters
m(input) Number of rows of W and B,
n(input) Number of columns of W and B, and number of elements of vector y
y(input) Simple precision vector with the sum of H rows
B(input) Simple precision input matrix (1D column-major)
W(inout) Simple precision input/output matrix (1D column-major)

Definition at line 1537 of file bdiv_cpu.c.