关于LM写的不错的文章:
https://blog.csdn.net/a6333230/article/details/83304098
三维重构PMP论文中使用的信赖域算法(LM)matlab版,修改在标定中可用
function [G, val] = rect_rot(G, A, d)
% Rectify rotations
%
% G: Rectifying transform
% A, d: Coefficients for orthonormality constraint
% val: Value of residual error
ik = size(G, 1);
ikk = numel(G);
k = ikk/ik;
Id = eye(ik);
IdG = eye(ikk);
% Parameters for trust-region optimization
delta = 1;
eta1 = 1/4;
eta2 = 3/4;
kappa = 2;
epsilon = 1e-3;
% Trust-region strategy
f = A*reshape(G*G', [], 1)-d;
c = norm(f)^2;
pc = inf;
while pc-c > 1e-10
pG = G;
pf = f;
pc = c;
J = A*kron(G, Id)+reshape(permute(reshape(A*kron(Id, G), [], k, ik), [1 3 2]), [], ikk);
H = J'*J;
g = J'*f;
while true
temp = H+IdG*delta;
r = (temp+trace(temp)*1e-10*IdG)\g;
G(:) = G(:)-r;
f = A*reshape(G*G', [], 1)-d;
c = norm(f)^2;
rho = (pc-c)/(pc-norm(pf-J*r)^2);
rho(isnan(rho)) = 0;
if rho < eta1 || pc < c
delta = delta*kappa;
elseif rho > eta2
delta = delta/kappa;
end
if rho < epsilon || pc < c
G = pG;
if delta > 1e10
c = pc;
break;
end
else
break;
end
end
end
val = mse(f);
end