RANSAC多元回归

时间:2014-10-29 01:06:43

标签: matlab regression ransac

我使用RANSAC作为我强大的回归方法。我找到了一个整洁的工具箱here,由Marco Zuliani执行RANSAC。我看到有一个线和一个平面的例子但是如果在多元回归中存在许多自变量会怎么样呢。反正有没有修改代码来处理这个?

到目前为止,我尝试修改3D代码以处理N维。当我这样做时,我得到所有的点作为内点,我知道可能是不正确的。这是过度拟合数据。以下是我厌倦的修改。

对于test_RANSAC_plane.m我刚添加了更多行X

estimate_plane.m

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

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;

0 个答案:

没有答案
相关问题