問題ベースの最小二乗法の目的関数の記述
問題ベースの最小二乗法に目的関数を指定するには、目的を二乗和または式のノルムの二乗として明示的に記述します。最小二乗法を明示的に使用することで、問題に対して最適かつ最も効率的なソルバーを取得できます。たとえば、
t = randn(10,1); % Data for the example x = optimvar('x',10); obj = sum((x - t).^2); % Explicit sum of squares prob = optimproblem("Objective",obj); % Check to see the default solver opts = optimoptions(prob)
opts = lsqlin options: ...
また、目的関数を 2 乗ノルムとして記述します。
obj2 = norm(x-t)^2; prob2 = optimproblem("Objective",obj2); % Check to see the default solver opts = optimoptions(prob2)
opts = lsqlin options: ...
これに対し、目的を数学的に等価な式として表すと、ソフトウェアはその問題を一般的な二次問題として解釈します。
obj3 = (x - t)'*(x - t); % Equivalent to a sum of squares, % but not interpreted as a sum of squares prob3 = optimproblem("Objective",obj3); % Check to see the default solver opts = optimoptions(prob3)
opts = quadprog options: ...
同様に、非線形最小二乗法をノルムの二乗または最適化式の明示的な二乗和として記述します。次の目的関数は、明示的な二乗和です。
t = linspace(0,5); % Data for the example A = optimvar('A'); r = optimvar('r'); expr = A*exp(r*t); ydata = 3*exp(-2*t) + 0.1*randn(size(t)); obj4 = sum((expr - ydata).^2); % Explicit sum of squares prob4 = optimproblem("Objective",obj4); % Check to see the default solver opts = optimoptions(prob4)
opts = lsqnonlin options: ...
また、目的関数を 2 乗ノルムとして記述します。
obj5 = norm(expr - ydata)^2; % norm squared prob5 = optimproblem("Objective",obj5); % Check to see the default solver opts = optimoptions(prob5)
opts = lsqnonlin options: ...
ソフトウェアが最小二乗問題として解釈する最も一般的な形式は、ノルムの二乗または次の形式の式 Rn の和です。
en は任意の式です。多次元の場合、en は
.^2
を使用して項ごとに 2 乗する必要があります。an はスカラー数値です。
kj は正のスカラー数値です。
各式 Rn は、多次元の値ではなく、スカラーとして評価しなければなりません。たとえば、
x = optimvar('x',10,3,4); y = optimvar('y',10,2); t = randn(10,3,4); % Data for example u = randn(10,2); % Data for example a = randn; % Coefficient k = abs(randn(5,1)); % Positive coefficients % Explicit sums of squares: R1 = a + k(1)*sum(k(2)*sum(k(3)*sum((x - t).^2,3))); R2 = k(4)*sum(k(5)*sum((y - u).^2,2)); R3 = 1 + cos(x(1))^2; prob = optimproblem('Objective',R1 + R2 + R3); options = optimoptions(prob)
options = lsqnonlin options: ...