renozao / NMF

NMF: A Flexible R package for Nonnegative Matrix Factorization
139 stars 41 forks source link

using my own objective with an existing method #151

Open ChristelSwift opened 4 years ago

ChristelSwift commented 4 years ago

this may be a naive question but is it possible to specify my own objective function using one of the existing methods?

For example, based on the example given in the vignette, let's say i want to use my own objective but instead of my own algorithm, i want to use the method 'snmf/l'. If i run this:

n <- 50 
r <- 3 
p <- 20
V <-syntheticNMF(n, r, p)

V_model <- nmf(V, 3, method = 'snmf/l', 
    objective = function(model, target, ...){
      ( sum( (target-fitted(model))^4 ) )^{1/4}
      }
    )  

it fails as this method already has its own objective baked in.

Can i somehow edit an existing method so i can use my own objective based on the model and fitted objects?