.Internal(La_rs())在某些安装中返回负值,但在其他安装中不返回 [英] .Internal(La_rs()) returns negative values on some installations but not others
问题描述
这是上一个问题的延续: Rfast hd.eigen()返回NA,但基本特征( )不
This is a continuation from a previous question: Rfast hd.eigen() returns NAs but base eigen() does not
.Internal(La_rs((x))
在不同的计算机上返回不同的结果时遇到了问题.
I have been having a problem with .Internal(La_rs((x))
returning different results on different machines.
我怀疑这可能与数字格式有关,因为在同一台计算机上,如果我另存为CSV并重新打开,则不会再出现底片了:
I suspect it may have something to do with number formatting, because on the same machine, if I save as a CSV and re-open, I don't get negatives anymore:
在Clear Linux上安装:
On Clear Linux install:
> load("input_to_La_rs.Rdata")
> r <- .Internal(La_rs(as.matrix(x), only.values = FALSE))
> sum(r$values < 0)
[1] 1
> write.csv(x, "test_for_internal.csv", row.names = FALSE)
> x <- read.csv("test_for_internal.csv")
> r <- .Internal(La_rs(as.matrix(x), only.values = FALSE))
> sum(r$values < 0)
[1] 0
但是,在Windows安装(以及基于CentOS的HPC设置)上,我可以直接打开rdata文件,而不会得到负值:
However on my Windows install (and on a CentOS based HPC setup), I can open the rdata file directly and don't get negative values:
> load("input_to_La_rs.Rdata")
> r <- .Internal(La_rs(x, only.values=TRUE))
> sum(r$values < 0)
[1] 0
这与不同的R版本/库版本有关吗?我不知道的某些设置?一个错误?
Is this related to different R builds/library versions? Some setting I don't know about? A bug?
这是一个更新的示例.即使在这个特定的安装上,它似乎也不一致,有时候我确实得到了零:
here is an updated example. It seems to work inconsistently, even on the this particular install, sometimes I do get zero:
set.seed(123)
bigm <- matrix(rnorm(2000*2000,mean=0,sd = 3), 2000, 2000)
m <- Rfast::colmeans(bigm)
y <- t(bigm) - m
xx <- crossprod(y)
x <- unname(as.matrix(xx))
b <- .Internal(La_rs(x, TRUE))
sum(b$values < 0)
# [1] 1
又一次更新:事实证明,第一个差异随着Rfast
的colmeans
蔓延,产生的结果与基本colMeans略有不同.
Yet another update: It turns out that the first difference creeps in with Rfast
's colmeans
producing slightly different results than base colMeans.
set.seed(123)
bigm <- matrix(rnorm(2000*2000,mean=0,sd = 3), 2000, 2000)
m <- colMeans(bigm)
m <- colmeans(bigm)
y <- t(bigm) - m
xx <- crossprod(y)
x <- unname(as.matrix(xx))
b <- .Internal(La_rs(x, TRUE))
sum(b$values < 0)
# [1] 1
m <- colMeans(bigm)
y <- t(bigm) - m
xx <- crossprod(y)
x <- unname(as.matrix(xx))
b <- .Internal(La_rs(x, TRUE))
sum(b$values < 0)
推荐答案
Rfast中的hd.eigen函数仅适用于n< p,即行数少于列数时.在hd.eigen函数的帮助页面中,提供了建议该算法的论文的参考.我认为该算法不适用于任何其他情况.也许这就是为什么您获得NA的原因.
The hd.eigen function in Rfast works only, only for the case of n < p, i.e. when the rows are less than the columns. In the help page of the hd.eigen function is the reference to the paper that suggested this algorithm. The algorithm I do not think works for any other case. Perhaps that is why you get NAs.
Rfast2包含一个称为"pca"的函数,该函数可在两种情况下(np)工作.也尝试一下.在其中,有效地执行了SVD,从R调用"svd".
Rfast2 contains a function called "pca" that works for either case, np. Try that one also. Inside there, an SVD is effectively performed calling "svd" from R.
这篇关于.Internal(La_rs())在某些安装中返回负值,但在其他安装中不返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!