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

Public Member Functions

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

Private Attributes

std::function< double(double)> m_norm
 

Detailed Description

Implementation of relative difference metric.

With default L2 norm and weighting off corresponds to the formula

\[Result = \sum (I \cdot Q^4 - D \cdot Q^4)^2\]

where $Q$ is the scattering vector magnitude. If weighting is on, coincides with the metric provided by Chi2Metric class.

Definition at line 191 of file ObjectiveMetric.h.

Constructor & Destructor Documentation

◆ RQ4Metric()

RQ4Metric::RQ4Metric ( )

Definition at line 224 of file ObjectiveMetric.cpp.

224 : Chi2Metric() {}

Member Function Documentation

◆ clone()

RQ4Metric * RQ4Metric::clone ( ) const
overridevirtual

Reimplemented from Chi2Metric.

Definition at line 226 of file ObjectiveMetric.cpp.

227 {
228  return copyMetric(*this);
229 }

References anonymous_namespace{ObjectiveMetric.cpp}::copyMetric().

Here is the call graph for this function:

◆ compute()

double RQ4Metric::compute ( const SimDataPair data_pair,
bool  use_weights 
) const
overridevirtual

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 from ObjectiveMetric.

Definition at line 231 of file ObjectiveMetric.cpp.

232 {
233  if (use_weights)
234  return Chi2Metric::compute(data_pair, use_weights);
235 
236  // fetching data in RQ4 form
237  auto sim_data = data_pair.simulationResult().data(Axes::Units::RQ4);
238  auto exp_data = data_pair.experimentalData().data(Axes::Units::RQ4);
239 
240  return computeFromArrays(sim_data->getRawDataVector(), exp_data->getRawDataVector(),
241  data_pair.user_weights_array());
242 }
double computeFromArrays(std::vector< double > sim_data, std::vector< double > exp_data, std::vector< double > uncertainties, std::vector< double > weight_factors) const override
Computes metric value from data arrays.
virtual double compute(const SimDataPair &data_pair, bool use_weights) const
Computes metric value from SimDataPair object.
std::vector< double > user_weights_array() const
Returns a flat array of user weights cut to the ROI area.
SimulationResult experimentalData() const
Returns the experimental data cut to the ROI area.
Definition: SimDataPair.cpp:98
SimulationResult simulationResult() const
Returns the result of last computed simulation.
Definition: SimDataPair.cpp:91
std::unique_ptr< OutputData< double > > data(Axes::Units units=Axes::Units::DEFAULT) const

References ObjectiveMetric::compute(), Chi2Metric::computeFromArrays(), SimulationResult::data(), SimDataPair::experimentalData(), SimDataPair::simulationResult(), and SimDataPair::user_weights_array().

Here is the call graph for this function:

◆ computeFromArrays() [1/2]

double Chi2Metric::computeFromArrays ( std::vector< double >  sim_data,
std::vector< double >  exp_data,
std::vector< double >  uncertainties,
std::vector< double >  weight_factors 
) const
overridevirtualinherited

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.

Implements ObjectiveMetric.

Definition at line 89 of file ObjectiveMetric.cpp.

92 {
93  checkIntegrity(sim_data, exp_data, uncertainties, weight_factors);
94 
95  double result = 0.0;
96  auto norm_fun = norm();
97  for (size_t i = 0, sim_size = sim_data.size(); i < sim_size; ++i)
98  if (exp_data[i] >= 0.0 && weight_factors[i] > 0.0 && uncertainties[i] > 0.0)
99  result += norm_fun((exp_data[i] - sim_data[i]) / uncertainties[i]) * weight_factors[i];
100 
101  return std::isfinite(result) ? result : double_max;
102 }
auto norm() const
Returns a copy of the normalization function used.
void checkIntegrity(const std::vector< double > &sim_data, const std::vector< double > &exp_data, const std::vector< double > &uncertainties, const std::vector< double > &weight_factors)

References anonymous_namespace{ObjectiveMetric.cpp}::checkIntegrity(), and ObjectiveMetric::norm().

Referenced by compute().

Here is the call graph for this function:

◆ computeFromArrays() [2/2]

double Chi2Metric::computeFromArrays ( std::vector< double >  sim_data,
std::vector< double >  exp_data,
std::vector< double >  weight_factors 
) const
overridevirtualinherited

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.

Implements ObjectiveMetric.

Reimplemented in RelativeDifferenceMetric, and PoissonLikeMetric.

Definition at line 104 of file ObjectiveMetric.cpp.

106 {
107  checkIntegrity(sim_data, exp_data, weight_factors);
108 
109  auto norm_fun = norm();
110  double result = 0.0;
111  for (size_t i = 0, sim_size = sim_data.size(); i < sim_size; ++i)
112  if (exp_data[i] >= 0.0 && weight_factors[i] > 0.0)
113  result += norm_fun(exp_data[i] - sim_data[i]) * weight_factors[i];
114 
115  return std::isfinite(result) ? result : double_max;
116 }

References anonymous_namespace{ObjectiveMetric.cpp}::checkIntegrity(), anonymous_namespace{ObjectiveMetric.cpp}::double_max, and ObjectiveMetric::norm().

Here is the call graph for this function:

◆ setNorm()

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

Definition at line 75 of file ObjectiveMetric.cpp.

76 {
77  m_norm = std::move(norm);
78 }
std::function< double(double)> m_norm

References ObjectiveMetric::m_norm, and ObjectiveMetric::norm().

Here is the call graph for this function:

◆ norm()

auto ObjectiveMetric::norm ( ) const
inlineinherited

◆ 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
privateinherited

Definition at line 66 of file ObjectiveMetric.h.

Referenced by ObjectiveMetric::norm(), and ObjectiveMetric::setNorm().


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