if(interactive()){
# Test data
matdata <- toyModel(model = "NMF")
# Bi-Cross-Validation
BCV <- rep(0, length=5)
names(BCV) <- 2:6
for(j in seq(BCV)){
print(j+1)
BCV[j] <- mean(GabrielNMF(matdata, J=j+1, nx=2, ny=2)$TestRecError)
}
proper.rank <- as.numeric(names(BCV)[which(BCV == min(BCV))])
# NMF
out <- NMF(matdata, J=proper.rank)
}
Run the code above in your browser using DataLab