MLPACK  1.0.8
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.8.
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 t_take_root = 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 
96  template<typename VecType1, typename VecType2>
97  double Evaluate(const VecType1& a, const VecType2& b);
98 
104  const arma::mat& Covariance() const { return covariance; }
105 
111  arma::mat& Covariance() { return covariance; }
112 
113  private:
115  arma::mat covariance;
116 };
117 
118 }; // namespace distance
119 }; // namespace mlpack
120 
121 #include "mahalanobis_distance_impl.hpp"
122 
123 #endif
double Evaluate(const VecType1 &a, const VecType2 &b)
Evaluate the distance between the two given points using this 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.
arma::mat covariance
The covariance matrix associated with this distance.
MahalanobisDistance()
Initialize the Mahalanobis distance with the empty matrix as covariance.
MahalanobisDistance(const size_t dimensionality)
Initialize the Mahalanobis distance with the identity matrix of the given dimensionality.
The Mahalanobis distance, which is essentially a stretched Euclidean distance.