认为,学算法,打印下来,一个一个看是最直观的,本来准备把NMF,每个函数都注解一遍,结果今天自己没事,看了下,乍一看一大片,用一个旁观者的视角看,我并不想继续读下去。所以代码给大家。因为实验室有打印机,我打印看,很快就知道什么流程了,纸上谈兵,上战场就~~~各种弱爆,想想就想哭。(不知道链接是不是一直有效,如果失效在Functional Biogeography of Ocean Microbes Revealedthrough Non-Negative Matrix Factorization 这篇文章里面)
# Non-negative matrix factorization
## Args:
# difcon: indicates how difference between the similarity matrice in two iteration.
#too small, in many times it has not convergenced in 2000 steps
#too large, because it convergenced in 200 steps
#may try to see results on 1e-5,-6,-7,-8,-9,-10, to see if it is sensentive on convergence criteria
#非负矩阵分解
##参数:
#difcon:表示两次迭代中相似度矩阵之间的差异。
#too很小,在很多时候它还没有在2000步骤收敛
#too很大,因为它收敛了200步
#可能试图在1e-5,-6,-7,-8,-9,-10上看到结果,看它是否是敏感的在收敛准则上
#参数含义 Z:为输入矩阵; K:为准备分类的个数; method = "lee":表示选用第一个提出NMF分解lee作者的基于欧式距离来分解; num.iter = 2000:迭代次数; seed = 10:初始化种子编号
NMF <- function(Z, k, method = "lee", eps = 1e-16, stopconv = 40, num.iter = 2000, difcon = 1e-10, ifseed = TRUE, seed = 10) {
n <- nrow(Z) #输入矩阵Z的行数