gdkrmr / dimRed

A Framework for Dimensionality Reduction in R
https://www.guido-kraemer.com/software/dimred/
GNU General Public License v3.0
73 stars 15 forks source link

NMF fails again #41

Closed gdkrmr closed 2 years ago

gdkrmr commented 5 years ago

no applicable method for 'predict' applied to an object of class "c('NMFfit', 'NMF')" seems like an import problem again.

✖ |  8 1     | NNMF [2.0 s]
────────────────────────────────────────────────────────────────────────────────
test_NNMF.R:68: error: other arguments
no applicable method for 'predict' applied to an object of class "c('NMFfit', 'NMF')"
1: embed(input_trn, "NNMF", seed = 13, nrun = 10, ndim = 3, method = "KL", options = list(.pbackend = NULL)) at /home/gkraemer/progs/R/dimRed/tests/testthat/test_NNMF.R:68
2: embed(input_trn, "NNMF", seed = 13, nrun = 10, ndim = 3, method = "KL", options = list(.pbackend = NULL))
3: .local(.data, ...)
4: do.call(methodObject@fun, args) at /home/gkraemer/progs/R/dimRed/R/embed.R:135
5: (function (data, pars, keep.org.data = TRUE) 
   {
       chckpkg("NMF")
       chckpkg("MASS")
       meta <- data@meta
       orgdata <- if (keep.org.data) 
           data@data
       else NULL
       data <- data@data
       if (!is.matrix(data)) 
           data <- as.matrix(data)
       data <- t(data)
       if (pars$ndim > nrow(data)) 
           stop("`ndim` should be less than the number of columns.", call. = FALSE)
       if (length(pars$method) != 1) 
           stop("only supply one `method`", call. = FALSE)
       args <- list(x = quote(data), rank = pars$ndim, method = pars$method, nrun = pars$nrun, 
           seed = pars$seed)
       if (length(pars$options) > 0) 
           args <- c(args, pars$options)
       nmf_result <- do.call(NMF::nmf, args)
       w <- NMF::basis(nmf_result)
       h <- t(NMF::coef(nmf_result))
       colnames(w) <- paste0("NNMF", 1:ncol(w))
       other.data <- list(w = w)
       colnames(h) <- paste0("NNMF", 1:ncol(h))
       appl <- function(x) {
           appl.meta <- if (inherits(x, "dimRedData")) 
               x@meta
           else data.frame()
           dat <- if (inherits(x, "dimRedData")) 
               x@data
           else x
           if (!is.matrix(dat)) 
               dat <- as.matrix(dat)
           if (ncol(dat) != nrow(w)) 
               stop("x must have the same number of columns ", "as the original data (", 
                   nrow(w), ")", call. = FALSE)
           res <- dat %*% t(MASS::ginv(w))
           colnames(res) <- paste0("NNMF", 1:ncol(res))
           scores <- new("dimRedData", data = res, meta = appl.meta)
           return(scores)
       }
       inv <- function(x) {
           appl.meta <- if (inherits(x, "dimRedData")) 
               x@meta
           else data.frame()
           proj <- if (inherits(x, "dimRedData")) 
               x@data
           else x
           if (ncol(proj) > ncol(w)) 
               stop("x must have less or equal number of dimensions ", "as the original data")
           res <- tcrossprod(proj, w)
           colnames(res) <- colnames(data)
           res <- new("dimRedData", data = res, meta = appl.meta)
           return(res)
       }
       inv <- function(x) {
           appl.meta <- if (inherits(x, "dimRedData")) 
               x@meta
           else data.frame()
           proj <- if (inherits(x, "dimRedData")) 
               x@data
           else x
           if (ncol(proj) > ncol(data)) 
               stop("x must have less or equal number of dimensions ", "as the original data")
           reproj <- proj %*% other.data$H
           reproj <- new("dimRedData", data = reproj, meta = appl.meta)
           return(reproj)
       }
       res <- new("dimRedResult", data = new("dimRedData", data = h, meta = meta), org.data = orgdata, 
           apply = appl, inverse = inv, has.org.data = keep.org.data, has.apply = TRUE, 
           has.inverse = TRUE, method = "NNMF", pars = pars, other.data = other.data)
       return(res)
   })(data = <S4 object of class structure("dimRedData", package = "dimRed")>, keep.org.data = TRUE, 
       pars = structure(list(ndim = 3, method = "KL", nrun = 10, seed = 13, options = structure(list(
           .pbackend = NULL), .Names = ".pbackend")), .Names = c("ndim", "method", "nrun", 
       "seed", "options")))
6: do.call(NMF::nmf, args) at /home/gkraemer/progs/R/dimRed/R/nnmf.R:93
7: (structure(function (x, rank, method, ...) 
   standardGeneric("nmf"), generic = structure("nmf", package = "NMF"), package = "NMF", group = list(), valueClass = character(0), signature = c("x", 
   "rank", "method"), default = `\001NULL\001`, skeleton = (function (x, rank, method, 
       ...) 
   stop("invalid call in method dispatch to 'nmf' (no default method)", domain = NA))(x, 
       rank, method, ...), class = structure("standardGeneric", package = "methods")))(x = data, 
       rank = 3, method = "KL", nrun = 10, seed = 13, .pbackend = NULL)
8: (structure(function (x, rank, method, ...) 
   standardGeneric("nmf"), generic = structure("nmf", package = "NMF"), package = "NMF", group = list(), valueClass = character(0), signature = c("x", 
   "rank", "method"), default = `\001NULL\001`, skeleton = (function (x, rank, method, 
       ...) 
   stop("invalid call in method dispatch to 'nmf' (no default method)", domain = NA))(x, 
       rank, method, ...), class = structure("standardGeneric", package = "methods")))(x = data, 
       rank = 3, method = "KL", nrun = 10, seed = 13, .pbackend = NULL)
9: nmf(x, rank, method = strategy, ...)
10: nmf(x, rank, method = strategy, ...)
...
15: (function (n, RNGobj) 
   {
       if (verbose) {
           if (verbose > 1) {
               cat("\n## Run: ", n, "/", nrun, "\n", sep = "")
           }
           else {
               cat("", n)
           }
       }
       if (verbose > 2) 
           message("# Setting up loop RNG ... ", appendLF = FALSE)
       setRNG(RNGobj, verbose = verbose > 3)
       if (verbose > 2) 
           message("OK")
       if (n == 1 && .checkRandomness) {
           .RNGinit <- getRNG()
       }
       res <- nmf(x, rank, method, nrun = 1, seed = seed, model = model, .options = .options, 
           ...)
       if (n == 1 && .checkRandomness && rng.equal(.RNGinit)) {
           warning("NMF::nmf - You are running multiple non-random NMF runs with a fixed seed", 
               immediate. = TRUE)
       }
       if (!keep.all) {
           resList <- list(residuals = NA, .callback = NULL)
           err <- residuals(res)
           best <- best.static$residuals
           if (is.na(best) || err < best) {
               if (verbose) {
                   if (verbose > 1L) 
                     cat("## Updating best fit [deviance =", err, "]\n", sep = "")
                   else cat("*")
               }
               best.static$fit <<- res
               best.static$residuals <<- err
               resList$residuals <- err
           }
           best.static$consensus <<- best.static$consensus + connectivity(res, no.attrib = TRUE)
           if (!is.null(.callback)) {
               resList$.callback <- tryCatch(.callback(res, n), error = function(e) e)
           }
           res <- resList
       }
       if (opt.gc && n%%opt.gc == 0) {
           if (verbose > 1) 
               message("# Call garbage collection NOW")
           else if (verbose) 
               cat("%")
           gc(verbose = verbose > 3)
       }
       if (verbose > 1) 
           cat("## DONE\n")
       res
   })(dots[[1L]][[1L]], dots[[2L]][[1L]])
16: connectivity(res, no.attrib = TRUE)
17: connectivity(res, no.attrib = TRUE)
18: .local(object, ...)
19: callNextMethod(object = object, what = "samples")
20: eval(call, callEnv)
21: eval(call, callEnv)
22: .nextMethod(object = object, what = "samples")
23: predict(object, ...)
24: predict(object, ...)
─────────────────────────────────────────
gdkrmr commented 5 years ago

travis passes, therefore I will just ignore it for now...

gdkrmr commented 5 years ago

Note: This seems to be related to the tensorflow installation, it disappeared on my computer for a while until I updated all the python dependencies. Now it is back.