mlpack 3.4.2
mahalanobis_distance.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
13#define MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
14
15#include <mlpack/prereqs.hpp>
16
17namespace mlpack {
18namespace metric {
19
59template<bool TakeRoot = true>
61{
62 public:
68
75 MahalanobisDistance(const size_t dimensionality) :
76 covariance(arma::eye<arma::mat>(dimensionality, dimensionality)) { }
77
84 MahalanobisDistance(arma::mat covariance) :
85 covariance(std::move(covariance)) { }
86
96 template<typename VecTypeA, typename VecTypeB>
97 double Evaluate(const VecTypeA& a, const VecTypeB& b);
98
104 const arma::mat& Covariance() const { return covariance; }
105
111 arma::mat& Covariance() { return covariance; }
112
114 template<typename Archive>
115 void serialize(Archive& ar, const unsigned int version);
116
117 private:
119 arma::mat covariance;
120};
121
122} // namespace metric
123} // namespace mlpack
124
125#include "mahalanobis_distance_impl.hpp"
126
127#endif
The Mahalanobis distance, which is essentially a stretched Euclidean distance.
MahalanobisDistance()
Initialize the Mahalanobis distance with the empty matrix as covariance.
const arma::mat & Covariance() const
Access the covariance matrix.
MahalanobisDistance(arma::mat covariance)
Initialize the Mahalanobis distance with the given covariance matrix.
void serialize(Archive &ar, const unsigned int version)
Serialize the Mahalanobis distance.
MahalanobisDistance(const size_t dimensionality)
Initialize the Mahalanobis distance with the identity matrix of the given dimensionality.
double Evaluate(const VecTypeA &a, const VecTypeB &b)
Evaluate the distance between the two given points using this Mahalanobis distance.
arma::mat & Covariance()
Modify the covariance matrix.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
Definition: prereqs.hpp:67
The core includes that mlpack expects; standard C++ includes and Armadillo.