mlpack  2.0.1
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  * This file is part of mlpack 2.0.1.
8  *
9  * mlpack is free software; you may redstribute it and/or modify it under the
10  * terms of the 3-clause BSD license. You should have received a copy of the
11  * 3-clause BSD license along with mlpack. If not, see
12  * http://www.opensource.org/licenses/BSD-3-Clause for more information.
13  */
14 #ifndef __MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
15 #define __MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
16 
17 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 namespace metric {
21 
54 template<bool TakeRoot = true>
56 {
57  public:
63 
70  MahalanobisDistance(const size_t dimensionality) :
71  covariance(arma::eye<arma::mat>(dimensionality, dimensionality)) { }
72 
79  MahalanobisDistance(const arma::mat& covariance) : covariance(covariance) { }
80 
90  template<typename VecTypeA, typename VecTypeB>
91  double Evaluate(const VecTypeA& a, const VecTypeB& b);
92 
98  const arma::mat& Covariance() const { return covariance; }
99 
105  arma::mat& Covariance() { return covariance; }
106 
108  template<typename Archive>
109  void Serialize(Archive& ar, const unsigned int version);
110 
111  private:
113  arma::mat covariance;
114 };
115 
116 } // namespace distance
117 } // namespace mlpack
118 
119 #include "mahalanobis_distance_impl.hpp"
120 
121 #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.
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.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
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.