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;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With