Gaia
frozenexponentialcompressdistance.h
1 /*
2  * Copyright (C) 2006-2013 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Gaia
5  *
6  * Gaia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef GAIA_FROZENEXPONENTIALCOMPRESSDISTANCE_H
21 #define GAIA_FROZENEXPONENTIALCOMPRESSDISTANCE_H
22 
23 #include "frozendistance.h"
24 
25 namespace gaia2 {
26 
27 
29 public:
30  FrozenExponentialCompressDistance(const FrozenDataSet& dataset, const ParameterMap& params)
31  : FrozenDistance(dataset) {
32 
33  validParams << "distance" << "params" << "alpha";
34 
35  if (params.empty()) throw GaiaException("Cannot create an exponential compress distance with no params...");
36 
37  QString dname = params["distance"].toString().toLower();
38  ParameterMap dparams = params["params"].toParameterMap();
39 
40  _dist = FrozenMetricFactory::create(dname, dataset, dparams);
41  _alpha = params.value("alpha", 1.0).toDouble();
42 
43  }
44 
46  delete _dist;
47  }
48 
49  void prepare(const FrozenPoint& query) {
50  _dist->prepare(query);
51  }
52 
53  Real operator()(int i, const FrozenPoint& query) const {
54  return 1 - exp(-_alpha * (*_dist)(i, query));
55  }
56 
57 protected:
58  FrozenDistance* _dist;
59  Real _alpha;
60 };
61 
62 
63 
64 } // namespace gaia2
65 
66 #endif // GAIA_FROZENEXPONENTIALCOMPRESSDISTANCE_H
Definition: frozendistance.h:33
Definition: frozenexponentialcompressdistance.h:28
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
Definition: parameter.h:34
A FrozenDataSet is a dataset that has been flagged as immutable.
Definition: frozendataset.h:49
Exception class that can take up to 3 arguments of any type, which will be serialized into a QString ...
Definition: gaiaexception.h:46