Skip to content

Commit 238cb8a

Browse files
committed
function isCovMat moved to directory statistics
1 parent c9fa31f commit 238cb8a

File tree

6 files changed

+68
-28
lines changed

6 files changed

+68
-28
lines changed

src/greasepad.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ HEADERS += \
7070
statistics/chisquared.h \
7171
statistics/exponential.h \
7272
statistics/gamma.h \
73+
statistics/iscov.h \
7374
statistics/normal.h \
7475
statistics/prob.h \
7576
statistics/uniform.h \

src/statistics/iscov.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3+
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
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
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU 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, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef ISCOV_H
20+
#define ISCOV_H
21+
22+
23+
#include <Eigen/Core>
24+
#include <Eigen/Eigenvalues>
25+
26+
27+
namespace Stats {
28+
29+
using Eigen::MatrixXd;
30+
31+
32+
//! Check if matrix MM is a proper covariance matrix
33+
[[maybe_unused, nodiscard]] static bool isCovMat( const MatrixXd & MM )
34+
{
35+
// qDebug() << Q_FUNC_INFO;
36+
const Eigen::SelfAdjointEigenSolver<MatrixXd> eig( MM, Eigen::ComputeEigenvectors);
37+
Eigen::VectorXcd ev = eig.eigenvalues();
38+
39+
constexpr double threshold = 1e-6;
40+
#ifdef QT_DEBUG
41+
if ( (ev.real().array() < -threshold ).any() ) {
42+
for ( Eigen::Index i=0; i< ev.size(); i++) {
43+
qDebug().noquote() << QStringLiteral( "(%1,%2)")
44+
.arg( ev(i).real() )
45+
.arg( ev(i).imag() );
46+
}
47+
}
48+
#endif
49+
50+
return ( ev.real().array() >= -threshold ).all();
51+
}
52+
53+
} // namespace Stats
54+
55+
#endif // ISCOV_H

src/uncertain.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -16,10 +16,9 @@
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "uncertain.h"
20-
#include "qlogging.h"
2119

2220
#include "matfun.h"
21+
#include "uncertain.h"
2322
#include "usegment.h"
2423

2524
#include <QDebug>
@@ -31,31 +30,13 @@
3130
#include <Eigen/Core>
3231
#include <Eigen/Eigenvalues>
3332

33+
3434
namespace Uncertain {
3535

3636
using Matfun::null;
3737
using Matfun::sign;
3838

3939

40-
//! Check if matrix MM is a proper covariance matrix
41-
bool isCovMat( const MatrixXd & MM )
42-
{
43-
// qDebug() << Q_FUNC_INFO;
44-
const Eigen::SelfAdjointEigenSolver<MatrixXd> eig( MM, Eigen::ComputeEigenvectors);
45-
Eigen::VectorXcd ev = eig.eigenvalues();
46-
47-
#ifdef QT_DEBUG
48-
if ( (ev.real().array() < -DBL_EPSILON ).any() ) {
49-
for ( Eigen::Index i=0; i< ev.size(); i++) {
50-
qDebug().noquote() << QStringLiteral( "(%1,%2)")
51-
.arg( ev(i).real() )
52-
.arg( ev(i).imag() );
53-
}
54-
}
55-
#endif
56-
57-
return (ev.real().array() >= -DBL_EPSILON ).all();
58-
}
5940

6041
//! Spherically normalize the entity
6142
void BasicEntity2D::normalizeSpherical()

src/uncertain.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -38,10 +38,6 @@ using Eigen::Vector3d;
3838
using Geometry::skew;
3939

4040

41-
//! Check if matrix is covariance matrix
42-
bool isCovMat( const Eigen::MatrixXd &MM);
43-
44-
4541
//! Uncertain distance
4642
class uDistance
4743
{

src/upoint.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
#include "matfun.h"
21+
#include "statistics/iscov.h"
2122
#include "uncertain.h"
2223
#include "upoint.h"
2324
#include "ustraightline.h"
@@ -33,10 +34,14 @@
3334
#include <cmath>
3435
#include <cstdlib>
3536

36-
using Matfun::sign;
3737

3838
namespace Uncertain {
3939

40+
using Matfun::sign;
41+
42+
using Stats::isCovMat;
43+
44+
4045
//! Construction of uncertain point via 3-vector x and its covariance matrix
4146
uPoint::uPoint(const Vector3d &x,
4247
const Matrix3d &Sigma_xx)

src/ustraightline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <cmath>
2323

2424
#include "matfun.h"
25+
#include "statistics/iscov.h"
2526
#include "uncertain.h"
2627
#include "upoint.h"
2728
#include "ustraightline.h"
@@ -41,6 +42,7 @@ using Eigen::Vector3d;
4142

4243
using Matfun::sign;
4344

45+
using Stats::isCovMat;
4446

4547
namespace Uncertain {
4648

0 commit comments

Comments
 (0)