24 const std::function<double(
double)>
l1_norm = [](
double term) {
return std::abs(term); };
25 const std::function<double(
double)>
l2_norm = [](
double term) {
return term * term; };
27 const std::map<std::string, std::function<std::unique_ptr<ObjectiveMetric>()>>
metric_factory = {
28 {
"chi2", []() {
return std::make_unique<Chi2Metric>(); }},
29 {
"poisson-like", []() {
return std::make_unique<PoissonLikeMetric>(); }},
30 {
"log", []() {
return std::make_unique<LogMetric>(); }},
31 {
"reldiff", []() {
return std::make_unique<RelativeDifferenceMetric>(); }},
32 {
"rq4", []() {
return std::make_unique<RQ4Metric>(); }}};
39 template <
class U> std::vector<std::string>
keys(
const std::map<std::string, U>& map)
41 std::vector<std::string> result;
42 result.reserve(map.size());
43 for (
auto& item : map)
44 result.push_back(item.first);
67 std::transform(metric.begin(), metric.end(), metric.begin(), ::tolower);
68 std::transform(norm.begin(), norm.end(), norm.begin(), ::tolower);
73 ss <<
"Error in ObjectiveMetricUtils::createMetric: either metric (" << metric
74 <<
") or norm (" << norm <<
") name is unknown.\n";
76 throw std::runtime_error(ss.str());
79 auto result = metric_iter->second();
80 result->setNorm(norm_iter->second);
87 ss <<
"Available metrics:\n";
89 ss <<
"\t" << item <<
"\n";
91 ss <<
"Available norms:\n";
93 ss <<
"\t" << item <<
"\n";
Defines ObjectiveMetric utilities and corresponding namespace.
Defines ObjectiveMetric classes.
const std::function< double(double)> l2Norm()
Returns L2 normalization function.
std::string defaultMetricName()
Returns default metric name.
std::string defaultNormName()
Returns default norm name.
std::string availableMetricOptions()
Prints available metric options.
std::unique_ptr< ObjectiveMetric > createMetric(const std::string &metric)
Creates the specified metric with the default norm.
std::vector< std::string > metricNames()
Returns the names of the objective metrics used.
const std::function< double(double)> l1Norm()
Returns L1 normalization function.
std::vector< std::string > normNames()
Returns the names of the norms used by ObjectiveMetric.
const std::function< double(double)> l1_norm
const std::string default_metric_name
const std::map< std::string, std::function< std::unique_ptr< ObjectiveMetric >)> > metric_factory
const std::map< std::string, std::function< double(double)> > norm_factory
const std::function< double(double)> l2_norm
const std::string default_norm_name
std::vector< std::string > keys(const std::map< std::string, U > &map)