File: seed-ica.R

package info (click to toggle)
r-cran-nmf 0.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,344 kB
  • sloc: cpp: 680; ansic: 7; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download | duplicates (4)
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
32
33
34
35
36
37
38
39
40
#' @include registry-seed.R
NULL

###% Seeding method: Absolute Independent Component Analysis
###%
###% @author Renaud Gaujoux
###% @creation 17 Jul 2009


###% Seeding method for Nonnegative Matrix Factorization (NMF) algorithms.
###% 
###% @param object An instance of class \code{NMF} to seed
###% @param x The target matrix
###% @param method The method parameter passed to \code{fastICA}. Can either be 'R' or 'C' and
###% tells which implementation of fastICA to use (R code or C code).
###% @param ... extra parameters passed to \code{fastICA}
###% 
###% @return an updated version of \code{object}, where the matrix slots \code{W} and \code{H}
###% are set to the positive part of the IC of \code{x}.
###%  
posICA <- function(object, x, ica.method=c('C', 'R'), ...){
			
	# perform ICA using the fastICA package
	if( !require.quiet('fastICA') )
		stop("Seeding method 'ica' requires package `fastICA` to be installed")
	requireNamespace('fastICA')
	ica.method <- match.arg(ica.method)
	res <- fastICA::fastICA(x, nbasis(object), method=ica.method, ...)
	
	# update the 'NMF' object
	.basis(object) <- pmax(res$S, .Machine$double.eps ); 
	.coef(object) <- pmax(res$A, .Machine$double.eps );	
	
	# return the updated object
	invisible(object)
	
} 

# Register positive ICA
setNMFSeed('ica', posICA, overwrite=TRUE)