Bak*_*son 7 matlab regression ransac
我使用RANSAC作为我强大的回归方法.我在这里找到了一个整洁的工具箱,由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;
Run Code Online (Sandbox Code Playgroud)
用于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;
Run Code Online (Sandbox Code Playgroud)
我不知道这个工具箱,但我过去使用过这个功能:
http://www.peterkovesi.com/matlabfns/Robust/ransac.m
它并不复杂,但运行良好,并且在处理任意维度时没有问题
| 归档时间: |
|
| 查看次数: |
908 次 |
| 最近记录: |