Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

非負の線形最小二乗法、ソルバーベース

この例では、いくつかのアルゴリズムを使用して、解が非負となる範囲制約のある、線形最小二乗問題を解く方法を説明します。線形最小二乗問題は、次の形式をとります。

minxCx-d2.

この場合、解が非負 x0 となるように制約します。

はじめに、配列 C および d をワークスペースに読み込みます。

load particle

各配列のサイズを表示します。

sizec = size(C)
sizec = 1×2

        2000         400

sized = size(d)
sized = 1×2

        2000           1

C は 2,000 行 400 列の行列です。したがって、行列乗算に適したサイズにするために、x ベクトルの行数は 400 行となります。非負の制約を表すには、すべての変数の下限をゼロに設定します。

lb = zeros(size(C,2),1);

lsqlin を使用して、問題を解きます。

[x,resnorm,residual,exitflag,output] = ...
    lsqlin(C,d,[],[],[],[],lb);
Minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.

最適化プロセスの詳細を確認するには、出力構造体を検証します。

disp(output)
            message: 'Minimum found that satisfies the constraints....'
          algorithm: 'interior-point'
      firstorderopt: 3.6717e-06
    constrviolation: 0
         iterations: 8
       linearsolver: 'sparse'
       cgiterations: []

この出力構造体は、lsqlin が内点法アルゴリズムの内部的な線形ソルバーとしてスパースを使用し、反復を 8 回実行して、1 次の最適性の尺度が約 3.7e-6 に到達したことを示しています。

アルゴリズムの変更

信頼領域 Reflective 法アルゴリズムは、範囲制約付き問題を扱います。次の問題に対して、うまく機能することを確認します。

options = optimoptions('lsqlin','Algorithm','trust-region-reflective');
[x2,resnorm2,residual2,exitflag2,output2] = ...
    lsqlin(C,d,[],[],[],[],lb,[],[],options);
Local minimum possible.

lsqlin stopped because the relative change in function value is less than the square root of the function tolerance and the rate of change in the function value is slow.
disp(output2)
         iterations: 10
          algorithm: 'trust-region-reflective'
      firstorderopt: 2.7870e-05
       cgiterations: 42
    constrviolation: []
       linearsolver: []
            message: 'Local minimum possible....'

このとき、ソルバーは反復回数を増やし、1 次の最適性の尺度がより高い (悪い) 解に到達します。

1 次の最適性の尺度を改善するには、SubproblemAlgorithm オプションを 'factorization' に設定して試します。

options.SubproblemAlgorithm = 'factorization';
[x3,resnorm3,residual3,exitflag3,output3] = ...
    lsqlin(C,d,[],[],[],[],lb,[],[],options);
Optimal solution found.
disp(output3)
         iterations: 12
          algorithm: 'trust-region-reflective'
      firstorderopt: 5.5907e-15
       cgiterations: 0
    constrviolation: []
       linearsolver: []
            message: 'Optimal solution found.'

このオプションを使用することにより、1 次の最適性の尺度はほぼゼロになります。これは最良の結果です。

ソルバーの変更

lsqnonneg ソルバーを使用して問題を解いてみましょう。このソルバーは、非負の線形最小二乗法を処理するよう設計されています。

[x4,resnorm4,residual4,exitflag4,output4] = lsqnonneg(C,d);
disp(output4)
    iterations: 184
     algorithm: 'active-set'
       message: 'Optimization terminated.'

lsqnonneg は 1 次の最適性の尺度を報告しません。代わりに、残差ノルムを調査します。下位の有効数字を確認するには、各残差ノルムから 22.5794 を減算します。

t = table(resnorm - 22.5794, resnorm2 - 22.5794, resnorm3 - 22.5794, resnorm4 - 22.5794,...
    'VariableNames',{'default','trust-region-reflective','factorization','lsqnonneg'})
t=1×4 table
     default      trust-region-reflective    factorization    lsqnonneg 
    __________    _______________________    _____________    __________

    7.5411e-05          4.9186e-05            4.9179e-05      4.9179e-05

既定の lsqlin アルゴリズムは、trust-region-reflective アルゴリズムよりも高い残差ノルムをもちます。factorization および lsqnonneg 残差ノルムはさらに低く、このレベルの表示精度では同一になります。どちらが低いかを確認します。

disp(resnorm3 - resnorm4)
   6.7857e-13

量の違いは無視できるレベルであるため、lsqnonneg 残差ノルムは最小値となります。しかし、lsqnonneg は、収束までの反復回数が最大です。

参考

|

関連するトピック