library(cmfrec)
### Generate a small random matrix
n_users <- 10L
n_items <- 8L
k <- 3L
set.seed(1)
X <- matrix(rnorm(n_users*n_items), nrow=n_users)
### Factorize it
model <- CMF(X, k=k, verbose=FALSE, nthreads=1L)
### Now swap the users and items
model.swapped <- swap.users.and.items(model)
### These will now throw the same result
### (up to numerical precision)
item_factors(model, X[, 1])
factors_single(model.swapped, X[, 1])
### Swapping it again restores the original
model.restored <- swap.users.and.items(model.swapped)
### These will throw the same result
topN(model, user=2, n=3)
topN(model.restored, user=2, n=3)
Run the code above in your browser using DataLab