ITK  6.0.0
Insight Toolkit
itkMahalanobisDistanceMetric.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkMahalanobisDistanceMetric_h
19#define itkMahalanobisDistanceMetric_h
20
21#include "vnl/vnl_vector.h"
22#include "vnl/vnl_vector_ref.h"
23#include "vnl/vnl_transpose.h"
24#include "vnl/vnl_matrix.h"
25#include "vnl/algo/vnl_matrix_inverse.h"
26#include "vnl/algo/vnl_determinant.h"
27#include "itkArray.h"
28
29#include "itkDistanceMetric.h"
30
31namespace itk
32{
33namespace Statistics
34{
46template <typename TVector>
47class ITK_TEMPLATE_EXPORT MahalanobisDistanceMetric : public DistanceMetric<TVector>
48{
49public:
55
57 itkOverrideGetNameOfClassMacro(MahalanobisDistanceMetric);
58 itkNewMacro(Self);
62 using typename Superclass::MeasurementVectorType;
63
65 using typename Superclass::MeasurementVectorSizeType;
66
68 using MeanVectorType = typename Superclass::OriginType;
69
71 using CovarianceMatrixType = vnl_matrix<double>;
72
75
77 void
78 SetMean(const MeanVectorType & mean);
79
81 const MeanVectorType &
82 GetMean() const;
83
88 void
90
92 itkGetConstReferenceMacro(Covariance, CovarianceMatrixType);
93
96 void
98
100 itkGetConstReferenceMacro(InverseCovariance, CovarianceMatrixType);
101
105 double
106 Evaluate(const MeasurementVectorType & measurement) const override;
107
109 double
110 Evaluate(const MeasurementVectorType & x1, const MeasurementVectorType & x2) const override;
111
113 itkSetMacro(Epsilon, double);
114 itkGetConstMacro(Epsilon, double);
117 itkSetMacro(DoubleMax, double);
118 itkGetConstMacro(DoubleMax, double);
119
120protected:
122 ~MahalanobisDistanceMetric() override = default;
123 void
124 PrintSelf(std::ostream & os, Indent indent) const override;
125
126private:
127 MeanVectorType m_Mean{}; // mean
128 CovarianceMatrixType m_Covariance{}; // covariance matrix
129
130 // inverse covariance matrix which is automatically calculated
131 // when covariance matrix is set. This speeds up the GetProbability()
132 CovarianceMatrixType m_InverseCovariance{};
133
134 double m_Epsilon{ 1e-100 };
135 double m_DoubleMax{ 1e+20 };
136
137 void
139};
140} // end of namespace Statistics
141} // end namespace itk
142
143#ifndef ITK_MANUAL_INSTANTIATION
144# include "itkMahalanobisDistanceMetric.hxx"
145#endif
146
147#endif
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
this class declares common interfaces for distance functions.
MahalanobisDistanceMetric class computes a Mahalanobis distance given a mean and covariance.
void SetInverseCovariance(const CovarianceMatrixType &invcov)
const MeanVectorType & GetMean() const
void SetMeasurementVectorSize(MeasurementVectorSizeType) override
void PrintSelf(std::ostream &os, Indent indent) const override
void SetCovariance(const CovarianceMatrixType &cov)
double Evaluate(const MeasurementVectorType &x1, const MeasurementVectorType &x2) const override
double Evaluate(const MeasurementVectorType &measurement) const override
void SetMean(const MeanVectorType &mean)
static constexpr double e
Definition: itkMath.h:56
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....