堅牢な回帰手法として RANSAC を使用しています。ここで、Marco Zuliani による RANSAC を実行するきちんとしたツールボックスを見つけました。線と平面の例があるのを見ましたが、多変量回帰のように多くの独立変数がある場合はどうでしょうか。これを処理するためにコードを変更する方法はありますか?
これまでに試したことは、N 次元を処理するように 3D コードを変更することです。これを行うと、すべてのポイントがインライアとして取得され、おそらく正しくないことがわかります。これはデータの過適合です。以下は、私が行うのに疲れた変更です。
行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;