我使用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;发布于 2015-09-09 13:05:21
我不知道这个工具箱,但我以前用过这个函数:
http://www.peterkovesi.com/matlabfns/Robust/ransac.m
它没有那么复杂,但工作得很好,处理任意维度也没有问题
https://stackoverflow.com/questions/26621212
复制相似问题