16Kernel::Logger
g_log(
"CostFuncUnweightedLeastSquares");
29 if (
g_log.
is(Kernel::Logger::Priority::PRIO_DEBUG)) {
30 g_log.
debug() <<
"== Final covariance matrix (H^-1) ==\n";
32 std::ios::fmtflags prevState =
g_log.
debug().flags();
35 for (
size_t i = 0; i < covar.
size1(); ++i) {
36 for (
size_t j = 0; j < covar.
size2(); ++j) {
48 std::vector<double> weights(values->size());
49 for (
size_t i = 0; i < weights.size(); ++i) {
50 weights[i] = values->getFitWeight(i) != 0 ? 1 : 0;
58 for (
size_t i = 0; i <
m_values->size(); i++) {
60 auto currentWeight =
m_values->getFitWeight(i);
62 if (std::abs(currentWeight) > std::max(1.0, std::abs(currentWeight)) * std::numeric_limits<double>::epsilon()) {
78 for (
size_t i = 0; i <
m_values->size(); ++i) {
80 sum += difference * difference;
83 auto degreesOfFreedom =
static_cast<double>(
m_values->size() -
nParams());
84 double residualVariance = sum / degreesOfFreedom;
86 if (
g_log.
is(Kernel::Logger::Priority::PRIO_DEBUG)) {
87 g_log.
debug() <<
"== Statistics of residuals ==\n";
88 std::ios::fmtflags prevState =
g_log.
debug().flags();
89 g_log.
debug() << std::left << std::fixed << std::setw(10);
90 g_log.
debug() <<
"Residual sum of squares: " << sum <<
'\n';
91 g_log.
debug() <<
"Residual variance: " << residualVariance <<
'\n';
92 g_log.
debug() <<
"Residual standard deviation: " << sqrt(residualVariance) <<
'\n';
93 g_log.
debug() <<
"Degrees of freedom: " <<
static_cast<size_t>(degreesOfFreedom) <<
'\n';
98 return residualVariance;
#define DECLARE_COSTFUNCTION(classname, username)
Macro for declaring a new type of cost functions to be used with the CostFunctionFactory.
API::FunctionValues_sptr m_values
Shared poinetr to the function values.
size_t nParams() const override
Number of parameters.
Cost function for least squares.
void calActiveCovarianceMatrix(EigenMatrix &covar, double epsrel=1e-8) override
Calculates covariance matrix for fitting function's active parameters.
In contrast to CostFuncLeastSquares, this variant of the cost function assumes that there are no weig...
void updateValidateFitWeights() override
Update the fit weights of m_values so that correct fit weights are used by the minimizer and GSLFunct...
void calActiveCovarianceMatrix(EigenMatrix &covar, double epsrel) override
Calculates covariance matrix for fitting function's active parameters.
std::vector< double > getFitWeights(API::FunctionValues_sptr values) const override
Return unit weights for all data points.
double getResidualVariance() const
Calculates the residual variance from the internally stored FunctionValues.
A wrapper around Eigen::Matrix.
double get(size_t i, size_t j) const
Get an element.
size_t size1() const
First size of the matrix.
size_t size2() const
Second size of the matrix.
void debug(const std::string &msg)
Logs at debug level.
bool is(int level) const
Returns true if at least the given log level is set.
std::shared_ptr< FunctionValues > FunctionValues_sptr
typedef for a shared pointer
Kernel::Logger g_log("ExperimentInfo")
static logger object