BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ObjectiveMetricUtils Namespace Reference

Functions

const std::function< double(double)> l1Norm ()
 
const std::function< double(double)> l2Norm ()
 
std::unique_ptr< ObjectiveMetriccreateMetric (const std::string &metric)
 
std::unique_ptr< ObjectiveMetriccreateMetric (std::string metric, std::string norm)
 
std::string availableMetricOptions ()
 
std::vector< std::string > normNames ()
 
std::vector< std::string > metricNames ()
 
std::string defaultNormName ()
 
std::string defaultMetricName ()
 

Function Documentation

◆ l1Norm()

const std::function< double(double)> ObjectiveMetricUtils::l1Norm ( )

Returns L1 normalization function.

Definition at line 49 of file ObjectiveMetricUtils.cpp.

50 {
51  return l1_norm;
52 }
const std::function< double(double)> l1_norm

References anonymous_namespace{ObjectiveMetricUtils.cpp}::l1_norm.

◆ l2Norm()

const std::function< double(double)> ObjectiveMetricUtils::l2Norm ( )

Returns L2 normalization function.

Definition at line 54 of file ObjectiveMetricUtils.cpp.

55 {
56  return l2_norm;
57 }
const std::function< double(double)> l2_norm

References anonymous_namespace{ObjectiveMetricUtils.cpp}::l2_norm.

◆ createMetric() [1/2]

std::unique_ptr< ObjectiveMetric > ObjectiveMetricUtils::createMetric ( const std::string &  metric)

Creates the specified metric with the default norm.

Definition at line 59 of file ObjectiveMetricUtils.cpp.

60 {
61  return createMetric(metric, defaultNormName());
62 }
std::string defaultNormName()
Returns default norm name.
std::unique_ptr< ObjectiveMetric > createMetric(const std::string &metric)
Creates the specified metric with the default norm.

References defaultNormName().

Referenced by FitObjective::setObjectiveMetric().

Here is the call graph for this function:

◆ createMetric() [2/2]

std::unique_ptr< ObjectiveMetric > ObjectiveMetricUtils::createMetric ( std::string  metric,
std::string  norm 
)

Creates the metric with the specified norm.

Definition at line 64 of file ObjectiveMetricUtils.cpp.

66 {
67  std::transform(metric.begin(), metric.end(), metric.begin(), ::tolower);
68  std::transform(norm.begin(), norm.end(), norm.begin(), ::tolower);
69  const auto metric_iter = metric_factory.find(metric);
70  const auto norm_iter = norm_factory.find(norm);
71  if (metric_iter == metric_factory.end() || norm_iter == norm_factory.end()) {
72  std::stringstream ss;
73  ss << "Error in ObjectiveMetricUtils::createMetric: either metric (" << metric
74  << ") or norm (" << norm << ") name is unknown.\n";
75  ss << availableMetricOptions();
76  throw std::runtime_error(ss.str());
77  }
78 
79  auto result = metric_iter->second();
80  result->setNorm(norm_iter->second);
81  return result;
82 }
std::string availableMetricOptions()
Prints available metric options.
const std::map< std::string, std::function< std::unique_ptr< ObjectiveMetric >)> > metric_factory
const std::map< std::string, std::function< double(double)> > norm_factory

References availableMetricOptions(), anonymous_namespace{ObjectiveMetricUtils.cpp}::metric_factory, and anonymous_namespace{ObjectiveMetricUtils.cpp}::norm_factory.

Here is the call graph for this function:

◆ availableMetricOptions()

std::string ObjectiveMetricUtils::availableMetricOptions ( )

Prints available metric options.

Definition at line 84 of file ObjectiveMetricUtils.cpp.

85 {
86  std::stringstream ss;
87  ss << "Available metrics:\n";
88  for (auto& item : metricNames())
89  ss << "\t" << item << "\n";
90  ss << "default metric: " << defaultMetricName() << "\n";
91  ss << "Available norms:\n";
92  for (auto& item : normNames())
93  ss << "\t" << item << "\n";
94  ss << "default norm: " << defaultNormName() << "\n";
95  return ss.str();
96 }
std::string defaultMetricName()
Returns default metric name.
std::vector< std::string > metricNames()
Returns the names of the objective metrics used.
std::vector< std::string > normNames()
Returns the names of the norms used by ObjectiveMetric.

References defaultMetricName(), defaultNormName(), metricNames(), and normNames().

Referenced by FitObjective::availableMetricOptions(), and createMetric().

Here is the call graph for this function:

◆ normNames()

std::vector< std::string > ObjectiveMetricUtils::normNames ( )

Returns the names of the norms used by ObjectiveMetric.

Definition at line 98 of file ObjectiveMetricUtils.cpp.

99 {
100  return keys(norm_factory);
101 }
std::vector< std::string > keys(const std::map< std::string, U > &map)

References anonymous_namespace{ObjectiveMetricUtils.cpp}::keys(), and anonymous_namespace{ObjectiveMetricUtils.cpp}::norm_factory.

Referenced by availableMetricOptions().

Here is the call graph for this function:

◆ metricNames()

std::vector< std::string > ObjectiveMetricUtils::metricNames ( )

Returns the names of the objective metrics used.

Definition at line 103 of file ObjectiveMetricUtils.cpp.

104 {
105  return keys(metric_factory);
106 }

References anonymous_namespace{ObjectiveMetricUtils.cpp}::keys(), and anonymous_namespace{ObjectiveMetricUtils.cpp}::metric_factory.

Referenced by availableMetricOptions().

Here is the call graph for this function:

◆ defaultNormName()

std::string ObjectiveMetricUtils::defaultNormName ( )

◆ defaultMetricName()

std::string ObjectiveMetricUtils::defaultMetricName ( )

Returns default metric name.

Definition at line 113 of file ObjectiveMetricUtils.cpp.

114 {
115  return default_metric_name;
116 }

References anonymous_namespace{ObjectiveMetricUtils.cpp}::default_metric_name.

Referenced by availableMetricOptions().