20 #ifndef GAIA_FROZENLINEARCOMBINATIONDISTANCE_H 21 #define GAIA_FROZENLINEARCOMBINATIONDISTANCE_H 23 #include "frozendistance.h" 33 validParams <<
"NO_PARAMS_CHECK";
35 if (params.empty())
throw GaiaException(
"Cannot create a linear combination distance with no params...");
37 ParameterMap::const_iterator it = params.constBegin();
38 for (; it != params.constEnd(); ++it) {
40 if (dparams.size() != 3 || !dparams.contains(
"distance") ||
41 !dparams.contains(
"params") || !dparams.contains(
"weight")) {
42 throw GaiaException(
"Params map should contain the following keys (and only those): distance, params, weight");
45 QString dname = dparams[
"distance"].toString().toLower();
46 ParameterMap params = dparams[
"params"].toParameterMap();
47 FrozenDistance* dist = FrozenMetricFactory::create(dname, dataset, params);
49 _dists.push_back(qMakePair((Real)dparams[
"weight"].toDouble(), dist));
54 for (uint i=0; i<_dists.size(); i++)
delete _dists[i].second;
57 void prepare(
const FrozenPoint& query) {
58 for (uint i=0; i<_dists.size(); i++) {
59 _dists[i].second->prepare(query);
63 Real operator()(
int i,
const FrozenPoint& query)
const {
64 Real result = _dists[0].first * (*_dists[0].second)(i, query);
65 for (uint j=1; j<_dists.size(); j++) {
66 result += _dists[j].first * (*_dists[j].second)(i, query);
72 std::vector<QPair<Real, FrozenDistance*> > _dists;
79 #endif // GAIA_FROZENLINEARCOMBINATIONDISTANCE_H Definition: frozendistance.h:33
Definition: frozenlinearcombinationdistance.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