Mantid
Loading...
Searching...
No Matches
CostFuncRwp.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
15
16#include <cmath>
17
19
20DECLARE_COSTFUNCTION(CostFuncRwp, Rwp)
21
22//----------------------------------------------------------------------------------------------
27 m_includePenalty = false;
28 m_value = 0.;
29 m_pushed = false;
30 m_factor = 1.;
31}
32
33std::vector<double> CostFuncRwp::getFitWeights(API::FunctionValues_sptr values) const {
34 double sqrtW = calSqrtW(values);
35
36 std::vector<double> weights(values->size());
37 for (size_t i = 0; i < weights.size(); ++i) {
38 weights[i] = getWeight(values, i, sqrtW);
39 }
40
41 return weights;
42}
43
44//----------------------------------------------------------------------------------------------
47double CostFuncRwp::getWeight(const API::FunctionValues_sptr &values, size_t i, double sqrtW) const {
48 return (values->getFitWeight(i) / sqrtW);
49}
50
51//----------------------------------------------------------------------------------------------
55 double weight = 0.0;
56
57 // FIXME : This might give a wrong answer in case of multiple-domain
58 size_t ny = values->size();
59 for (size_t i = 0; i < ny; ++i) {
60 double obsval = values->getFitData(i);
61 double inv_sigma = values->getFitWeight(i);
62 weight += obsval * obsval * inv_sigma * inv_sigma;
63 }
64
65 return sqrt(weight);
66}
67
68} // namespace Mantid::CurveFitting::CostFunctions
const std::string & m_value
Definition: Algorithm.cpp:71
#define DECLARE_COSTFUNCTION(classname, username)
Macro for declaring a new type of cost functions to be used with the CostFunctionFactory.
Definition: ICostFunction.h:66
Cost function for Rwp = (sum_i (( obs_i - cal_i )/sigma_i)**2 ) / (sum_i (obs_i/sigma_i)**2)
Definition: CostFuncRwp.h:52
std::vector< double > getFitWeights(API::FunctionValues_sptr values) const override
Get mapped weights from FunctionValues.
Definition: CostFuncRwp.cpp:33
double calSqrtW(const API::FunctionValues_sptr &values) const
Calcualte sqrt(W).
Definition: CostFuncRwp.cpp:54
double getWeight(const API::FunctionValues_sptr &values, size_t i, double sqrtW=1.0) const
Get weight (1/sigma)
Definition: CostFuncRwp.cpp:47
std::shared_ptr< FunctionValues > FunctionValues_sptr
typedef for a shared pointer