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

Utility functions related to class ObjectiveMetric. More...

Functions

std::string availableMetricOptions ()
 Prints available metric options. More...
 
std::unique_ptr< ObjectiveMetriccreateMetric (const std::string &metric)
 Creates the specified metric with the default norm. More...
 
std::unique_ptr< ObjectiveMetriccreateMetric (std::string metric, std::string norm)
 Creates the metric with the specified norm. More...
 
std::string defaultMetricName ()
 Returns default metric name. More...
 
std::string defaultNormName ()
 Returns default norm name. More...
 
const std::function< double(double)> l1Norm ()
 Returns L1 normalization function. More...
 
const std::function< double(double)> l2Norm ()
 Returns L2 normalization function. More...
 
std::vector< std::string > metricNames ()
 Returns the names of the objective metrics used. More...
 
std::vector< std::string > normNames ()
 Returns the names of the norms used by ObjectiveMetric. More...
 

Detailed Description

Utility functions related to class ObjectiveMetric.

Function Documentation

◆ availableMetricOptions()

std::string ObjectiveMetricUtils::availableMetricOptions ( )

Prints available metric options.

Definition at line 83 of file ObjectiveMetricUtils.cpp.

84 {
85  std::stringstream ss;
86  ss << "Available metrics:\n";
87  for (auto& item : metricNames())
88  ss << "\t" << item << "\n";
89  ss << "default metric: " << defaultMetricName() << "\n";
90  ss << "Available norms:\n";
91  for (auto& item : normNames())
92  ss << "\t" << item << "\n";
93  ss << "default norm: " << defaultNormName() << "\n";
94  return ss.str();
95 }
std::string defaultMetricName()
Returns default metric name.
std::string defaultNormName()
Returns default norm 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:

◆ createMetric() [1/2]

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

Creates the specified metric with the default norm.

Definition at line 58 of file ObjectiveMetricUtils.cpp.

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

References defaultNormName().

Referenced by MinimizerContainerItem::createMetric(), and 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 63 of file ObjectiveMetricUtils.cpp.

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

References availableMetricOptions().

Here is the call graph for this function:

◆ defaultMetricName()

std::string ObjectiveMetricUtils::defaultMetricName ( )

Returns default metric name.

Definition at line 112 of file ObjectiveMetricUtils.cpp.

113 {
114  return default_metric_name;
115 }

Referenced by MinimizerContainerItem::MinimizerContainerItem(), and availableMetricOptions().

◆ defaultNormName()

std::string ObjectiveMetricUtils::defaultNormName ( )

Returns default norm name.

Definition at line 107 of file ObjectiveMetricUtils.cpp.

108 {
109  return default_norm_name;
110 }

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

◆ l1Norm()

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

Returns L1 normalization function.

Definition at line 48 of file ObjectiveMetricUtils.cpp.

49 {
50  return l1_norm;
51 }

◆ l2Norm()

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

Returns L2 normalization function.

Definition at line 53 of file ObjectiveMetricUtils.cpp.

54 {
55  return l2_norm;
56 }

◆ metricNames()

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

Returns the names of the objective metrics used.

Definition at line 102 of file ObjectiveMetricUtils.cpp.

103 {
104  return keys(metric_factory);
105 }

Referenced by MinimizerContainerItem::MinimizerContainerItem(), and availableMetricOptions().

◆ normNames()

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

Returns the names of the norms used by ObjectiveMetric.

Definition at line 97 of file ObjectiveMetricUtils.cpp.

98 {
99  return keys(norm_factory);
100 }

Referenced by MinimizerContainerItem::MinimizerContainerItem(), and availableMetricOptions().