11using namespace Kernel;
21int CalculateChiSquared::version()
const {
return 1; }
24const std::string CalculateChiSquared::summary()
const {
25 return "Calculate chi squared for a function and a data set in a workspace.";
30void CalculateChiSquared::initConcrete() {
33 "Output value of chi squared divided by the "
34 "number of degrees of freedom (NofData "
38 "Output value of chi squared divided by the "
39 "number of data points).",
43 "Output value of weighted chi squared divided by the "
44 "number of degrees of freedom (NofData "
48 "Output value of weighted chi squared divided by the "
49 "number of data points).",
52 "Option to use the weighted chi squared "
53 "in error estimation. Default is false.");
58void CalculateChiSquared::execConcrete() {
72 for (
size_t i = 0; i <
m_function->nParams(); ++i) {
81 double chiSquared = 0.0;
82 double chiSquaredWeighted = 0.0;
85 g_log.
notice() <<
"Chi squared " << chiSquared <<
"\n"
86 <<
"Chi squared weighted " << chiSquaredWeighted <<
"\n";
90 setProperty(
"chiSquaredWeighted", chiSquaredWeighted);
93 double nData = dof +
static_cast<double>(nParams);
94 const double chiSquaredNData = chiSquared / nData;
95 const double chiSquaredWeightedNData = chiSquaredWeighted / nData;
96 g_log.
notice() <<
"Chi squared / NData " << chiSquaredNData <<
"\n"
97 <<
"Chi squared weighed / NData " << chiSquaredWeightedNData <<
"\n"
98 <<
"NParams " << nParams <<
"\n";
101 setProperty(
"ChiSquaredDividedByNData", chiSquaredNData);
102 setProperty(
"ChiSquaredWeightedDividedByNData", chiSquaredWeightedNData);
107 g_log.
warning(
"DOF has a non-positive value, changing to 1.0");
109 const double chiSquaredDOF = chiSquared / dof;
110 const double chiSquaredWeightedDOF = chiSquaredWeighted / dof;
111 g_log.
notice() <<
"Chi squared / DOF " << chiSquaredDOF <<
"\n"
112 <<
"Chi squared weighed / DOF " << chiSquaredWeightedDOF <<
"\n"
113 <<
"DOF " << dof <<
"\n";
116 setProperty(
"ChiSquaredDividedByDOF", chiSquaredDOF);
117 setProperty(
"ChiSquaredWeightedDividedByDOF", chiSquaredWeightedDOF);
140 chiSquaredWeighted = 0.0;
141 dof = -
static_cast<double>(nParams);
142 for (
size_t i = 0; i < values.
size(); ++i) {
148 chiSquaredWeighted +=
tmp *
tmp;
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Base class that represents the domain of a function.
A class to store values calculated by a function.
double getFitWeight(size_t i) const
Get a fitting weight.
double getFitData(size_t i) const
Get a fitting data value.
size_t size() const
Return the number of values.
double getCalculated(size_t i) const
Get i-th calculated value.
This is an interface to a fitting function - a semi-abstarct class.
virtual void function(const FunctionDomain &domain, FunctionValues &values) const =0
Evaluates the function for all arguments in the domain.
Calculate chi squared for a function and a data set in a workspace.
static void calcChiSquared(const API::IFunction &fun, size_t nParams, const API::FunctionDomain &domain, API::FunctionValues &values, double &chiSquared, double &chiSquaredWeighted, double &dof)
Caclculate the chi squared, weighted chi squared and the number of degrees of freedom.
std::shared_ptr< API::IDomainCreator > m_domainCreator
Pointer to a domain creator.
std::shared_ptr< API::IFunction > m_function
Pointer to the fitting function.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void warning(const std::string &msg)
Logs at warning level.
std::shared_ptr< FunctionValues > FunctionValues_sptr
typedef for a shared pointer
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< FunctionDomain > FunctionDomain_sptr
typedef for a shared pointer
@ Output
An output workspace.