BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ChiSquaredModule.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Residual/ChiSquaredModule.cpp
6 //! @brief Implements class ChiSquaredModule.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Util/Assert.h"
19 #include <cmath>
20 #include <limits>
21 
22 double ChiSquaredModule::residual(double a, double b, double weight)
23 {
24  double value_simu = a;
25  double value_real = b;
26 
28  value_simu = m_intensity_function->evaluate(value_simu);
29  value_real = m_intensity_function->evaluate(value_real);
30  }
31 
32  double variance = m_variance_function->variance(value_real, value_simu);
33  double normalize = variance <= 0 ? std::numeric_limits<double>::min() : std::sqrt(variance);
34 
35  return std::sqrt(weight) * (value_simu - value_real) / normalize;
36 }
Defines the macro ASSERT.
Defines class ChiSquaredModule.
Defines and implements the interface class IIntensityFunction and its child classes IntensityFunction...
Defines IVarianceFunction classes.
double residual(double a, double b, double weight) override
std::unique_ptr< IIntensityFunction > m_intensity_function
std::unique_ptr< IVarianceFunction > m_variance_function