mlpack  master
mahalanobis_distance.hpp
Go to the documentation of this file.
1 /***
2  * @file mahalanobis_dstance.h
3  * @author Ryan Curtin
4  *
5  * The Mahalanobis distance.
6  *
7  * mlpack is free software; you may redistribute it and/or modify it under the
8  * terms of the 3-clause BSD license. You should have received a copy of the
9  * 3-clause BSD license along with mlpack. If not, see
10  * http://www.opensource.org/licenses/BSD-3-Clause for more information.
11  */
12 #ifndef MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
13 #define MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace metric {
19 
52 template<bool TakeRoot = true>
54 {
55  public:
61 
68  MahalanobisDistance(const size_t dimensionality) :
69  covariance(arma::eye<arma::mat>(dimensionality, dimensionality)) { }
70 
77  MahalanobisDistance(const arma::mat& covariance) : covariance(covariance) { }
78 
88  template<typename VecTypeA, typename VecTypeB>
89  double Evaluate(const VecTypeA& a, const VecTypeB& b);
90 
96  const arma::mat& Covariance() const { return covariance; }
97 
103  arma::mat& Covariance() { return covariance; }
104 
106  template<typename Archive>
107  void Serialize(Archive& ar, const unsigned int version);
108 
109  private:
111  arma::mat covariance;
112 };
113 
114 } // namespace distance
115 } // namespace mlpack
116 
117 #include "mahalanobis_distance_impl.hpp"
118 
119 #endif
MahalanobisDistance(const size_t dimensionality)
Initialize the Mahalanobis distance with the identity matrix of the given dimensionality.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
MahalanobisDistance()
Initialize the Mahalanobis distance with the empty matrix as covariance.
arma::mat covariance
The covariance matrix associated with this distance.
void Serialize(Archive &ar, const unsigned int version)
Serialize the Mahalanobis distance.
const arma::mat & Covariance() const
Access the covariance matrix.
MahalanobisDistance(const arma::mat &covariance)
Initialize the Mahalanobis distance with the given covariance matrix.
arma::mat & Covariance()
Modify the covariance matrix.
double Evaluate(const VecTypeA &a, const VecTypeB &b)
Evaluate the distance between the two given points using this Mahalanobis distance.
The Mahalanobis distance, which is essentially a stretched Euclidean distance.