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;
63 for (
size_t i = 0; i <
m_values->size(); ++i) {
65 sum += difference * difference;
68 auto degreesOfFreedom =
static_cast<double>(
m_values->size() -
nParams());
69 double residualVariance = sum / degreesOfFreedom;
71 if (
g_log.
is(Kernel::Logger::Priority::PRIO_DEBUG)) {
72 g_log.
debug() <<
"== Statistics of residuals ==\n";
73 std::ios::fmtflags prevState =
g_log.
debug().flags();
74 g_log.
debug() << std::left << std::fixed << std::setw(10);
75 g_log.
debug() <<
"Residual sum of squares: " << sum <<
'\n';
76 g_log.
debug() <<
"Residual variance: " << residualVariance <<
'\n';
77 g_log.
debug() <<
"Residual standard deviation: " << sqrt(residualVariance) <<
'\n';
78 g_log.
debug() <<
"Degrees of freedom: " <<
static_cast<size_t>(degreesOfFreedom) <<
'\n';
83 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 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