Open sureshgorakala opened 8 years ago
You can plug the complete algorithm (loop, stopping criteria) or use the built-in iterative framework.
# define the complete algorithm
my_objective_function <- function(x, R, alpha, beta, ...){
# distance/objective function
P <- basis(x); Q <- t(coef(x))
sum((R - P %*% t(Q))^2) + alpha * sum(abs(P)) + beta * sum(Q^2)
}
algo <- function(R, x, alpha = 1, beta = 10){
# iterative loop
n <- 0
while(TRUE){
# update basis (P) and coefficient (t(Q)) matrix
coef(x) <- coef(x) %*% (alpha * diag(runif(ncol(x))))
basis(x) <- basis(x) %*% (beta * diag(runif(nbasis(x))))
if( n>100 || my_objective_function(x, R, alpha, beta) < .5 ) break
n <- n + 1
}
x
}
x <- rmatrix(20, 10)
nmf(x, 2, algo, alpha = 1, beta = 10, .opt = 'v', objective = my_objective_function)
# Or use the built-in iterative framework
algo_iter <- NMFStrategy('test', objective = my_objective_function,
Update = function(i, R, x, alpha, beta, ...){
# update basis (P) and coefficient (t(Q)) matrix
coef(x) <- coef(x) %*% (alpha * diag(runif(ncol(x))))
basis(x) <- basis(x) %*% (beta * diag(runif(nbasis(x))))
x
}, Stop = function(algo, i, R, x, ...){
# use step 0 to initialize local static variable if necessary
if( i == 0L ) return(FALSE)
# here random stopping criteria
runif(1, max = 100) > 99
}
)
nmf(x, 2, algo_iter, alpha = 1, beta = 10, .opt = 'v')
Thank you Renozao for the response., will try it and get back to you.
HI Renozao, just for confirmation, did the above equation doesn't contain the regularised part containing similarity calculation in the above equation?
The code I sent is a toy example, showing how you can can define your own algorithm, with a specific objective function. I only tried to use the notations from the paper you sent. You need to implement the right equations there.
sureshgorakala have you finished work on 2 level matrix factorization? I have been working on it. But I have find it difficult in some places? will you please help me in this regard?
Hi Renozao,
I'm working on recommender systems using matrix factorization methods, recently I come across below paper: https://opus.lib.uts.edu.au/bitstream/10453/37442/4/Two%20level%20Matrix%20Factorization.pdf
My objective is to integrate item attributes to the rating matrix which is explained in the above paper. I need your guidance to modify the objective function in NMF package to address the below objective function: