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
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 y = getParameter(np - 1);
33 if (np > 1) {
34 for (size_t ip = np - 1; ip > 0; --ip) {
35 y = getParameter(ip - 1) + xValues[i] * y;
36 }
37 }
38 out[i] = y;
39 }
40}
41
42void FunctionChangesNParams::functionDeriv1D(Mantid::API::Jacobian *out, const double *xValues, const size_t nData) {
43 auto np = nParams();
44 for (size_t i = 0; i < nData; ++i) {
45 double y = 1.0;
46 out->set(i, 0, y);
47 if (np > 1) {
48 for (size_t ip = 1; ip < np; ++ip) {
49 y = xValues[i] * y;
50 out->set(i, ip, y);
51 }
52 }
53 }
54}
55
56} // 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.
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.
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)