Vespucci  1.0.0
distancemetricwrapper.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
21 
27  : metric_description_(metric_description)
28 {
29  std::set<std::string> valid_types = {"euclidean",
30  "squaredeuclidean",
31  "manhattan",
32  "chebyshev",
33  "cosine",
34  "correlation"};
35  if (!valid_types.count(metric_description))
36  throw std::invalid_argument("Unsupported metric type " + metric_description);
37 }
38 
47 double Vespucci::Math::DistanceMetricWrapper::Evaluate(arma::vec &first, arma::vec &second)
48 {
49  if (metric_description_ == "squaredeuclidean")
50  return squared_euclidean_.Evaluate(first, second);
51  if (metric_description_ == "manhattan")
52  return manhattan_.Evaluate(first, second);
53  if (metric_description_ == "chebyshev")
54  return chebyshev_.Evaluate(first, second);
55  if (metric_description_ == "cosine")
56  return 1 - arma::norm_dot(first, second);
57  if (metric_description_ == "correlation")
58  return 1 - arma::as_scalar(arma::cor(first, second));
59  if (metric_description_ == "euclidean")
60  return euclidean_.Evaluate(first, second);
61  throw std::runtime_error("Unsupported metric type");
62 }
DistanceMetricWrapper(std::string metric_description)
Vespucci::Math::DistanceMetricWrapper::DistanceMetricWrapper.
double Evaluate(arma::vec &first, arma::vec &second)
Vespucci::Math::DistanceMetricWrapper::Evaluate.