固有線形問題解決(最小二乗など)
Eigen Linear Problem Solving Least Squares
線形システムを解く方法、LU、QR、SVDなどのいくつかの計算分解。
基本的な線形ソリューション
質問:次のように行列形式で記述された連立方程式があるとします。
Ax = b
ここで、A、bは行列、bベクトルは次のようになります。xを解くことを目的とする場合、分解は行列Aの形式と速度と精度の考慮に応じて、さまざまな方法を選択できます。以下は簡単な例です。 。
#include #include using namespace std using namespace Eigen int main() { Matrix3f A Vector3f b A << 1,2,3, 4,5,6, 7,8,10 b << 3, 3, 4 cout << 'Here is the matrix A:
' << A << endl cout << 'Here is the vector b:
' << b << endl Vector3f x = A.colPivHouseholderQr().solve(b) cout << 'The solution is:
' << x << endl }
次のように解決します。
Here is the matrix A: 1 2 3 4 5 6 7 8 10 Here is the vector b: 3 3 4 The solution is: -2 1 1
colPivHouseholderQr()メソッドの例はクラスオブジェクトColPivHouseholderQRを返すため、文を書くことができます
ColPivHouseholderQR dec(A) Vector3f x = dec.solve(b)
ここで、ColPivHouseholderQR QR分解は、さまざまなマトリックスを対象としており、十分に高速です。以下は、いくつかの分解の比較です。
分解 | 方法 | マトリックスの要件 | 速度(中小) | スピード(大) | 正確さ |
---|---|---|---|---|---|
PartialPivLU | partialPivLu() | 可逆 | ++ | ++ | + |
FullPivLU | fullPivLu() | なし | - | --- | +++ |
HouseholderQR | 世帯主Qr() | なし | ++ | ++ | + |
ColPivHouseholderQR | colPivHouseholderQr() | なし | ++ | - | +++ |
FullPivHouseholderQR | fullPivHouseholderQr() | なし | - | --- | +++ |
LLT | lt() | ポジティブ | 明確 | +++ | +++ |
LDLT | ldlt() | 正または負の半定値 | +++ | + | ++ |
JacobiSVD | jacobiSvd() | なし | --- | -------- | +++ |
上記の分解はsolve()メソッドを提供します。たとえば、行列が正の定値である場合、テーブルはLLTを示し、LDLTが適切な選択です。