MLPACK  1.0.10
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 1.0.10.
8  *
9  * MLPACK is free software: you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation, either version 3 of the License, or (at your option) any
12  * later version.
13  *
14  * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
15  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16  * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  * details (LICENSE.txt).
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * MLPACK. If not, see <http://www.gnu.org/licenses/>.
21  */
22 #ifndef __MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
23 #define __MLPACK_CORE_METRICS_MAHALANOBIS_DISTANCE_HPP
24 
25 #include <mlpack/core.hpp>
26 
27 namespace mlpack {
28 namespace metric {
29 
60 template<bool TakeRoot = false>
62 {
63  public:
69 
76  MahalanobisDistance(const size_t dimensionality) :
77  covariance(arma::eye<arma::mat>(dimensionality, dimensionality)) { }
78 
85  MahalanobisDistance(const arma::mat& covariance) : covariance(covariance) { }
86 
97  // Return String of Object
98  std::string ToString() const;
99  template<typename VecType1, typename VecType2>
100  double Evaluate(const VecType1& a, const VecType2& b);
101 
107  const arma::mat& Covariance() const { return covariance; }
108 
114  arma::mat& Covariance() { return covariance; }
115  private:
117  arma::mat covariance;
118 };
119 
120 }; // namespace distance
121 }; // namespace mlpack
122 
123 #include "mahalanobis_distance_impl.hpp"
124 
125 #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: load.hpp:31
std::string ToString() const
Evaluate the distance between the two given points using this Mahalanobis distance.
MahalanobisDistance()
Initialize the Mahalanobis distance with the empty matrix as covariance.
arma::mat covariance
The covariance matrix associated with this distance.
double Evaluate(const VecType1 &a, const VecType2 &b)
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.
The Mahalanobis distance, which is essentially a stretched Euclidean distance.