24Kernel::Logger
g_log(
"CostFuncLeastSquares");
41 size_t ny = values->size();
47 for (
size_t i = 0; i < ny; i++) {
48 double val = (values->getCalculated(i) - values->getFitData(i)) * weights[i];
68 function->function(*domain, *values);
69 size_t np = function->nParams();
70 size_t ny = values->size();
72 function->functionDeriv(*domain, jacobian);
78 for (
size_t ip = 0; ip < np; ++ip) {
79 if (!function->isActive(ip))
83 for (
size_t i = 0; i < ny; ++i) {
84 double calc = values->getCalculated(i);
85 double obs = values->getFitData(i);
86 double w = weights[i];
87 double y = (calc - obs) * w;
88 d +=
y * jacobian.
get(i, ip) * w;
110 for (
size_t i = 0; i < np; ++i)
112 if (!function->isActive(i))
115 for (
size_t j = 0; j <= i; ++j)
117 if (!function->isActive(j))
120 for (
size_t k = 0; k < ny; ++k)
122 double w = weights[k];
123 d += jacobian.
get(k, i) * jacobian.
get(k, j) * w * w;
145 std::vector<double> weights(values->size());
146 for (
size_t i = 0; i < weights.size(); ++i) {
147 weights[i] = values->getFitWeight(i);
165 if (
g_log.
is(Kernel::Logger::Priority::PRIO_DEBUG)) {
166 std::ostringstream osHess;
167 osHess <<
"== Hessian (H) ==\n";
168 osHess << std::left << std::fixed;
171 osHess << std::setw(10);
181 if (
g_log.
is(Kernel::Logger::Priority::PRIO_DEBUG)) {
182 std::ostringstream osCovar;
183 osCovar <<
"== Covariance matrix (H^-1) ==\n";
184 osCovar << std::left << std::fixed;
185 for (
size_t i = 0; i < covar.
size1(); ++i) {
186 for (
size_t j = 0; j < covar.
size2(); ++j) {
187 osCovar << std::setw(10);
188 osCovar << covar.
get(i, j) <<
" ";
#define DECLARE_COSTFUNCTION(classname, username)
Macro for declaring a new type of cost functions to be used with the CostFunctionFactory.
#define PARALLEL_CRITICAL(name)
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Represents the Jacobian in IFitFunction::functionDeriv.
virtual double get(size_t iY, size_t iP)=0
Get the value to a Jacobian matrix element.
A semi-abstract class for a cost function for fitting functions.
virtual double valDerivHessian(bool evalDeriv=true, bool evalHessian=true) const
Calculate the value, the first and the second derivatives of the cost function.
API::IFunction_sptr m_function
Shared pointer to the fitting function.
virtual double val() const override
Calculate value of cost function.
Cost function for least squares.
void calActiveCovarianceMatrix(EigenMatrix &covar, double epsrel=1e-8) override
Calculates covariance matrix for fitting function's active parameters.
void addVal(API::FunctionDomain_sptr domain, API::FunctionValues_sptr values) const override
Add a contribution to the cost function value from the fitting function evaluated on a particular dom...
void addValDerivHessian(API::IFunction_sptr function, API::FunctionDomain_sptr domain, API::FunctionValues_sptr values, bool evalDeriv=true, bool evalHessian=true) const override
Update the cost function, derivatives and hessian by adding values calculated on a domain.
virtual std::vector< double > getFitWeights(API::FunctionValues_sptr values) const
Get mapped weights from FunctionValues.
A wrapper around Eigen::Matrix.
bool isEmpty() const
Is matrix empty.
void set(size_t i, size_t j, double value)
Set an element.
double get(size_t i, size_t j) const
Get an element.
size_t size1() const
First size of the matrix.
void invert()
Invert this matrix.
size_t size2() const
Second size of the matrix.
void set(const size_t i, const double value)
Set an element.
double get(const size_t i) const
Get an element.
size_t size() const
Size of the vector.
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
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< FunctionDomain > FunctionDomain_sptr
typedef for a shared pointer