poismf_unsafe: Poisson factorization with no input casting

Description Usage Arguments Value See Also Examples

Description

This is a faster version of poismf which will not make any checks or castings on its inputs. It is intended as a fast alternative when a model is to be fit multiple times with different hyperparameters, and for allowing custom-initialized factor matrices. Note that since it doesn't make any checks or conversions, passing the wrong kinds of inputs or passing inputs with mismatching dimensions will crash the R process.

For most use cases, it's recommended to use the function 'poismf' instead.

Usage

1
poismf_unsafe(A, B, Xcsr, Xcsc, k, ...)

Arguments

A

Initial values for the user-factor matrix of dimensions [dimA, k], assuming row-major order. Can be passed as a vector of dimension [dimA*k], or as a matrix of dimension [k, dimA]. Note that R matrices use column-major order, so if you want to pass an R matrix as initial values, you'll need to transpose it, hence the shape [k, dimA]. Recommended to initialize '~ Gamma(1,1)'. Will be modified in-place.

B

Initial values for the item-factor matrix of dimensions [dimB, k]. See documentation about 'A' for more details.

Xcsr

The transpose of the 'X' matrix in CSC format (so that its structure would match a CSR matrix). Should be an object of class 'Matrix::dgCMatrix'.

Xcsc

The 'X' matrix in CSC format. Should be an object of class 'Matrix::dgCMatrix'.

k

The number of latent factors. Must match with the dimension of 'A' and 'B'.

...

Other hyperparameters that can be passed to 'poismf'. See the documentation for poismf for details about possible hyperparameters. Init type and seed are ignored as the 'A' and 'B' matrices are supposed to be passed already-initialized.

Value

A 'poismf' model object. See the documentation for poismf for details.

See Also

poismf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
library(poismf)

### create a random sparse data frame in COO format
nrow <- 10^2 ## <- users
ncol <- 10^3 ## <- items
nnz  <- 10^4 ## <- events (agg)
set.seed(1)
X <- data.frame(
        row_ix = sample(nrow, size=nnz, replace=TRUE),
        col_ix = sample(ncol, size=nnz, replace=TRUE),
        count  = rpois(nnz, 1) + 1
     )
X <- X[!duplicated(X[, c("row_ix", "col_ix")]), ]

### convert to required format
Xcsr <- Matrix::sparseMatrix(
            i=X$col_ix, j=X$row_ix, x=X$count,
            repr="C"
)
Xcsc <- Matrix::sparseMatrix(
            i=X$row_ix, j=X$col_ix, x=X$count,
            repr="C"
)

### initialize factor matrices
k <- 5L
A <- rgamma(nrow*k, 1, 1)
B <- rgamma(ncol*k, 1, 1)

### call function
model <- poismf_unsafe(A, B, Xcsr, Xcsc, k, nthreads=1)

poismf documentation built on Jan. 13, 2021, 6:46 a.m.

Related to poismf_unsafe in poismf...