Debian Codegraph @

external/gsl/gsl_multifit__covar.c

raw symbols SCIP
1 /* multifit/covar.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004, 2007 Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
21 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
22 #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
23 #include "gsl_permutation.h"cxx . . $ `<file>/external/gsl/gsl_permutation.h`/
24 #include "gsl_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
25 #include "gsl_multifit_nlin.h"cxx . . $ `<file>/external/gsl/gsl_multifit_nlin.h`/
26
27 /* Compute the covariance matrix
28
29 cov = inv (J^T J)
30
31 by QRP^T decomposition of J
32 */
33
34 int
35 gsl_multifit_covarcxx . . $ gsl_multifit_covar(2e19bc0961f74fa8). (const gsl_matrixcxx . . $ gsl_matrix# * J, double epsrel, gsl_matrixcxx . . $ gsl_matrix# * covar)
36 {
37 double tolr;
38
39 size_t i, j, k;
40 size_t kmax = 0;
41
42 gsl_matrixcxx . . $ gsl_matrix# * r;
43 gsl_vectorcxx . . $ gsl_vector# * tau;
44 gsl_vectorcxx . . $ gsl_vector# * norm;
45 gsl_permutationcxx . . $ gsl_permutation# * perm;
46
47 size_t m = J->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1., n = J->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2. ;
48
49 if (m < n)
50 {
51 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("Jacobian be rectangular M x N with M >= N", GSL_EBADLEN);
52 }
53
54 if (covar->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1. != covar->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2. || covar->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1. != n)
55 {
56 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("covariance matrix must be square and match second dimension of jacobian", GSL_EBADLEN);
57 }
58
59 r = gsl_matrix_alloccxx . . $ gsl_matrix_alloc(5a4d020b4836594). (m, n);
60 tau = gsl_vector_alloccxx . . $ gsl_vector_alloc(71d9e095f27e8ea9). (n);
61 perm = gsl_permutation_alloccxx . . $ gsl_permutation_alloc(311f4cfee96dd0e3). (n) ;
62 norm = gsl_vector_alloccxx . . $ gsl_vector_alloc(71d9e095f27e8ea9). (n) ;
63
64 {
65 int signum = 0;
66 gsl_matrix_memcpycxx . . $ gsl_matrix_memcpy(2d55a18be0e0c72f). (r, J);
67 gsl_linalg_QRPT_decompcxx . . $ gsl_linalg_QRPT_decomp(d6e1b21eccd765e2). (r, tau, perm, &signum, norm);
68 }
69
70
71 /* Form the inverse of R in the full upper triangle of R */
72
73 tolr = epsrel * fabscxx . . $ fabs(447c67c6676f75c3).(gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5).(r, 0, 0));
74
75 for (k = 0 ; k < n ; k++)
76 {
77 double rkk = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5).(r, k, k);
78
79 if (fabscxx . . $ fabs(447c67c6676f75c3).(rkk) <= tolr)
80 {
81 break;
82 }
83
84 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13).(r, k, k, 1.0/rkk);
85
86 for (j = 0; j < k ; j++)
87 {
88 double t = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5).(r, j, k) / rkk;
89 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (r, j, k, 0.0);
90
91 for (i = 0; i <= j; i++)
92 {
93 double rik = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, i, k);
94 double rij = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, i, j);
95
96 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (r, i, k, rik - t * rij);
97 }
98 }
99 kmax = k;
100 }
101
102 /* Form the full upper triangle of the inverse of R^T R in the full
103 upper triangle of R */
104
105 for (k = 0; k <= kmax ; k++)
106 {
107 for (j = 0; j < k; j++)
108 {
109 double rjk = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, j, k);
110
111 for (i = 0; i <= j ; i++)
112 {
113 double rij = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, i, j);
114 double rik = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, i, k);
115
116 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (r, i, j, rij + rjk * rik);
117 }
118 }
119
120 {
121 double t = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, k, k);
122
123 for (i = 0; i <= k; i++)
124 {
125 double rik = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, i, k);
126
127 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (r, i, k, t * rik);
128 };
129 }
130 }
131
132 /* Form the full lower triangle of the covariance matrix in the
133 strict lower triangle of R and in w */
134
135 for (j = 0 ; j < n ; j++)
136 {
137 size_t pj = gsl_permutation_getcxx . . $ gsl_permutation_get(177a5570f8ac741a). (perm, j);
138
139 for (i = 0; i <= j; i++)
140 {
141 size_t pi = gsl_permutation_getcxx . . $ gsl_permutation_get(177a5570f8ac741a). (perm, i);
142
143 double rij;
144
145 if (j > kmax)
146 {
147 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (r, i, j, 0.0);
148 rij = 0.0 ;
149 }
150 else
151 {
152 rij = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, i, j);
153 }
154
155 if (pi > pj)
156 {
157 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (r, pi, pj, rij);
158 }
159 else if (pi < pj)
160 {
161 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (r, pj, pi, rij);
162 }
163
164 }
165
166 {
167 double rjj = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, j, j);
168 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (covar, pj, pj, rjj);
169 }
170 }
171
172
173 /* symmetrize the covariance matrix */
174
175 for (j = 0 ; j < n ; j++)
176 {
177 for (i = 0; i < j ; i++)
178 {
179 double rji = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (r, j, i);
180
181 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (covar, j, i, rji);
182 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (covar, i, j, rji);
183 }
184 }
185
186 gsl_matrix_freecxx . . $ gsl_matrix_free(ab29a617cccd3636). (r);
187 gsl_permutation_freecxx . . $ gsl_permutation_free(bfe6c130f63679fa). (perm);
188 gsl_vector_freecxx . . $ gsl_vector_free(5d65852ca0326259). (tau);
189 gsl_vector_freecxx . . $ gsl_vector_free(5d65852ca0326259). (norm);
190
191 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
192 }