BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ObjectiveMetric Class Referenceabstract
Inheritance diagram for ObjectiveMetric:
Collaboration diagram for ObjectiveMetric:

Public Member Functions

 ObjectiveMetric (std::function< double(double)> norm)
 
ObjectiveMetricclone () const override=0
 
virtual double compute (const SimDataPair &data_pair, bool use_weights) const
 
virtual double computeFromArrays (std::vector< double > sim_data, std::vector< double > exp_data, std::vector< double > uncertainties, std::vector< double > weight_factors) const =0
 
virtual double computeFromArrays (std::vector< double > sim_data, std::vector< double > exp_data, std::vector< double > weight_factors) const =0
 
void setNorm (std::function< double(double)> norm)
 
auto norm () const
 
virtual void transferToCPP ()
 

Private Attributes

std::function< double(double)> m_norm
 

Detailed Description

Base class for metric implementations.

Definition at line 26 of file ObjectiveMetric.h.

Constructor & Destructor Documentation

◆ ObjectiveMetric()

ObjectiveMetric::ObjectiveMetric ( std::function< double(double)>  norm)

Definition at line 59 of file ObjectiveMetric.cpp.

59 : m_norm(std::move(norm)) {}
std::function< double(double)> m_norm
auto norm() const
Returns a copy of the normalization function used.

Member Function Documentation

◆ clone()

ObjectiveMetric* ObjectiveMetric::clone ( ) const
overridepure virtual

◆ compute()

double ObjectiveMetric::compute ( const SimDataPair data_pair,
bool  use_weights 
) const
virtual

Computes metric value from SimDataPair object.

Calls computeFromArrays internally.

Parameters
data_pairSimDataPair object. Can optionally contain data uncertainties
use_weightsboolean, defines if data uncertainties should be taken into account

Reimplemented in RQ4Metric.

Definition at line 61 of file ObjectiveMetric.cpp.

62 {
63  if (use_weights && !data_pair.containsUncertainties())
64  throw std::runtime_error("Error in ObjectiveMetric::compute: the metric is weighted, but "
65  "the simulation-data pair does not contain uncertainties");
66 
67  if (use_weights)
68  return computeFromArrays(data_pair.simulation_array(), data_pair.experimental_array(),
69  data_pair.uncertainties_array(), data_pair.user_weights_array());
70  else
71  return computeFromArrays(data_pair.simulation_array(), data_pair.experimental_array(),
72  data_pair.user_weights_array());
73 }
virtual double computeFromArrays(std::vector< double > sim_data, std::vector< double > exp_data, std::vector< double > uncertainties, std::vector< double > weight_factors) const =0
Computes metric value from data arrays.
std::vector< double > experimental_array() const
Returns the flattened experimental data cut to the ROI area.
std::vector< double > user_weights_array() const
Returns a flat array of user weights cut to the ROI area.
std::vector< double > uncertainties_array() const
Returns the flattened experimental uncertainties cut to the ROI area.
std::vector< double > simulation_array() const
Returns the flattened simulated intensities cut to the ROI area.
bool containsUncertainties() const
Definition: SimDataPair.cpp:81

References computeFromArrays(), SimDataPair::containsUncertainties(), SimDataPair::experimental_array(), SimDataPair::simulation_array(), SimDataPair::uncertainties_array(), and SimDataPair::user_weights_array().

Referenced by RQ4Metric::compute().

Here is the call graph for this function:

◆ computeFromArrays() [1/2]

virtual double ObjectiveMetric::computeFromArrays ( std::vector< double >  sim_data,
std::vector< double >  exp_data,
std::vector< double >  uncertainties,
std::vector< double >  weight_factors 
) const
pure virtual

Computes metric value from data arrays.

Negative values in exp_data are ignored as well as non-positive weight_factors and uncertainties. All arrays involved in the computation must be of the same size.

Parameters
sim_dataarray with simulated intensities.
exp_dataarray with intensity values obtained from an experiment.
uncertaintiesarray with experimental data uncertainties.
weight_factorsuser-defined weighting factors. Used linearly, no matter which norm is chosen.

Implemented in LogMetric, and Chi2Metric.

Referenced by compute().

◆ computeFromArrays() [2/2]

virtual double ObjectiveMetric::computeFromArrays ( std::vector< double >  sim_data,
std::vector< double >  exp_data,
std::vector< double >  weight_factors 
) const
pure virtual

Computes metric value from data arrays.

Negative values in exp_data are ignored as well as non-positive weight_factors. All arrays involved in the computation must be of the same size.

Parameters
sim_dataarray with simulated intensities.
exp_dataarray with intensity values obtained from an experiment.
weight_factorsuser-defined weighting factors. Used linearly, no matter which norm is chosen.

Implemented in RelativeDifferenceMetric, LogMetric, PoissonLikeMetric, and Chi2Metric.

◆ setNorm()

void ObjectiveMetric::setNorm ( std::function< double(double)>  norm)

Definition at line 75 of file ObjectiveMetric.cpp.

76 {
77  m_norm = std::move(norm);
78 }

References m_norm, and norm().

Here is the call graph for this function:

◆ norm()

auto ObjectiveMetric::norm ( ) const
inline

Returns a copy of the normalization function used.

Definition at line 63 of file ObjectiveMetric.h.

63 { return m_norm; }

References m_norm.

Referenced by Chi2Metric::computeFromArrays(), LogMetric::computeFromArrays(), PoissonLikeMetric::computeFromArrays(), RelativeDifferenceMetric::computeFromArrays(), and setNorm().

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

Used for Python overriding of clone (see swig/tweaks.py)

Definition at line 34 of file ICloneable.h.

Member Data Documentation

◆ m_norm

std::function<double(double)> ObjectiveMetric::m_norm
private

Definition at line 66 of file ObjectiveMetric.h.

Referenced by norm(), and setNorm().


The documentation for this class was generated from the following files: