无法找到具有相同内在尺寸的两个矩阵(W和H)的点产物
我正在进行R中的矩阵 a 的非负矩阵分解(NMF)。它在列上的行和样品上具有基因。对于NMF,我正在使用 cran package nmf
。一旦计算出基础矩阵 w 和系数矩阵 h ,我想检查分解是否足够准确。为此,我试图计算 w 和 h 的点产物,以便检查我是否可以将原始矩阵 a 回到返回。
尽管基矩阵 w 和系数矩阵 h 的内部维度相同(rank = 3)
,但我不能乘它们。我不断遇到以下错误。这一行错误不是很有帮助。
Error in x * y : non-conformable arrays
可再现的代码
# Make a 10 * 10 matrix
ranVal= sample(1:10,100,replace =T)
M=matrix(ranVal,nrow=10)
# Rename the rows and columns
rownames(M) <- paste(rep("gene", 10),c(1:10), sep = "_")
colnames(M) <- paste(rep("sample", 10),c(1:10), sep = "_")
# See how it looks
M
# NMF
library(NMF)
tempRes <- nmf(x = M, rank = 3, .options = c("pv"))
# NMF implementation from Brunet et al. (2004)
result <- nmf_update.brunet_R(i = 1, v = M, x = tempRes, eps=.Machine$double.eps)
# Basis Matrix
W <- .basis(result);
# Coeff Matrix
H <- .coef(result)
# Checking dimensions
dim(W)
dim(H)
# Dot product
A <- W*H # Error: non-conformable arrays
A <- geometry::dot(W,H) # Error: non-conformable arrays
我应该如何处理?有其他检查方法吗?谢谢!
I am doing Non-Negative Matrix Factorization (NMF) of a matrix A in R. It has Genes on rows and Samples on the columns. For NMF, I am using the CRAN package NMF
. Once the basis matrix W and coefficient matrix H are computed, I want to check whether the factorisation was accurate enough. For that, I am trying to calculate the dot product of W and H so as to check whether I can get the original matrix A back.
Although the inner dimensions of basis matrix W and coefficient matrix H are same (rank = 3)
, I cannot multiply them. I keep getting the following error. This one line error is not very helpful.
Error in x * y : non-conformable arrays
Reproducible code
# Make a 10 * 10 matrix
ranVal= sample(1:10,100,replace =T)
M=matrix(ranVal,nrow=10)
# Rename the rows and columns
rownames(M) <- paste(rep("gene", 10),c(1:10), sep = "_")
colnames(M) <- paste(rep("sample", 10),c(1:10), sep = "_")
# See how it looks
M
# NMF
library(NMF)
tempRes <- nmf(x = M, rank = 3, .options = c("pv"))
# NMF implementation from Brunet et al. (2004)
result <- nmf_update.brunet_R(i = 1, v = M, x = tempRes, eps=.Machine$double.eps)
# Basis Matrix
W <- .basis(result);
# Coeff Matrix
H <- .coef(result)
# Checking dimensions
dim(W)
dim(H)
# Dot product
A <- W*H # Error: non-conformable arrays
A <- geometry::dot(W,H) # Error: non-conformable arrays
How should I go about it? Is there a different way to check it? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
w%*%h
呢?What about
W %*% H
?