zdebruine / RcppML

Rcpp Machine Learning: Fast robust NMF, divisive clustering, and more
GNU General Public License v2.0
89 stars 15 forks source link

Initialization #30

Closed ludvigla closed 2 years ago

ludvigla commented 2 years ago

Hi there,

Thanks for an excellent R package!

I was wondering if you have any plan to implement an option to leverage user specified initial matrices for the nmf similar to the nnmf function in this package?

Cheers, Ludvig

zdebruine commented 2 years ago

Hi Ludvig,

This feature is available in the development version of RcppML available on GitHub. Use the seed argument in the nmf function to specify the initial matrix. Note that you can only specify the initial w matrix, because the h matrix is computed from w during the first iteration and so there is no sense in seeding h (not in the NNLM package either).

devtools::install_github("zdebruine/RcppSparse")
devtools::install_github("zdebruine/RcppML")
library(RcppML)
library(Matrix)
A <- rsparsematrix(100, 100, 0.1)
w_init <- matrix(runif(100*10), 100, 10)
nmf_model <- RcppML::nmf(A, k = 10, seed = w_init)

You can also specify a list of initial matrices.

Hopefully I will be able to migrate this feature to the CRAN version soon.

Best, Zach

ludvigla commented 2 years ago

Fantastic Zach, thanks!

I will try it right away :-)