37#include <boost/lexical_cast.hpp>
48constexpr double EPSILON = std::numeric_limits<double>::epsilon();
49constexpr double MIN_DOUBLE = std::numeric_limits<double>::min();
50constexpr double STEP_PERCENTAGE = 0.001;
52const auto defaultStepSize = [](
const double parameterValue) ->
double {
53 return fabs(parameterValue) < 100.0 * MIN_DOUBLE / STEP_PERCENTAGE ? 100.0 *
EPSILON
54 : parameterValue * STEP_PERCENTAGE;
57const auto sqrtEpsilonStepSize = [](
const double parameterValue) ->
double {
64using namespace Geometry;
68Kernel::Logger
g_log(
"IFunction");
78 bool operator<(TieNode
const &other)
const {
79 return std::find(other.right.begin(), other.right.end(),
left) != other.right.end();
82const std::vector<std::string> EXCLUDEUSAGE = {
"CompositeFunction"};
99 if (!Kernel::UsageService::Instance().isEnabled()) {
102 if (std::find(EXCLUDEUSAGE.cbegin(), EXCLUDEUSAGE.cend(),
name()) == EXCLUDEUSAGE.cend() && !
m_isRegistered) {
111 auto clonedFunction = FunctionFactory::Instance().createInitialized(this->
asString());
112 for (
size_t i = 0; i < this->
nParams(); i++) {
114 clonedFunction->setError(i,
error);
116 return clonedFunction;
190 if (status ==
Tied) {
206 if (status ==
Tied) {
222 auto newTie = std::make_unique<ParameterTie>(
this, parName, expr, isDefault);
224 if (!isDefault && newTie->isConstant()) {
240void IFunction::tie(
const std::string &parName,
const std::string &expr,
bool isDefault) {
244 addTie(std::move(tiePtr));
258 std::map<size_t, std::pair<size_t, std::string>> oldTies;
263 for (
const auto &t : list) {
264 if (t.name() ==
"=" && t.size() >= 2) {
265 size_t n = t.size() - 1;
266 const std::string expr = t[
n].str();
267 for (
size_t i =
n; i != 0;) {
269 const auto &parName = t[i].name();
274 oldTies[iPar] =
insertTie(std::move(parTie));
282 }
catch (std::runtime_error &) {
283 for (
const auto &[iPar, oldTie] : oldTies) {
284 auto [oldIdx, oldExp] = oldTie;
286 if (!oldExp.empty()) {
309 std::ostringstream tieStream;
311 for (
auto &parTie :
m_ties) {
312 if (parTie->isDefault())
319 tieStream << parTie->asString(
this);
321 return tieStream.str();
331 std::size_t existingTieIndex =
333 [&](
const auto &m_tie) { return getParameterIndex(*m_tie) == iPar; }));
334 std::string oldExp =
"";
335 const auto oldTie =
getTie(iPar);
337 const auto oldTieStr = oldTie->asString();
338 oldExp = oldTieStr.substr(oldTieStr.find(
"=") + 1);
341 if (existingTieIndex <
m_ties.size()) {
342 m_ties[existingTieIndex] = std::move(
tie);
349 return {existingTieIndex, oldExp};
351 return {existingTieIndex,
""};
362 const auto [oldIdx, oldExp] =
insertTie(std::move(
tie));
367 }
catch (std::runtime_error &) {
369 if (!oldExp.empty()) {
393 for (
auto &parTie :
m_ties) {
423 throw std::out_of_range(
"Function parameter index out of range.");
441 if (it !=
m_ties.cend()) {
450 for (
size_t i = 0; i <
nParams(); ++i) {
460 size_t iPar = ic->parameterIndex();
462 [&iPar](
const auto &constraint) { return constraint->parameterIndex() == iPar; });
489 [&iPar](
const auto &constraint) { return iPar == constraint->getLocalIndex(); });
502 [&iPar](
const auto &constraint) { return iPar == constraint->getLocalIndex(); });
505 (*it)->setPenaltyFactor(c);
507 g_log.
warning() << parName <<
" does not have constraint so setConstraintPenaltyFactor failed"
517 constraint->setParamToSatisfyConstraint();
524 std::ostringstream stream;
527 if (constrint->isDefault())
534 stream << constrint->asString();
554 std::ostringstream ostr;
555 ostr <<
"name=" << this->
name();
558 for (
const auto &attName : attr) {
560 if (!attValue.empty() && attValue !=
"\"\"") {
561 ostr <<
',' << attName <<
'=' << attValue;
564 std::vector<std::string> ties;
566 for (
size_t i = 0; i <
nParams(); i++) {
567 std::ostringstream paramOut;
569 ostr <<
',' << paramOut.str();
572 ties.emplace_back(paramOut.str());
579 if (!constraints.empty()) {
580 ostr <<
",constraints=(" << constraints <<
")";
585 if (!tiesString.empty()) {
586 ties.emplace_back(tiesString);
593 ostr << parentLocalAttributesStr;
607 for (
auto it = list.
begin(); it != list.
end(); ++it) {
609 if (expr.terms()[0].str().compare(
"penalty") == 0) {
612 if ((it + 1) != list.
end()) {
613 auto next_expr = *(it + 1);
614 if (next_expr.terms()[0].str().compare(
"penalty") == 0) {
615 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
616 double penalty_factor = std::stof(next_expr.terms()[1].str(), NULL);
617 c->setPenaltyFactor(penalty_factor);
620 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
624 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
634 std::vector<std::string> out;
635 for (
size_t i = 0; i <
nParams(); ++i) {
645 if (handler && handler->function().get() !=
this) {
646 throw std::runtime_error(
"Function handler points to a different function");
678 std::string apply(
const std::string & )
const override {
return "std::string"; }
680 std::string apply(
const int & )
const override {
return "int"; }
682 std::string apply(
const double & )
const override {
return "double"; }
684 std::string apply(
const bool & )
const override {
return "bool"; }
686 std::string apply(
const std::vector<double> & )
const override {
return "std::vector<double>"; }
701 explicit AttValue(
bool quoteString =
false)
706 std::string apply(
const std::string &str)
const override {
707 return (
m_quoteString) ? std::string(
"\"" + str +
"\"") : str;
710 std::string apply(
const int &i)
const override {
return std::to_string(i); }
712 std::string apply(
const double &d)
const override {
return boost::lexical_cast<std::string>(d); }
714 std::string apply(
const bool &b)
const override {
return b ?
"true" :
"false"; }
716 std::string apply(
const std::vector<double> &v)
const override {
717 std::string res =
"(";
719 for (
size_t i = 0; i < v.size() - 1; ++i) {
720 res += boost::lexical_cast<std::string>(v[i]) +
",";
722 res += boost::lexical_cast<std::string>(v.back());
735 AttValue
tmp(m_quoteValue);
744 return asQuotedString();
747 return boost::get<std::string>(
m_data);
749 throw std::runtime_error(
"Trying to access a " + type() +
762 attr = boost::get<std::string>(
m_data);
764 throw std::runtime_error(
"Trying to access a " + type() +
772 std::string quoted(attr);
773 if (*(attr.begin()) !=
'\"')
774 quoted =
"\"" + attr;
775 if (*(quoted.end() - 1) !=
'\"')
788 attr = boost::get<std::string>(
m_data);
790 throw std::runtime_error(
"Trying to access a " + type() +
794 std::string unquoted(attr);
797 if (*(attr.begin()) ==
'\"')
798 unquoted = std::string(attr.begin() + 1, attr.end() - 1);
799 if (*(unquoted.end() - 1) ==
'\"')
800 unquoted.resize(unquoted.size() - 1);
810 return boost::get<int>(
m_data);
812 throw std::runtime_error(
"Trying to access a " + type() +
823 return boost::get<double>(
m_data);
825 throw std::runtime_error(
"Trying to access a " + type() +
836 return boost::get<bool>(
m_data);
838 throw std::runtime_error(
"Trying to access a " + type() +
849 return boost::get<std::vector<double>>(
m_data);
851 throw std::runtime_error(
"Trying to access a " + type() +
862 evaluateValidator(str);
865 boost::get<std::string>(
m_data) = str;
867 throw std::runtime_error(
"Trying to access a " + type() +
878 evaluateValidator(
d);
881 boost::get<double>(
m_data) =
d;
883 throw std::runtime_error(
"Trying to access a " + type() +
894 evaluateValidator(i);
897 boost::get<int>(
m_data) = i;
899 throw std::runtime_error(
"Trying to access a " + type() +
910 evaluateValidator(b);
913 boost::get<bool>(
m_data) = b;
915 throw std::runtime_error(
"Trying to access a " + type() +
927 evaluateValidator(v);
930 auto &data = boost::get<std::vector<double>>(
m_data);
931 data.assign(v.begin(), v.end());
933 throw std::runtime_error(
"Trying to access a " + type() +
942 return boost::get<std::string>(
m_data).empty();
944 throw std::runtime_error(
"Trying to access a " + type() +
" attribute as string");
964 void apply(std::string &str)
const override {
969 void apply(
int &i)
const override {
972 std::istringstream istr(
m_value +
" ");
975 throw std::invalid_argument(
"Failed to set int attribute "
979 evaluateValidator(tempi);
983 void apply(
double &d)
const override {
986 std::istringstream istr(
m_value +
" ");
989 throw std::invalid_argument(
"Failed to set double attribute "
993 evaluateValidator(tempd);
997 void apply(
bool &b)
const override {
1001 evaluateValidator(tempb);
1006 void apply(std::vector<double> &v)
const override {
1018 Kernel::StringTokenizer
tokenizer(
m_value,
",", Kernel::StringTokenizer::TOK_TRIM);
1023 std::vector<double> tempVec(newSize);
1025 for (
size_t i = 0; i < tempVec.size(); ++i) {
1026 tempVec[i] = boost::lexical_cast<double>(tokenizer[i]);
1028 evaluateValidator(tempVec);
1032 for (
size_t i = 0; i < v.size(); ++i) {
1033 v[i] = boost::lexical_cast<double>(tokenizer[i]);
1038 template <
typename T>
void evaluateValidator(T &inputData)
const {
1040 IFunction::ValidatorEvaluator::evaluate(inputData,
m_validator);
1072 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1081 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1092 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1103 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1121 const size_t nParam =
nParams();
1131 nData = minusStep.
size();
1135 for (
size_t iP = 0; iP < nParam; iP++) {
1140 const double paramPstep = val + step;
1147 step = paramPstep - val;
1148 for (
size_t i = 0; i < nData; i++) {
1163 return defaultStepSize(parameterValue);
1165 return sqrtEpsilonStepSize(parameterValue);
1169 throw std::invalid_argument(
"An invalid method for calculating the step size was provided.");
1198 const auto &specDef =
workspace->spectrumInfo().spectrumDefinition(wi);
1199 if (specDef.size() == 0) {
1201 <<
" as no detector ids can be found for this workspace on the instrument\n";
1205 const auto &componentInfo =
workspace->componentInfo();
1206 const auto ¶mInfo = *(componentInfo.sharedParameterInfo());
1207 const auto detIndex = specDef[0].first;
1209 for (
size_t i = 0; i <
nParams(); i++) {
1215 paramInfo.getRecursiveFittingParameter(componentInfo, detIndex,
parameterName(i), this->
name());
1218 param = paramInfo.getRecursive(componentInfo, detIndex,
parameterName(i),
"fitting");
1226 if (
name() == fitParam.getFunction()) {
1229 if (testWithLocation ==
nullptr ||
1230 (!fitParam.getLookUpTable().containData() && fitParam.getFormula().empty())) {
1233 double centreValue = testWithLocation->centre();
1236 if (fitParam.getFormula().empty())
1237 centreUnit = fitParam.getLookUpTable().getXUnit();
1239 if (!fitParam.getFormulaUnit().empty()) {
1241 centreUnit = Kernel::UnitFactory::Instance().create(fitParam.getFormulaUnit());
1243 g_log.
warning() << fitParam.getFormulaUnit() <<
" Is not an recognised formula unit for parameter "
1244 << fitParam.getName() <<
"\n";
1253 <<
" centre of peak before any unit conversion is " << centreValue <<
'\n';
1256 <<
" centre of peak after any unit conversion is " << centreValue <<
'\n';
1259 double paramValue = fitParam.getValue(centreValue);
1266 if (fitParam.getFormula().empty()) {
1270 <<
" before y-unit conversion\n";
1273 <<
" after y-unit conversion\n";
1277 std::string resultUnitStr = fitParam.getResultUnit();
1279 if (!resultUnitStr.empty()) {
1280 std::vector<std::string> allUnitStr = Kernel::UnitFactory::Instance().getKeys();
1281 for (
auto &iUnit : allUnitStr) {
1282 size_t found = resultUnitStr.find(iUnit);
1283 if (found != std::string::npos) {
1284 size_t len = iUnit.size();
1285 std::stringstream readDouble;
1288 resultUnitStr.replace(found, len, readDouble.str());
1294 p.SetExpr(resultUnitStr);
1296 <<
" before result-unit conversion (using " << resultUnitStr <<
")\n";
1297 paramValue *= p.Eval();
1299 <<
" after result-unit conversion\n";
1300 }
catch (mu::Parser::exception_type &e) {
1301 g_log.
error() <<
"Cannot convert formula unit to workspace unit"
1302 <<
" Formula unit which cannot be passed is " << resultUnitStr
1303 <<
". Muparser error message is: " << e.GetMsg() <<
'\n';
1314 if (!fitParam.getTie().empty()) {
1315 std::ostringstream str;
1322 if (!fitParam.getConstraint().empty()) {
1323 IConstraint *constraint = ConstraintFactory::Instance().createInitialized(
this, fitParam.getConstraint());
1324 if (!fitParam.getConstraintPenaltyFactor().empty()) {
1326 double penalty = std::stod(fitParam.getConstraintPenaltyFactor());
1329 g_log.
warning() <<
"Can't set penalty factor for constraint\n";
1351 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1353 const auto &wsUnit = ws->getAxis(0)->unit();
1354 if (outUnit->unitID() == wsUnit->unitID())
1359 double factor(0.0), power(0.0);
1360 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1361 return factor * std::pow(
value, power);
1363 std::vector<double> singleValue(1,
value);
1365 return singleValue.front();
1378 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1380 const auto &wsUnit = ws->getAxis(0)->unit();
1381 if (outUnit->unitID() == wsUnit->unitID())
1385 double factor, power;
1386 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1387 auto iend = values.end();
1388 for (
auto itr = values.begin(); itr !=
iend; ++itr)
1389 (*itr) = factor * std::pow(*itr, power);
1394 if (sample ==
nullptr) {
1395 g_log.
error() <<
"No sample defined instrument. Cannot convert units for function\n"
1396 <<
"Ignore conversion.";
1399 const auto &spectrumInfo = ws->spectrumInfo();
1400 double l1 = spectrumInfo.l1();
1402 auto emode = ws->getEMode();
1405 spectrumInfo.getDetectorValues(*wsUnit, *outUnit, emode,
false, wsIndex,
pmap);
1407 std::vector<double> emptyVec;
1408 wsUnit->toTOF(values, emptyVec, l1, emode,
pmap);
1409 outUnit->fromTOF(values, emptyVec, l1, emode,
pmap);
1410 }
catch (std::exception &) {
1411 throw std::runtime_error(
"Unable to perform unit conversion to " + outUnit->unitID());
1430 std::string str(
value);
1447 throw std::runtime_error(
"Function " +
name() +
" doesn't have children.");
1452 std::vector<std::string> names;
1467 throw std::out_of_range(
"Function attribute index out of range.");
1481 throw std::invalid_argument(
"ParamFunctionAttributeHolder::getAttribute - Unknown attribute '" +
name +
"'");
1530 std::ostringstream msg;
1531 msg <<
"Attribute (" <<
name <<
") already exists.";
1532 throw std::invalid_argument(msg.str());
1551 value.setValidator(validatorClone);
1552 value.evaluateValidator();
1556 throw std::invalid_argument(
"ParamFunctionAttributeHolder::setAttribute - Unknown attribute '" +
name +
"'");
1582 throw std::invalid_argument(
"IFunction: Cannot set an empty covariance matrix");
1585 if (covar->numRows() !=
nParams() || covar->numCols() !=
nParams()) {
1586 throw std::invalid_argument(
"IFunction: Covariance matrix has a wrong size");
1613 for (
size_t i = 0; i <
nParams(); ++i) {
1622 for (
size_t i = 0; i <
nParams(); ++i) {
1631 for (
size_t i = 0; i <
nParams(); ++i) {
1644 for (
size_t i = 0; i <
nParams(); ++i) {
1663 return std::vector<IFunction_sptr>(1, FunctionFactory::Instance().createInitialized(
asString()));
1674 std::list<TieNode> orderedTieNodes;
1675 for (
size_t i = 0; i <
nParams(); ++i) {
1676 auto const parTie =
getTie(i);
1683 auto const rhsParameters = parTie->getRHSParameters();
1684 newNode.right.reserve(rhsParameters.size());
1685 for (
auto &&p : rhsParameters) {
1688 if (newNode < newNode) {
1689 throw std::runtime_error(
"Parameter is tied to itself: " + parTie->asString(
this));
1691 bool before(
false), after(
false);
1692 size_t indexBefore(0), indexAfter(0);
1693 for (
auto &&node : orderedTieNodes) {
1694 if (newNode < node) {
1696 indexBefore = node.left;
1698 if (node < newNode) {
1700 indexAfter = node.left;
1705 std::string message =
"Circular dependency in ties:\n" + parTie->asString(
this) +
'\n';
1707 if (indexAfter != indexBefore) {
1710 throw std::runtime_error(message);
1712 orderedTieNodes.push_front(newNode);
1714 orderedTieNodes.emplace_back(newNode);
1718 for (
auto &&node : orderedTieNodes) {
1719 auto const parTie =
getTie(node.left);
1731MANTID_API_DLL std::shared_ptr<Mantid::API::IFunction>
1732IPropertyManager::getValue<std::shared_ptr<Mantid::API::IFunction>>(
const std::string &
name)
const {
1737 std::string message =
"Attempt to assign property " +
name +
" to incorrect type. Expected shared_ptr<IFunction>.";
1738 throw std::runtime_error(message);
1743MANTID_API_DLL std::shared_ptr<const Mantid::API::IFunction>
1744IPropertyManager::getValue<std::shared_ptr<const Mantid::API::IFunction>>(
const std::string &
name)
const {
1746 dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>
> *>(getPointerToProperty(
name));
1748 return prop->operator()();
1750 std::string message =
1751 "Attempt to assign property " +
name +
" to incorrect type. Expected const shared_ptr<IFunction>.";
1752 throw std::runtime_error(message);
const std::string & m_value
Kernel::IValidator_sptr m_validator
bool m_quoteString
Flag to quote a string value returned.
double value
The value of the point.
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
const double EPSILON(1.0E-10)
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
const std::vector< Type > & m_data
This class represents an expression made up of names, binary operators and brackets.
void parse(const std::string &str)
Parse a string and create an expression.
iterator end() const
An iterator pointing to the end of the expressions.
iterator begin() const
An iterator pointing to the start of the expressions.
void toList(const std::string &sep=",")
Make sure the expression is a list of expression separated by sep, eg "term1,term2,...
Base class that represents the domain of a function.
virtual size_t size() const =0
Return the number of points in the domain.
A class to store values calculated by a function.
size_t size() const
Return the number of values.
double getCalculated(size_t i) const
Get i-th calculated value.
An interface to a constraint.
virtual void setPenaltyFactor(const double &c)=0
set the penalty factor for the constraint Set panelty factor.
An interface to a function with location, which here means a function for which the user may ask what...
Atribute validator visitor class.
Attribute is a non-fitting parameter.
std::string asUnquotedString() const
Returns a string value that is guarenteed to be unquoted.
void setString(const std::string &str)
Sets new value if attribute is a string.
std::vector< double > asVector() const
Returns vector<double> if attribute is vector<double>, throws exception otherwise.
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
void evaluateValidator() const
Evaluates the validator associated with this attribute. Returns error as a string.
std::string asString() const
Returns string value if attribute is a string, throws exception otherwise.
void setVector(const std::vector< double > &)
Sets new value if attribute is a vector.
T apply(AttributeVisitor< T > &v)
Apply an attribute visitor.
void setDouble(const double &)
Sets new value if attribute is a double.
std::string asQuotedString() const
Returns a string value that is guarenteed to be quoted for use in places where the string is used as ...
void setValidator(const Kernel::IValidator_sptr &validator) const
Set validator to enforce limits on attribute value.
std::string value() const
Returns the attribute value as a string.
void setBool(const bool &)
Sets new value if attribute is a bool.
void fromString(const std::string &str)
Set value from a string.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
bool isEmpty() const
Check if a string attribute is empty.
void setInt(const int &)
Sets new value if attribute is a int.
bool asBool() const
Returns bool value if attribute is a bool, throws exception otherwise.
std::string type() const
Returns type of the attribute.
Const version of AttributeVisitor.
This is an interface to a fitting function - a semi-abstarct class.
virtual void functionDeriv(const FunctionDomain &domain, Jacobian &jacobian)
Derivatives of function with respect to active parameters.
bool hasOrderedTies() const
virtual std::string descriptionOfActive(size_t i) const
Returns the name of active parameter i.
virtual size_t nParams() const =0
Total number of parameters.
void sortTies(const bool checkOnly=false)
Put all ties in order in which they will be applied correctly.
virtual void removeConstraint(const std::string &parName)
Remove a constraint.
bool isActive(size_t i) const
Check if an active parameter i is actually active.
std::string writeTies() const
Write a parameter tie to a string.
void unfixParameter(const std::string &name)
Free a parameter.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
void setProgressReporter(std::shared_ptr< Kernel::ProgressBase > reporter)
Attach a progress reporter.
virtual double getParameter(size_t i) const =0
Get i-th parameter.
double convertValue(double value, Kernel::Unit_sptr &outUnit, const std::shared_ptr< const MatrixWorkspace > &ws, size_t wsIndex) const
Convert a value from one unit (inUnit) to unit defined in workspace (ws)
virtual void clearTies()
Remove all ties.
virtual void clearConstraints()
Remove all constraints.
virtual ~IFunction()
Virtual destructor.
std::vector< double > m_stepSizes
The custom step sizes for the derivative.
void declareAttribute(const std::string &name, const API::IFunction::Attribute &defaultValue)
Declare a single attribute.
virtual std::shared_ptr< IFunction > clone() const
Virtual copy constructor.
void setHandler(std::unique_ptr< FunctionHandler > handler)
Set a function handler.
void storeReadOnlyAttribute(const std::string &name, const API::IFunction::Attribute &value) const
A read-only ("mutable") attribute can be stored in a const method.
double calculateStepSize(size_t parameterIndex, double parameterValue) const
Calculate step size for the given parameter value.
virtual void tie(const std::string &parName, const std::string &expr, bool isDefault=false)
Tie a parameter to other parameters (or a constant)
std::map< std::string, API::IFunction::Attribute > m_attrs
The declared attributes.
virtual void declareAttributes()
Override to declare function attributes.
virtual ParameterStatus getParameterStatus(size_t i) const =0
Get status of parameter.
virtual void setMatrixWorkspace(std::shared_ptr< const API::MatrixWorkspace > workspace, size_t wi, double startX, double endX)
Set matrix workspace.
virtual void setParameter(size_t, const double &value, bool explicitlySet=true)=0
Set i-th parameter.
virtual void applyTies()
Apply the ties.
void checkAttributeName(const std::string &name)
Check Attribute to declare does not already exist.
virtual ParameterTie * getTie(size_t i) const
Get the tie of i-th parameter.
virtual void setStepSizeMethod(const StepSizeMethod method)
Sets the StepSizeMethod to use when calculation the step size.
virtual const std::string category() const
The categories the Fit function belong to.
virtual const std::string categorySeparator() const
Function to return the sperator token for the category string.
virtual std::string writeToString(const std::string &parentLocalAttributesStr="") const
Writes itself into a string.
virtual void setAttribute(const std::string &name, const Attribute &)
Set a value to attribute attName.
void unfixAllDefault()
Free all parameters fixed by default.
virtual size_t getValuesSize(const FunctionDomain &domain) const
Get number of values for a given domain.
virtual std::string nameOfActive(size_t i) const
Returns the name of active parameter i.
void fixAllActive(bool isDefault=false)
Fix all active parameters.
bool cancellationRequestReceived() const
Returns true if a progress reporter is set & evalaution has been requested to stop.
virtual double activeParameter(size_t i) const
Value of i-th active parameter.
virtual size_t getParameterIndex(const ParameterReference &ref) const =0
Return parameter index from a parameter reference.
std::pair< std::size_t, std::string > insertTie(std::unique_ptr< ParameterTie > tie)
Insert a new tie to the correct position.
virtual void setUpForFit()
Set up the function for a fit.
virtual const std::vector< std::string > categories() const
Function to return all of the categories that contain this algorithm.
virtual std::string parameterDescription(size_t i) const =0
Returns the description of parameter i.
void fixParameter(const std::string &name, bool isDefault=false)
Fix a parameter.
virtual std::vector< std::string > getAttributeNames() const
Returns a list of attribute names.
virtual std::string attributeName(size_t index) const
Get name of ith attribute.
void reportProgress(const std::string &msg="") const
Reports progress with an optional message.
virtual void setConstraintPenaltyFactor(const std::string &parName, const double &c)
Set a constraint penalty.
std::vector< ParameterTie * > m_orderedTies
Ties ordered in order of correct application.
virtual void addTies(const std::string &ties, bool isDefault=false)
Add several ties.
std::string asString() const
Writes itself into a string.
void unfix(size_t i)
Restores a declared parameter i to the active status.
virtual std::string parameterName(size_t i) const =0
Returns the name of parameter i.
virtual std::string name() const =0
Returns the function's name.
void setCovarianceMatrix(const std::shared_ptr< Kernel::Matrix< double > > &covar)
Set the covariance matrix.
std::vector< std::unique_ptr< ParameterTie > > m_ties
Holds parameter ties.
void calNumericalDeriv(const FunctionDomain &domain, Jacobian &jacobian)
Calculate numerical derivatives.
std::shared_ptr< Kernel::ProgressBase > m_progReporter
Pointer to the progress handler.
std::vector< std::unique_ptr< IConstraint > > m_constraints
Holds the constraints added to function.
virtual bool hasAttribute(const std::string &name) const
Check if attribute attName exists.
void unfixAll()
Free all parameters.
StepSizeMethod m_stepSizeMethod
The method used to calculate the step size.
virtual void setParameterStatus(size_t i, ParameterStatus status)=0
Change status of parameter.
virtual std::shared_ptr< IFunction > getFunction(size_t i) const
Returns the pointer to i-th child function.
virtual void addTie(std::unique_ptr< ParameterTie > tie)
Add a new tie. Derived classes must provide storage for ties.
virtual std::vector< std::shared_ptr< IFunction > > createEquivalentFunctions() const
Split this function (if needed) into a list of independent functions.
void setCustomStepSizes(const std::vector< double > &stepSizes)
Sets the custom step sizes.
virtual void addConstraints(const std::string &str, bool isDefault=false)
Add a list of conatraints from a string.
void fixAll(bool isDefault=false)
Fix all parameters.
virtual void function(const FunctionDomain &domain, FunctionValues &values) const =0
Evaluates the function for all arguments in the domain.
virtual void registerFunctionUsage(bool internal)
Registers the usage of the algorithm with the UsageService.
virtual size_t parameterIndex(const std::string &name) const =0
Returns the index of parameter name.
std::string writeConstraints() const
Write a parameter constraint to a string.
void setAttributeValue(const std::string &attName, const T &value)
Set an attribute value.
virtual void removeTie(const std::string &parName)
Removes the tie off a parameter.
virtual double getError(size_t i) const =0
Get the fitting error for a parameter.
void storeAttributeValue(const std::string &name, const API::IFunction::Attribute &value)
Store an attribute's value.
virtual void init()
Function initialization. Declare function parameters in this method.
bool isFixedByDefault(size_t i) const
Check if a parameter i is fixed by default (not by user).
std::unique_ptr< ParameterTie > createAndProcessTie(const std::string &parName, const std::string &expr, bool isDefault)
Creates and processes a single tie, handling constant expressions and validation.
virtual void declareParameters()
Override to declare function parameters.
std::vector< std::string > getParameterNames() const
Return a vector with all parameter names.
virtual bool ignoreTie(const ParameterTie &) const
Ignore a tie.
void fix(size_t i, bool isDefault=false)
Removes a parameter i from the list of active.
bool isFixed(size_t i) const
Check if a parameter i is fixed.
virtual void setActiveParameter(size_t i, double value)
Set new value of i-th active parameter.
virtual void addConstraint(std::unique_ptr< IConstraint > ic)
Add a constraint to function.
virtual size_t nAttributes() const
Returns the number of attributes associated with the function.
virtual bool isExplicitlySet(size_t i) const =0
Checks if a parameter has been set explicitly.
virtual IConstraint * getConstraint(size_t i) const
Get constraint of i-th parameter.
std::unique_ptr< FunctionHandler > m_handler
Pointer to a function handler.
virtual size_t getNumberDomains() const
Get number of domains required by this function.
StepSizeMethod
Describes the method in which the step size will be calculated: DEFAULT: Uses the traditional Mantid ...
bool m_isRegistered
whether the function usage has been registered
std::shared_ptr< Kernel::Matrix< double > > m_covar
The covariance matrix of the fitting parameters.
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::string asString(const IFunction *fun=nullptr) const
Return the string that can be used to recreate this tie.
Used to find ParameterTie for a parameter i.
const IFunction & m_fun
The function that has the tie.
bool operator()(const std::unique_ptr< T > &p)
Bracket operator.
ReferenceEqual(const IFunction &fun, size_t i)
Constructor.
const size_t m_i
index to find
Store information about a fitting parameter such as its value if it is constrained or tied.
IValidator is the basic interface for all validators for properties.
virtual IValidator_sptr clone() const =0
Make a copy of the present type of validator.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
virtual bool hasCancellationBeenRequested() const
Override so that the reporter can inform whether a cancellation request has been used.
The concrete, templated class for properties.
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
const TokenVec & asVector()
Returns a vector of tokenized strings.
std::size_t count() const
Get the total number of tokens.
MANTID_API_DLL std::ostream & operator<<(std::ostream &, const AlgorithmHistory &)
Prints a text representation.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Mantid::Kernel::StringTokenizer tokenizer
std::shared_ptr< Parameter > Parameter_sptr
Typedef for the shared pointer.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
bool operator<(const TrackDirection left, const TrackDirection right)
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, const std::string &separator, typename std::enable_if<!(std::is_same< typename std::iterator_traits< ITERATOR_TYPE >::iterator_category, std::random_access_iterator_tag >::value)>::type *=nullptr)
Join a set or vector of (something that turns into a string) together into one string,...
std::unordered_map< UnitParams, double > UnitParametersMap
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Generate a tableworkspace to store the calibration results.
std::string to_string(const wide_integer< Bits, Signed > &n)