7

I am using RANSAC as my robust regression method. I found a neat toolbox here which performs RANSAC by Marco Zuliani. I saw that there are examples for a line and a plane but what if there are many independent variables as in multivariate regression. Is there anyway to modify the code to handle this?

What I tried thus far is modifying the 3D code to handle N dimensions. When I do this I get all the points as inliers and I know that probably is not correct. This is over-fitting the data. Below are the modifications I tired to make.

For test_RANSAC_plane.m I just added more rows to X

For 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;

For 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;
Baker Johnson
  • 253
  • 1
  • 3
  • 13
  • see http://www.csd.uwo.ca/~yuri/Abstracts/ijcv10_pearl-abs.shtml – Shai Oct 29 '14 at 08:31
  • One example shows a three dimensional situation, what happens if you simply try to increase the number of dimensions? Also, please share what you have tried in general so far. – Dennis Jaheruddin Nov 06 '14 at 14:28
  • I have updated the question to include the code thus far. – Baker Johnson Nov 06 '14 at 22:56
  • it is not clear from your question: what is the dimension of each point? how many points do you have to fit? what is your model: is it a linear subspace of lower dimension than the input dimension, or is it a mix of planes in higher dimension? – Shai Nov 10 '14 at 16:38
  • What I am trying to do is make the code more general, so that someone can enter any dimensions of data and get a result. Thus, the dimensions of each point and the number of points to fit is not know beforehand. For the model I was following the original code in that the model was an array with the number of rows equal to the number of dimensions plus one(the constant). This would be the equation of the line that models the inliers. – Baker Johnson Nov 10 '14 at 17:55

1 Answers1

1

I don't know about this toolbox but I have used this function in the past:

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

It's not as sophisticated but works well and has no problem coping with arbitrary dimensionality

gregswiss
  • 1,456
  • 9
  • 20