本文介绍了矩阵计算误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R工具计算SVD(svd(m)),它适用于小型矩阵,但是当我将其传递给20Kx20X矩阵时.处理后,出现以下错误

I am using R tool to calculate SVD (svd(m)) and it works on small matrix but as I pass it 20Kx20X matrix. After processing, it gives the following error

Error in svd(m) : infinite or missing values in 'x'

我检查了,没有行或列的值全部为0,并且在行和列中没有重复项柱子.所有列都有值.

I checked and there is no row or column with all 0 values and no duplicate in row andcolumn. All columns have values.

我不能在这里过去20Kx20K矩阵:(

I cannot past 20Kx20K matrix here :(

推荐答案

我猜测您的问题与内存大小无关,尽管我无法在4GB内存计算机上处​​理20Kx20K矩阵.

I am guessing that your problem is not related to memory size, although I am not able to process a 20Kx20K matrix on my 4GB memory machine.

进行此猜测的原因是svd()中的第一行代码如下:

The reason for this guess is that the first line of code inside svd() is the following:

if (any(!is.finite(x)))
    stop("infinite or missing values in 'x'")

换句话说,svd()函数首先测试数据中是否有任何个无限值.

In other words, the svd() function test first whether there are any infinite values in your data.

之前发生这种情况.因此,如果您遇到内存问题,即使在调用svd()之前,这些问题也会很明显.

This happens before any further processing. So, if you had memory problems, these would be apparent even before your call to svd().

我建议您检查无限值:

x <- c(0, Inf, NA, NULL)
which(!is.finite(x))

[1] 2 3

这表示第二个和第三个值被认为不是有限的.换句话说,数据中的任何 NA值都将导致您的错误.

This indicates that the second and third values are considered to be not finite. In other words, any NA values in your data will cause your error.

这篇关于矩阵计算误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 04:26