zdebruine/RcppML

how to check the top features in each rank?

ruiye88 opened this issue · 2 comments

Hi Zach,

Thank you for implementing this great package for fast NMF. Just wondering is there a similar function like the extracFeatures from the original nmf package that allows us to quickly get the top fetures from each rank? Thanks!

Best,
Rui

Hi Rui,

You can do this using some basic R functions. Here's a working example if you're using the development version:

library(RcppML)
data(hawaiibirds)
nmf_model <- nmf(hawaiibirds$counts, k = 10)

# split the "w" matrix into a list of column vectors
w <- lapply(seq_len(ncol(nmf_model@w)), function(i) nmf_model@w[,i])

# get the top "n" values in each list item
lapply(h, function(x) head(sort(x, decreasing = TRUE), n = 10L))

This is quite well vectorised and should run efficiently. You can also use dplyr and friends to a similar effect.

You may also be able to convert an RcppML::nmf class to an NMF class if you so desire, but my experience is that the NMF package is a bit out of date and does not outperform base R and tidyverse functionality.

Hope this helps! Let me know if you have any other questions!

Zach

Hi Zach,

Tkank you for the quick reply!!

Best,
Rui

Hi Rui,

You can do this using some basic R functions. Here's a working example if you're using the development version:

library(RcppML)
data(hawaiibirds)
nmf_model <- nmf(hawaiibirds$counts, k = 10)

# split the "w" matrix into a list of column vectors
w <- lapply(seq_len(ncol(nmf_model@w)), function(i) nmf_model@w[,i])

# get the top "n" values in each list item
lapply(h, function(x) head(sort(x, decreasing = TRUE), n = 10L))

This is quite well vectorised and should run efficiently. You can also use dplyr and friends to a similar effect.

You may also be able to convert an RcppML::nmf class to an NMF class if you so desire, but my experience is that the NMF package is a bit out of date and does not outperform base R and tidyverse functionality.

Hope this helps! Let me know if you have any other questions!

Zach