벡터에 행렬 변환에
덕분에, 당신은 단지 비 - 제로 요소를 유지할 수 있습니다.
# Sample data
n <- 4e6
k <- n
library(Matrix)
I <- spMatrix(n, n, 1:n, 1:n, rep(1,n))
G <- spMatrix(n, n,
sample(1:n, k, replace=TRUE),
sample(1:n, k, replace=TRUE),
sample(0:9, k, replace=TRUE)
)
G2 <- G %*% G
G2 <- as(G2, "dgTMatrix") # For the j slot
# Only keep elements that are non-zero in one of the 3 matrices
i <- as.integer(c([email protected], [email protected], [email protected]) + 1)
j <- as.integer(c([email protected], [email protected], [email protected]) + 1)
ij <- cbind(i,j)
rankMatrix(cbind(G2[ij], G[ij], I[ij])) # 3
# Another example
m <- ceiling(n/2)-1
G <- spMatrix(n, n,
c(1:n, 2*(1:m)),
c(1:n, 2*(1:m)+1),
rep(1, n+m)
)
G2 <- as(G %*% G, "dgTMatrix")
i <- c([email protected], [email protected], [email protected]) + 1
j <- c([email protected], [email protected], [email protected]) + 1
ij <- cbind(i,j)
rankMatrix(cbind(G2[ij], G[ij], I[ij])) # 2
(최대 속도 것들, 당신이 그 벡터의 작은 부분 만 걸릴 수 있습니다 : 그것은이 경우 를 순위 이미 3 인 경우, 당신은 그들이 독립적 인 것을 알고, , 당신은 경우에 확인하실 수 있습니다 선형 의존 관계는 큰 벡터에도 적용됩니다.)
정확히 내가 원했던 것! 정말 고맙습니다 ! – mmgm
ij <- cbind (i, j) 연산에 문제가 있습니다. 일부 행렬에 대해 R은 벡터가 너무 크다고 불평합니다. 어떤 아이디어? – mmgm
인덱스가 정수인 것을 확인하면 메모리 사용량이 줄어들지 만 요소 2만큼 줄어 듭니다. 이는 충분하지 않을 수 있습니다. –