MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / UdUfactor_variant1

Function UdUfactor_variant1

bayes/src/UdU.cpp:193–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191
192
193RowMatrix::value_type UdUfactor_variant1 (RowMatrix& M, std::size_t n)
194/* In place Modified upper triangular Cholesky factor of a
195 * Positive definite or semi-definite matrix M
196 * Reference: A+G p.218 Upper Cholesky algorithm modified for UdU'
197 * Numerical stability may not be as good as M(k,i) is updated from previous results
198 * Algorithm has poor locality of reference and avoided for large matrices
199 * Infinity values on the diagonal can be factorised
200 *
201 * Strict lower triangle of M is ignored in computation
202 *
203 * Input: M, n=last std::size_t to be included in factorisation
204 * Output: M as UdU' factor
205 * strict_upper_triangle(M) = strict_upper_triangle(U)
206 * diagonal(M) = d
207 * strict_lower_triangle(M) is unmodified
208 * Return:
209 * reciprocal condition number, -1 if negative, 0 if semi-definite (including zero)
210 */
211{
212 std::size_t i,j,k;
213 RowMatrix::value_type e, d;
214
215 if (n > 0)
216 {
217 j = n-1;
218 do {
219 d = M(j,j);
220
221 // Diagonal element
222 if (d > 0)
223 { // Positive definite
224 d = 1 / d;
225
226 for (i = 0; i < j; ++i)
227 {
228 e = M(i,j);
229 M(i,j) = d*e;
230 for (k = 0; k <= i; ++k)
231 {
232 RowMatrix::Row Mk(M,k);
233 Mk[i] -= e*Mk[j];
234 }
235 }
236 }
237 else if (d == 0)
238 { // Possibly semi-definite, check not negative
239 for (i = 0; i < j; ++i)
240 {
241 if (M(i,j) != 0)
242 goto Negative;
243 }
244 }
245 else
246 { // Negative
247 goto Negative;
248 }
249 } while (j-- > 0);
250 }

Callers 1

Calls 2

rcond_internalFunction · 0.85
diagFunction · 0.85

Tested by

no test coverage detected