BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ChiModuleWrapper Class Reference

Metric wrapper for back-compaptibility with old scripts. More...

Inheritance diagram for ChiModuleWrapper:
[legend]
Collaboration diagram for ChiModuleWrapper:
[legend]

Public Member Functions

 ChiModuleWrapper (std::unique_ptr< IChiSquaredModule > module)
 
double compute (const std::vector< SimDataPair > &fit_objects, size_t n_pars) const override
 

Private Attributes

std::unique_ptr< IChiSquaredModulem_module
 

Detailed Description

Metric wrapper for back-compaptibility with old scripts.

Definition at line 31 of file FitObjective.cpp.

Constructor & Destructor Documentation

◆ ChiModuleWrapper()

ChiModuleWrapper::ChiModuleWrapper ( std::unique_ptr< IChiSquaredModule module)
explicit

Definition at line 318 of file FitObjective.cpp.

319  : IMetricWrapper(), m_module(std::move(module))
320 {
321  if (!m_module)
322  throw std::runtime_error("Error in ChiModuleWrapper: empty chi square module passed");
323 }
std::unique_ptr< IChiSquaredModule > m_module

References m_module.

Member Function Documentation

◆ compute()

double ChiModuleWrapper::compute ( const std::vector< SimDataPair > &  fit_objects,
size_t  n_pars 
) const
overridevirtual

Implements IMetricWrapper.

Definition at line 325 of file FitObjective.cpp.

326 {
327  size_t n_points = 0;
328  double result = 0.0;
329  for (auto& obj : fit_objects) {
330  const auto sim_array = obj.simulation_array();
331  const auto exp_array = obj.experimental_array();
332  const auto weights = obj.user_weights_array();
333  const size_t n_elements = sim_array.size();
334  for (size_t i = 0; i < n_elements; ++i) {
335  double value = m_module->residual(sim_array[i], exp_array[i], weights[i]);
336  result += value * value;
337  }
338  n_points += n_elements;
339  }
340 
341  int fnorm = static_cast<int>(n_points) - static_cast<int>(n_pars);
342  if (fnorm <= 0)
343  throw std::runtime_error("Error in ChiModuleWrapper: Normalization shall be positive");
344 
345  return result / fnorm;
346 }

References m_module.

Member Data Documentation

◆ m_module

std::unique_ptr<IChiSquaredModule> ChiModuleWrapper::m_module
private

Definition at line 37 of file FitObjective.cpp.

Referenced by ChiModuleWrapper(), and compute().


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