ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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::Statistics
32{
43
44template <typename TVector>
45class ITK_TEMPLATE_EXPORT MahalanobisDistanceMetric : public DistanceMetric<TVector>
46{
47public:
53
56 itkOverrideGetNameOfClassMacro(MahalanobisDistanceMetric);
57 itkNewMacro(Self);
61
64
67
69 using CovarianceMatrixType = vnl_matrix<double>;
70
73
75 void
76 SetMean(const MeanVectorType & mean);
77
79 const MeanVectorType &
80 GetMean() const;
81
86 void
88
90 itkGetConstReferenceMacro(Covariance, CovarianceMatrixType);
91
94 void
96
98 itkGetConstReferenceMacro(InverseCovariance, CovarianceMatrixType);
99
103 double
104 Evaluate(const MeasurementVectorType & measurement) const override;
105
107 double
108 Evaluate(const MeasurementVectorType & x1, const MeasurementVectorType & x2) const override;
109
112 itkSetMacro(Epsilon, double);
113 itkGetConstMacro(Epsilon, double);
115 itkSetMacro(DoubleMax, double);
116 itkGetConstMacro(DoubleMax, double);
117
118protected:
120 ~MahalanobisDistanceMetric() override = default;
121 void
122 PrintSelf(std::ostream & os, Indent indent) const override;
123
124private:
126 CovarianceMatrixType m_Covariance{}; // covariance matrix
127
128 // inverse covariance matrix which is automatically calculated
129 // when covariance matrix is set. This speeds up the GetProbability()
131
132 double m_Epsilon{ 1e-100 };
133 double m_DoubleMax{ 1e+20 };
134
135 void
137};
138} // namespace itk::Statistics
139
140#ifndef ITK_MANUAL_INSTANTIATION
141# include "itkMahalanobisDistanceMetric.hxx"
142#endif
143
144#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
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)