R中的不一致数组错误

时间:2014-06-13 03:32:11

标签: arrays r matrix

numberofusers=75000
numberofitems=65000
number.of.factors=10
# N is a numberofusers*numberofitems sparse Matrix (loaded from a dataset).
#X,Y matrices are already available and have dimensions 
#     (numberofusers,number.of.factors) and 
#(numberofitems,number.of.factors) respectively

ptempuser<-rep(0,numberofitems)
tempuser<-rep(0,numberofitems)
Y.big<-t(Y)%*%Y
for (i in 1:numberofusers) {
   matrixproduct1 <- matrix(0,numberofitems,number.of.factors)
   nonzerolistforthatuser <- which(N[i,]!=0)
   tempuser[nonzerolistforthatuser] <- alpha*N[i,nonzerolistforthatuser]
   ptempuser[nonzerolistforthatuser] <- 1
   matrixproduct1[nonzerolistforthatuser,]   <-tempuser[nonzerolistforthatuser]*Y[nonzerolistforthatuser,]
   finalproductmatrix1 <- matrix(0,number.of.factors,number.of.factors)
   finalproductmatrix1 <- t(Y)[,nonzerolistforthatuser] %*% matrixproduct1[nonzerolistforthatuser,]
   tempuser <- 1+tempuser
   matrixproduct2 <- t(Y)
   matrixproduct2[,nonzerolistforthatuser] <- t(Y)[,nonzerolistforthatuser]*tempuser[nonzerolistforthatuser]

   Agen<-Y.big + finalproductmatrix1
   dim1<-dim(Y.big)
   dim2<-dim(finalproductmatrix1)
   if(dim1[1]!=dim2[1]){
     print(i)
     print(dim1[1])
     print(dim2[1])
    }
   if(dim1[2]!=dim2[2]){
     print(i)
     print(dim1[2])
     print(dim2[2])
     } 

   finalproductmatrix2 <- matrixproduct2[,nonzerolistforthatuser] %*% cbind(ptempuser[nonzerolistforthatuser])
   X[i,] <- (ginv(Y.big+finalproductmatrix1+diag(rep(lambda,number.of.factors))))%*%(finalproductmatrix2)  
}

我得到错误为Y.big + finalproductmatrix1中的错误:不一致的数组&#39; 。但我甚至尝试在函数内部执行Agen&lt; -Y.big + final productmatrix1,这没有问题。所以尺寸肯定不会引起问题。我仍然不顺从。 请告诉我该怎么办。我被困在这几个小时。我还检查了尺寸条件,但没有显示打印结果。所以我很困惑。

0 个答案:

没有答案