首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RANSAC多元回归

RANSAC多元回归
EN

Stack Overflow用户
提问于 2014-10-29 09:06:43
回答 1查看 1.1K关注 0票数 7

我使用RANSAC作为我的稳健回归方法。我找到了一个简洁的工具箱here,它执行Marco Zuliani的RANSAC。我看到有直线和平面的例子,但如果有许多自变量,就像多元回归一样。有没有办法修改代码来处理这个问题?

到目前为止,我尝试的是修改3D代码来处理N维。当我这样做的时候,我得到了所有的积分,我知道这可能是不正确的。这是对数据的过度拟合。下面是我想要做的修改。

对于test_RANSAC_plane.m,我只是在X中添加了更多行

对于estimate_plane.m

代码语言:javascript
复制
function [Theta, k] = estimate_plane(X, s)
    % cardinality of the MSS
    k = size(X,1);

    if (nargin == 0) || isempty(X)
        Theta = [];
        return;
    end;

    if (nargin == 2) && ~isempty(s)
        X = X(:, s);
    end;

    % check if we have enough points
    N = size(X, 2);
    if (N < k)
        error('estimate_plane:inputError', ...
            'At least k points are required');
    end;

    A = [];
    for i=1:k
        A = [A transpose(X(i, :))];
    end
    A = [A ones(N, 1)];
    [U S V] = svd(A);
    Theta = V(:, k+1);

    return;

对于error_plane.m

代码语言:javascript
复制
function [E T_noise_squared d] = error_plane(Theta, X, sigma, P_inlier)
    % compute the squared error
    E = [];
    k = size(X,1);
    den = 0;

    if ~isempty(Theta) && ~isempty(X)
        for i=1:k
            den = den + Theta(i)^2;
        end

        sum = Theta(1)*X(1,:);
        for j=2:k
            sum = sum + Theta(j)*X(j,:);
        end
        sum = sum + Theta(j+1);
        E = (sum).^2 / den;                 
    end;

    % compute the error threshold
    if (nargout > 1)
        if (P_inlier == 0)
            T_noise_squared = sigma;
        else
            d = k;
            % compute the inverse probability
            T_noise_squared = sigma^2 * chi2inv_LUT(P_inlier, d);
        end; 
    end; 
    return;
EN

回答 1

Stack Overflow用户

发布于 2015-09-09 13:05:21

我不知道这个工具箱,但我以前用过这个函数:

http://www.peterkovesi.com/matlabfns/Robust/ransac.m

它没有那么复杂,但工作得很好,处理任意维度也没有问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26621212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档