【问题标题】:How to remove outliers?如何去除异常值?
【发布时间】:2013-12-01 15:45:16
【问题描述】:

我有一个矩阵,其第一列为 X,第二列为 Y,第三列为 Z(来自地球的点云)。 它们之间是异常值,即非常向下或非常外部的点(由于系统误差)。 我创建一个距离矩阵并使用以下代码计算每个点到所有其他点的距离:

xl = selected(:,1);
yl = selected(:,2);
zl = selected(:,3);
distanceMatrix = zeros(size(selected,1));
x = [xl(:)'; yl(:)'; zl(:)'];
IP = x' * x;
distanceMatrix = sqrt(bsxfun(@plus, diag(IP), diag(IP)') - 2 * IP);

selectedl 是我的矩阵。并计算每个点的邻居并说:只有 1 或 2 个邻居的点是异常值。 但是:由于我的矩阵太大(考虑矩阵的大小),我的笔记本电脑无法处理(内存不足:4G!)

有没有不计算距离矩阵自动计算异常值的方法、函数或代码?

【问题讨论】:

    标签: matlab matrix distance outliers


    【解决方案1】:

    您的代码可以提高效率。首先,请注意您的x 就是selected'。其次,所有您的代码都可以替换为:

    distanceMatrix = squareform(pdist(selected));
    

    (参见pdistsquareform 的文档)。除了使代码更简单之外,这可能有助于减少内存使用。

    如果内存仍然是个问题,您可能需要分块工作,计算当前块中的点到所有点的距离。您可以使用pdist2pdist 的通用版本,允许两种不同的输入,并且不需要squareform):

    chunkSize = 100; %// use largest value your memory permits; here it is
    %// assumed to divide size(selected,1)
    for ii = chunkSize:chunkSize:size(selected,1)
        ind = ii + (-chunkSize+1:0); %// indices of points in current chunk
        distanceMatrix = pdist2(selected,selected(ind,:)); %// distance from points
        %// in current chunk to all points
    
        %// Decide which points of the current chunk are outliers, based on
        %// computed distanceMatrix
    end
    

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 2021-10-22
      • 2015-03-11
      • 2020-05-25
      相关资源
      最近更新 更多