mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Made the code in chol() more robust to indefinite matrices.
--HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403867
This commit is contained in:
parent
116cf434c6
commit
02cdfcf454
@ -1088,6 +1088,8 @@ convergence:
|
||||
if (A.size() == 0)
|
||||
return L;
|
||||
|
||||
const T eps = std::numeric_limits<T>::epsilon();
|
||||
|
||||
// compute the upper left corner
|
||||
if (A(0,0) > 0)
|
||||
L(0,0) = std::sqrt(A(0,0));
|
||||
@ -1095,10 +1097,10 @@ convergence:
|
||||
// compute the first column
|
||||
for (long r = 1; r < A.nr(); ++r)
|
||||
{
|
||||
if (L(0,0) > 0)
|
||||
if (L(0,0) > eps*A(r,0))
|
||||
L(r,0) = A(r,0)/L(0,0);
|
||||
else
|
||||
L(r,0) = A(r,0);
|
||||
return L;
|
||||
}
|
||||
|
||||
// now compute all the other columns
|
||||
@ -1121,10 +1123,10 @@ convergence:
|
||||
{
|
||||
temp -= L(r,i)*L(c,i);
|
||||
}
|
||||
if (L(c,c) > 0)
|
||||
if (L(c,c) > eps*temp)
|
||||
L(r,c) = temp/L(c,c);
|
||||
else
|
||||
L(r,c) = temp;
|
||||
return L;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,11 @@ namespace
|
||||
type temp;
|
||||
DLIB_TEST_MSG( (temp= max(abs(test.get_l()*trans(test.get_l()) - m))) < eps,temp);
|
||||
|
||||
{
|
||||
matrix<type> mat = chol(m);
|
||||
DLIB_TEST_MSG( (temp= max(abs(mat*trans(mat) - m))) < eps,temp);
|
||||
}
|
||||
|
||||
|
||||
matrix<type> m2;
|
||||
matrix<type,0,1> col;
|
||||
|
Loading…
Reference in New Issue
Block a user