双向阵列的r-张量分解



我可以使用rTensor::cp来分解R中的三向数组。然而,在分解双向阵列CCD_ 3时会出现错误。如何分解双向数组?谢谢

cp适用于3路阵列。

library(rTensor)
a <- c(0.1,0.9)
b <- c(0.5,0.5)
c <- c(0.7,0.3)
tnsr <- as.tensor(outer(outer(a,b),c))
cpD <- cp(tnsr, num_components=1)
> $U[[1]]
>      [,1]
> [1,]  0.1
> [2,]  0.9
> $U[[2]]
>      [,1]
> [1,] -0.5
> [2,] -0.5
> $U[[3]]
>      [,1]
> [1,] -0.7
> [2,] -0.3

双向阵列出现错误。

tnsr <- as.tensor(outer(a,b))
cpD <- cp(tnsr, num_components=1)
> Error in L[[i]] : subscript out of bounds

一种解决方法是将2路数组乘以1,使其成为3路数组。

tnsr = as.tensor(outer(outer(a,b),1))
cpD = cp(tnsr, num_components=1)
> $U[[1]]
>      [,1]
> [1,]  0.1
> [2,]  0.9
> $U[[2]]
>      [,1]
> [1,] -0.5
> [2,] -0.5
> $U[[3]]
>      [,1]
> [1,]   -1

最新更新