Mantid
Loading...
Searching...
No Matches
FunctionCreationHelper.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 +
9
11
12std::string FunctionChangesNParams::name() const { return "FunctionChangesNParams"; }
13
15 this->declareParameter("A0", 0.0);
16}
17
19
21 auto np = nParams();
22 if (m_canChange && np < m_maxNParams) {
23 declareParameter("A" + std::to_string(np), 0.0);
25 }
26 m_canChange = false;
27}
28
29void FunctionChangesNParams::function1D(double *out, const double *xValues, const size_t nData) const {
30 auto np = nParams();
31 for (size_t i = 0; i < nData; ++i) {
32 double x = xValues[i];
33 double y = getParameter(np - 1);
34 if (np > 1) {
35 for (size_t ip = np - 1; ip > 0; --ip) {
36 y = getParameter(ip - 1) + x * y;
37 }
38 }
39 out[i] = y;
40 }
41}
42
43void FunctionChangesNParams::functionDeriv1D(Mantid::API::Jacobian *out, const double *xValues, const size_t nData) {
44 auto np = nParams();
45 for (size_t i = 0; i < nData; ++i) {
46 double x = xValues[i];
47 double y = 1.0;
48 out->set(i, 0, y);
49 if (np > 1) {
50 for (size_t ip = 1; ip < np; ++ip) {
51 y = x * y;
52 out->set(i, ip, y);
53 }
54 }
55 }
56}
57
58} // namespace Mantid::FrameworkTestHelpers
This is a specialization of IFunction for functions of one real argument.
Definition: IFunction1D.h:43
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
Implements the part of IFunction interface dealing with parameters.
Definition: ParamFunction.h:33
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
size_t nParams() const override
Total number of parameters.
Definition: ParamFunction.h:53
double getParameter(size_t i) const override
Get i-th parameter.
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
void iterationStarting() override
Called at the start of each iteration.
void functionDeriv1D(Mantid::API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
std::string name() const override
Returns the function's name.
void iterationFinished() override
Called at the end of an iteration.
Exception thrown when a fitting function changes number of parameters during fit.
Definition: Exception.h:336
Helper class which provides the Collimation Length for SANS instruments.
std::string to_string(const wide_integer< Bits, Signed > &n)