Y = X Aという行列式において、YとXが分かっている状態で、Aを推定する問題を考えます。このXに対してQR分解を行い、QR分解で得られたQとRとYを使いAを求めます。この最小二乗法では、 R * A = QT * Yを計算します。但し、Qの右上のTは転置を意味します。まず、QT * Yを求め、後退代入によりAの値を計算します。そのプログラムは、最小二乗法(正規方程式、逆行列、QR分解)で公開しています。そのプログラムは本に掲載されているくらいですから、とても洗練されたものだと思います。しかし、私のようなプログラミングが得意ではない人間にとっては、プログラムの中でどれがQでどれがRで、R * A = QT * Yの計算がどう行われているのかが少し分かり難いと感じました。そこで、ここではQとRをはっきりと示しながら、R * A = QT * Yの計算がより分かるようなプログラムを公開します。solve_A_using_QR.cで、その計算を行っています。main.c に solve_A_using_QR( y, Q, R, A ) が加えられています。
In the determinant Y = X A, we consider the problem of estimating A when Y and X are known. The QR decomposition is performed on this X and A is estimated using Q, R and Y where Q and R are obtained from the QR decomposition. In the least-squares method, the value of A is calculated using R * A = QT * Y, where the T in the upper right-hand corner of Q means transposition. First, QT * Y is obtained and the value of A is calculated by backward substitution. The programme is disclosed in least square method (normal equation, inverse matrix and QR decomposition). I think that the program is very sophisticated, as it is published in the book. However, as I am not good at programming, I feel that it is a little difficult to understand which is Q and which is R, and how the calculation of R * A = QT * Y is performed in the program. So, I disclose a program that clearly shows Q and R and makes it easier to understand the calculation of R * A = QT * Y on this page. The calculation is performed in solve_A_using_QR.c and solve_A_using_QR( y, Q, R, A ) is added to main.c.
programme
main.c contains the main function.
-----------------------------------------------
number of rows: 3
number of columns: 2
DELTA: 1e-20
-----------------------------------------------
A0: 1.0000000000
A1: 2.0000000000
-----------------------------------------------