17using namespace CurveFitting;
22using namespace Kernel;
34 if (std::string(varName) !=
"x") {
51 "The comma separated list of initial values of the fit "
52 "parameters in the form varName=value");
66 throw std::runtime_error(
"Formula does not contain the x variable");
69 std::string initParams =
getProperty(
"InitialParameters");
70 if (!initParams.empty()) {
72 for (
const auto &it : values) {
73 size_t ieq = it.find(
'=');
74 if (ieq == std::string::npos)
75 throw std::invalid_argument(
"Property InitialParameters is malformed");
76 std::string varName = it.substr(0, ieq);
77 std::string varValue = it.substr(ieq + 1);
78 size_t i0 = varName.find_first_not_of(
" \t");
79 size_t i1 = varName.find_last_not_of(
" \t");
80 if (i0 == std::string::npos)
81 throw std::invalid_argument(
"Property InitialParameters is malformed");
82 varName = varName.substr(i0, i1 - i0 + 1);
83 if (varName.empty() || varValue.empty())
84 throw std::invalid_argument(
"Property InitialParameters is malformed");
85 double value = std::stod(varValue);
87 throw std::invalid_argument(
"Fit parameter " + varName +
" does not exist");
111 for (
size_t i = 0; i < static_cast<size_t>(
m_nPars); i++)
114 for (
size_t i = 0; i < nData; i++) {
130 std::vector<double> dp(
m_nPars);
131 std::vector<double> in1(
m_nPars);
132 for (
int i = 0; i <
m_nPars; i++) {
148 for (
int j = 0; j <
m_nPars; j++) {
151 for (
size_t i = 0; i < nData; i++) {
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Represents the Jacobian in IFitFunction::functionDeriv.
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
std::vector< std::string > m_parameterNames
Holds a copy of the names of the fitting parameters.
Deprecation notice: instead of using this algorithm please use the Fit algorithm where the Function p...
int m_nPars
Number of actual parameters.
void declareAdditionalProperties() override
Declare properties that are not fit parameters.
std::vector< double > m_tmp
Temporary data storage.
mu::Parser m_parser
muParser instance
std::vector< double > m_parameters
Pointer to muParser variables' buffer.
void functionDeriv(const double *in, API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to parameters you are trying to fit.
static double * AddVariable(const char *varName, void *palg)
Static callback function used by MuParser to initialize variables implicitly.
bool m_x_set
True indicates that input formula contains 'x' variable.
void function(const double *in, double *out, const double *xValues, const size_t nData) override
overwrite base class methods
void prepare() override
Declare fit parameters using muParser's implicit variable initialization.
double m_x
Used as 'x' variable in m_parser.
std::vector< double > m_tmp1
Temporary data storage.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
Validator to check that a property is not left empty.
@ TOK_TRIM
remove leading and trailing whitespace from tokens