rnnmf

Regularize Non-Negative Matrix Factorization

https://github.com/shabbychef/rnnmf

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.2%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Regularize Non-Negative Matrix Factorization

Basic Info
  • Host: GitHub
  • Owner: shabbychef
  • License: lgpl-3.0
  • Language: R
  • Default Branch: main
  • Size: 335 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created almost 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.Rmd

```{r setup,include=FALSE}
library(ggplot2)

theme_set(theme_minimal(base_size=12))
theme_update(legend.position="bottom")

if (require(viridis,quietly=TRUE)) {
  scale_colour_discrete <- function(...) {
    require(viridis,quietly=TRUE)
    scale_color_viridis(discrete=TRUE,end=0.85,option='D',...)
  }
  scale_fill_discrete <- function(...) {
    require(viridis,quietly=TRUE)
    scale_fill_viridis(discrete=TRUE,end=0.85,option='D',...)
  }
  # wait, can I also default for continuous cases?
  scale_colour_continuous <- function(...) {
    require(viridis,quietly=TRUE)
    scale_color_viridis(discrete=FALSE,end=0.85,option='D',...)
  }
  scale_fill_continuous <- function(...) {
    require(viridis,quietly=TRUE)
    scale_fill_viridis(discrete=FALSE,end=0.85,option='D',...)
  }
}

# set the knitr options ... for everyone!
# if you unset this, then vignette build bonks. oh, joy.
#opts_knit$set(progress=TRUE)
opts_knit$set(eval.after='fig.cap')
# for a package vignette, you do want to echo.
# opts_chunk$set(echo=FALSE,warning=FALSE,message=FALSE)
opts_chunk$set(warning=FALSE,message=FALSE)
#opts_chunk$set(results="asis")
opts_chunk$set(cache=TRUE,cache.path="cache/")

#opts_chunk$set(fig.path="github_extra/figure/",dev=c("pdf","cairo_ps"))
#opts_chunk$set(fig.path="github_extra/figure/",dev=c("png","pdf"))
opts_chunk$set(fig.path="tools/figure/",dev=c("png"))
opts_chunk$set(fig.width=7,fig.height=6,dpi=100,out.width='700px',out.height='600px')

# doing this means that png files are made of figures;
# the savings is small, and it looks like shit:
#opts_chunk$set(fig.path="figure/",dev=c("png","pdf","cairo_ps"))
#opts_chunk$set(fig.width=4,fig.height=4)
# for figures? this is sweave-specific?
#opts_knit$set(eps=TRUE)

# this would be for figures:
#opts_chunk$set(out.width='.8\\textwidth')
# for text wrapping:
options(width=64,digits=2)
opts_chunk$set(size="small")
opts_chunk$set(tidy=TRUE,tidy.opts=list(width.cutoff=50,keep.blank.line=TRUE))

#rnnmf.meta <- packageDescription('rnnmf')
```

# rnnmf

```{r ignore,include=FALSE,eval=FALSE}
# [![Build Status](https://github.com/shabbychef/rnnmf/workflows/R-CMD-check/badge.svg)](https://github.com/shabbychef/rnnmf/actions)
# [![codecov.io](http://codecov.io/github/shabbychef/rnnmf/coverage.svg?branch=master)](http://codecov.io/github/shabbychef/rnnmf?branch=master)
# [![CRAN](http://www.r-pkg.org/badges/version/rnnmf)](https://cran.r-project.org/package=rnnmf)
# [![Downloads](http://cranlogs.r-pkg.org/badges/rnnmf?color=green)](http://www.r-pkg.org/pkg/rnnmf)
# [![Total](http://cranlogs.r-pkg.org/badges/grand-total/rnnmf?color=green)](http://www.r-pkg.org/pkg/rnnmf)
```

Implements regularized non-negative matrix factorization by a method similar to 
Lee & Seung, "Algorithms for Non-negative Matrix Factorization," 2001.

-- Steven E. Pav, shabbychef@gmail.com

## Installation

This package may be installed from CRAN; the latest version may be
found on [github](https://github.com/shabbychef/rnnmf "rnnmf")
via devtools, or installed via [drat](https://github.com/eddelbuettel/drat "drat"):

```{r install,eval=FALSE,echo=TRUE}
# CRAN
install.packages(c('rnnmf'))
# devtools
if (require(devtools)) {
	# latest greatest
	install_github('shabbychef/rnnmf')
}
# via drat:
if (require(drat)) {
	drat:::add('shabbychef')
	# not yet:
	# install.packages('rnnmf')
}
```

# What is it?

Non-negative matrix factorization is a tool for decomposing a non-negative
matrix $Y$ approximately as $Y \approx L R$ for non-negative matrices $L, R$ of
pre-specified rank.
This package provides code for non-negative matrix factorization with penalty
terms for the $\ell_1$ and $\ell_2$ norms of the two factors, as well as
for non-orthogonality of the factors.
The code is based on the conceptually simple multiplicative update of 
[Lee & Seung](http://papers.nips.cc/paper/2861-algorithms-for-non-negative-matrix-factorization.pdf).
An additive update based on the same ideas is also given.

This code is provided mostly for research purposes, and no warranty is given
regarding speed, or convergence.

# Basic Usage

We demonstrate the usage of the multiplicative and additive updates in
factoring a small matrix which we constructed to be the product of two
reduced rank non-negative matrices.

```{r basic_simulations,cache=TRUE,eval=TRUE,echo=TRUE,dpi=200,out.width='600px',out.height='500px'}
library(dplyr)
library(rnnmf)
library(ggplot2)

frobenius_norm_err <- function(Y, L, R) {
	sqrt(sum(abs(Y - L %*% R)^2))
}
runifmat <- function(nr,nc,...) {
	matrix(pmax(0,runif(nr*nc,...)),nrow=nr)
}
test_a_bunch <- function(Y_t, L_0, R_0, niter=1e4L) {
	iter_hist <- new.env()
	iter_hist[['history']] <- rep(NA_real_, niter)

	on_iteration_end <- function(iteration, Y, L, R, ...) {
		iter_hist[['history']][iteration] <<- frobenius_norm_err(Y,L,R)
	}
	wuz <- aurnmf(Y_t, L_0, R_0, max_iterations=niter, on_iteration_end=on_iteration_end)
	df1 <- tibble(x=seq_along(iter_hist[['history']]),y=iter_hist[['history']]) %>% mutate(method='additive, optimal step')

	iter_hist[['history']] <- rep(NA_real_, niter)
	wuz <- murnmf(Y_t, L_0, R_0, max_iterations=niter, on_iteration_end=on_iteration_end)
	df2 <- tibble(x=seq_along(iter_hist[['history']]),y=iter_hist[['history']]) %>% mutate(method='multiplicative')

	retv <- bind_rows(df1,df2) %>%
		mutate(nr=nrow(Y_t),
					 nc=ncol(Y_t),
					 nd=ncol(L_0),
					 max_iter=niter)
	return(retv)
}

nr <- 30
nc <- 8
nd <- 3
set.seed(1234)
L_t <- runifmat(nr,nd)
R_t <- runifmat(nd,nc)
Y_t <- L_t %*% R_t

L_0 <- runifmat(nrow(Y_t),nd+1)
R_0 <- runifmat(ncol(L_0),ncol(Y_t))

test_a_bunch(Y_t, L_0, R_0, niter=1e4L) %>%
	ggplot(aes(x,y,color=method)) + 
	geom_line() + 
	scale_x_log10(labels=scales::comma) + scale_y_log10() +
	labs(x='Step',y=expression(L[2]~~Error),
			 title='Frobenius Norm of Error vs Step',color='Method',
			 caption=paste0('Factoring ',nr,' x ',nc,' matrix down to ',nd,' dimensions.'))


```


## See also

* Lee, Daniel D. and Seung, H. Sebastian. [Algorithms for Non-negative Matrix Factorization](http://papers.nips.cc/paper/1861-algorithms-for-non-negative-matrix-factorization.pdf), 2001.
* Pav, Steven E. [System and method for unmixing spectroscopic observations with nonnegative matrix factorization](https://patentscope.wipo.int/search/en/detail.jsf?docId=US42758160), 2012.

Owner

  • Name: Steven Pav
  • Login: shabbychef
  • Kind: user

GitHub Events

Total
  • Push event: 4
Last Year
  • Push event: 4

Packages

  • Total packages: 1
  • Total downloads:
    • cran 486 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: rnnmf

Regularized Non-Negative Matrix Factorization

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 486 Last month
Rankings
Dependent packages count: 27.8%
Dependent repos count: 34.3%
Average: 49.7%
Downloads: 87.0%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.0.2 depends
  • matrixcalc * imports
  • cocktailApp * suggests
  • knitr * suggests
  • testthat * suggests