35#include <boost/lexical_cast.hpp>
46constexpr double EPSILON = std::numeric_limits<double>::epsilon();
47constexpr double MIN_DOUBLE = std::numeric_limits<double>::min();
48constexpr double STEP_PERCENTAGE = 0.001;
50const auto defaultStepSize = [](
const double parameterValue) ->
double {
51 return fabs(parameterValue) < 100.0 * MIN_DOUBLE / STEP_PERCENTAGE ? 100.0 *
EPSILON
52 : parameterValue * STEP_PERCENTAGE;
55const auto sqrtEpsilonStepSize = [](
const double parameterValue) ->
double {
62using namespace Geometry;
66Kernel::Logger
g_log(
"IFunction");
76 bool operator<(TieNode
const &other)
const {
77 return std::find(other.right.begin(), other.right.end(),
left) != other.right.end();
80const std::vector<std::string> EXCLUDEUSAGE = {
"CompositeFunction"};
86IFunction ::IFunction()
87 : m_isParallel(false), m_handler(nullptr), m_chiSquared(0.0), m_stepSizeFunction(defaultStepSize) {}
98 if (!Kernel::UsageService::Instance().isEnabled()) {
101 if (std::find(EXCLUDEUSAGE.cbegin(), EXCLUDEUSAGE.cend(),
name()) == EXCLUDEUSAGE.cend() && !
m_isRegistered) {
110 auto clonedFunction = FunctionFactory::Instance().createInitialized(this->
asString());
111 for (
size_t i = 0; i < this->
nParams(); i++) {
113 clonedFunction->setError(i,
error);
115 return clonedFunction;
183 if (status ==
Tied) {
199 if (status ==
Tied) {
215 auto newTie = std::make_unique<ParameterTie>(
this, parName, expr, isDefault);
217 if (!isDefault && newTie->isConstant()) {
233void IFunction::tie(
const std::string &parName,
const std::string &expr,
bool isDefault) {
237 addTie(std::move(tiePtr));
251 std::map<size_t, std::pair<size_t, std::string>> oldTies;
256 for (
const auto &t : list) {
257 if (t.name() ==
"=" && t.size() >= 2) {
258 size_t n = t.size() - 1;
259 const std::string expr = t[
n].str();
260 for (
size_t i =
n; i != 0;) {
262 const auto &parName = t[i].name();
267 oldTies[iPar] =
insertTie(std::move(parTie));
275 }
catch (std::runtime_error &) {
276 for (
const auto &[iPar, oldTie] : oldTies) {
277 auto [oldIdx, oldExp] = oldTie;
279 if (!oldExp.empty()) {
302 std::ostringstream tieStream;
304 for (
auto &parTie :
m_ties) {
305 if (parTie->isDefault())
312 tieStream << parTie->asString(
this);
314 return tieStream.str();
324 std::size_t existingTieIndex =
326 [&](
const auto &m_tie) { return getParameterIndex(*m_tie) == iPar; }));
327 std::string oldExp =
"";
328 const auto oldTie =
getTie(iPar);
330 const auto oldTieStr = oldTie->asString();
331 oldExp = oldTieStr.substr(oldTieStr.find(
"=") + 1);
334 if (existingTieIndex <
m_ties.size()) {
335 m_ties[existingTieIndex] = std::move(
tie);
342 return {existingTieIndex, oldExp};
344 return {existingTieIndex,
""};
355 const auto [oldIdx, oldExp] =
insertTie(std::move(
tie));
360 }
catch (std::runtime_error &) {
362 if (!oldExp.empty()) {
386 for (
auto &parTie :
m_ties) {
416 throw std::out_of_range(
"Function parameter index out of range.");
434 if (it !=
m_ties.cend()) {
443 for (
size_t i = 0; i <
nParams(); ++i) {
453 size_t iPar = ic->parameterIndex();
455 [&iPar](
const auto &constraint) { return constraint->parameterIndex() == iPar; });
482 [&iPar](
const auto &constraint) { return iPar == constraint->getLocalIndex(); });
495 [&iPar](
const auto &constraint) { return iPar == constraint->getLocalIndex(); });
498 (*it)->setPenaltyFactor(c);
500 g_log.
warning() << parName <<
" does not have constraint so setConstraintPenaltyFactor failed"
510 constraint->setParamToSatisfyConstraint();
517 std::ostringstream stream;
520 if (constrint->isDefault())
527 stream << constrint->asString();
547 std::ostringstream ostr;
548 ostr <<
"name=" << this->
name();
551 for (
const auto &attName : attr) {
553 if (!attValue.empty() && attValue !=
"\"\"") {
554 ostr <<
',' << attName <<
'=' << attValue;
557 std::vector<std::string> ties;
559 for (
size_t i = 0; i <
nParams(); i++) {
560 std::ostringstream paramOut;
562 ostr <<
',' << paramOut.str();
565 ties.emplace_back(paramOut.str());
572 if (!constraints.empty()) {
573 ostr <<
",constraints=(" << constraints <<
")";
578 if (!tiesString.empty()) {
579 ties.emplace_back(tiesString);
586 ostr << parentLocalAttributesStr;
600 for (
auto it = list.
begin(); it != list.
end(); ++it) {
602 if (expr.terms()[0].str().compare(
"penalty") == 0) {
605 if ((it + 1) != list.
end()) {
606 auto next_expr = *(it + 1);
607 if (next_expr.terms()[0].str().compare(
"penalty") == 0) {
608 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
609 double penalty_factor = std::stof(next_expr.terms()[1].str(), NULL);
610 c->setPenaltyFactor(penalty_factor);
613 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
617 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
627 std::vector<std::string> out;
628 for (
size_t i = 0; i <
nParams(); ++i) {
638 if (handler && handler->function().get() !=
this) {
639 throw std::runtime_error(
"Function handler points to a different function");
671 std::string apply(
const std::string & )
const override {
return "std::string"; }
673 std::string apply(
const int & )
const override {
return "int"; }
675 std::string apply(
const double & )
const override {
return "double"; }
677 std::string apply(
const bool & )
const override {
return "bool"; }
679 std::string apply(
const std::vector<double> & )
const override {
return "std::vector<double>"; }
694 explicit AttValue(
bool quoteString =
false)
699 std::string apply(
const std::string &str)
const override {
700 return (
m_quoteString) ? std::string(
"\"" + str +
"\"") : str;
703 std::string apply(
const int &i)
const override {
return std::to_string(i); }
705 std::string apply(
const double &d)
const override {
return boost::lexical_cast<std::string>(d); }
707 std::string apply(
const bool &b)
const override {
return b ?
"true" :
"false"; }
709 std::string apply(
const std::vector<double> &v)
const override {
710 std::string res =
"(";
712 for (
size_t i = 0; i < v.size() - 1; ++i) {
713 res += boost::lexical_cast<std::string>(v[i]) +
",";
715 res += boost::lexical_cast<std::string>(v.back());
728 AttValue
tmp(m_quoteValue);
737 return asQuotedString();
740 return boost::get<std::string>(
m_data);
742 throw std::runtime_error(
"Trying to access a " + type() +
755 attr = boost::get<std::string>(
m_data);
757 throw std::runtime_error(
"Trying to access a " + type() +
765 std::string quoted(attr);
766 if (*(attr.begin()) !=
'\"')
767 quoted =
"\"" + attr;
768 if (*(quoted.end() - 1) !=
'\"')
781 attr = boost::get<std::string>(
m_data);
783 throw std::runtime_error(
"Trying to access a " + type() +
787 std::string unquoted(attr);
790 if (*(attr.begin()) ==
'\"')
791 unquoted = std::string(attr.begin() + 1, attr.end() - 1);
792 if (*(unquoted.end() - 1) ==
'\"')
793 unquoted.resize(unquoted.size() - 1);
803 return boost::get<int>(
m_data);
805 throw std::runtime_error(
"Trying to access a " + type() +
816 return boost::get<double>(
m_data);
818 throw std::runtime_error(
"Trying to access a " + type() +
829 return boost::get<bool>(
m_data);
831 throw std::runtime_error(
"Trying to access a " + type() +
842 return boost::get<std::vector<double>>(
m_data);
844 throw std::runtime_error(
"Trying to access a " + type() +
855 evaluateValidator(str);
858 boost::get<std::string>(
m_data) = str;
860 throw std::runtime_error(
"Trying to access a " + type() +
871 evaluateValidator(
d);
874 boost::get<double>(
m_data) =
d;
876 throw std::runtime_error(
"Trying to access a " + type() +
887 evaluateValidator(i);
890 boost::get<int>(
m_data) = i;
892 throw std::runtime_error(
"Trying to access a " + type() +
903 evaluateValidator(b);
906 boost::get<bool>(
m_data) = b;
908 throw std::runtime_error(
"Trying to access a " + type() +
920 evaluateValidator(v);
923 auto &data = boost::get<std::vector<double>>(
m_data);
924 data.assign(v.begin(), v.end());
926 throw std::runtime_error(
"Trying to access a " + type() +
935 return boost::get<std::string>(
m_data).empty();
937 throw std::runtime_error(
"Trying to access a " + type() +
" attribute as string");
957 void apply(std::string &str)
const override {
962 void apply(
int &i)
const override {
965 std::istringstream istr(
m_value +
" ");
968 throw std::invalid_argument(
"Failed to set int attribute "
972 evaluateValidator(tempi);
976 void apply(
double &d)
const override {
979 std::istringstream istr(
m_value +
" ");
982 throw std::invalid_argument(
"Failed to set double attribute "
986 evaluateValidator(tempd);
990 void apply(
bool &b)
const override {
994 evaluateValidator(tempb);
999 void apply(std::vector<double> &v)
const override {
1011 Kernel::StringTokenizer
tokenizer(
m_value,
",", Kernel::StringTokenizer::TOK_TRIM);
1016 std::vector<double> tempVec(newSize);
1018 for (
size_t i = 0; i < tempVec.size(); ++i) {
1019 tempVec[i] = boost::lexical_cast<double>(tokenizer[i]);
1021 evaluateValidator(tempVec);
1025 for (
size_t i = 0; i < v.size(); ++i) {
1026 v[i] = boost::lexical_cast<double>(tokenizer[i]);
1031 template <
typename T>
void evaluateValidator(T &inputData)
const {
1033 IFunction::ValidatorEvaluator::evaluate(inputData,
m_validator);
1065 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1074 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1085 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1096 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1114 const size_t nParam =
nParams();
1124 nData = minusStep.
size();
1128 for (
size_t iP = 0; iP < nParam; iP++) {
1133 const double paramPstep = val + step;
1140 step = paramPstep - val;
1141 for (
size_t i = 0; i < nData; i++) {
1166 throw std::invalid_argument(
"An invalid method for calculating the step size was provided.");
1187 const auto ¶mMap =
workspace->constInstrumentParameters();
1190 size_t numDetectors =
workspace->getSpectrum(wi).getDetectorIDs().size();
1191 if (numDetectors > 1) {
1196 auto firstDetectorId = *
workspace->getSpectrum(wi).getDetectorIDs().begin();
1198 const auto &detectorInfo =
workspace->detectorInfo();
1199 const auto detectorIndex = detectorInfo.indexOf(firstDetectorId);
1200 const auto &detector = detectorInfo.detector(
detectorIndex);
1201 detectorPtr = &detector;
1204 const auto &spectrumInfo =
workspace->spectrumInfo();
1205 const auto &detector = spectrumInfo.detector(wi);
1206 detectorPtr = &detector;
1209 for (
size_t i = 0; i <
nParams(); i++) {
1218 if (
name() == fitParam.getFunction()) {
1221 if (testWithLocation ==
nullptr ||
1222 (!fitParam.getLookUpTable().containData() && fitParam.getFormula().empty())) {
1225 double centreValue = testWithLocation->centre();
1228 if (fitParam.getFormula().empty())
1229 centreUnit = fitParam.getLookUpTable().getXUnit();
1231 if (!fitParam.getFormulaUnit().empty()) {
1233 centreUnit = Kernel::UnitFactory::Instance().create(fitParam.getFormulaUnit());
1235 g_log.
warning() << fitParam.getFormulaUnit() <<
" Is not an recognised formula unit for parameter "
1236 << fitParam.getName() <<
"\n";
1245 <<
" centre of peak before any unit conversion is " << centreValue <<
'\n';
1248 <<
" centre of peak after any unit conversion is " << centreValue <<
'\n';
1251 double paramValue = fitParam.getValue(centreValue);
1258 if (fitParam.getFormula().empty()) {
1262 <<
" before y-unit conversion\n";
1265 <<
" after y-unit conversion\n";
1269 std::string resultUnitStr = fitParam.getResultUnit();
1271 if (!resultUnitStr.empty()) {
1272 std::vector<std::string> allUnitStr = Kernel::UnitFactory::Instance().getKeys();
1273 for (
auto &iUnit : allUnitStr) {
1274 size_t found = resultUnitStr.find(iUnit);
1275 if (found != std::string::npos) {
1276 size_t len = iUnit.size();
1277 std::stringstream readDouble;
1280 resultUnitStr.replace(found, len, readDouble.str());
1286 p.SetExpr(resultUnitStr);
1288 <<
" before result-unit conversion (using " << resultUnitStr <<
")\n";
1289 paramValue *= p.Eval();
1291 <<
" after result-unit conversion\n";
1292 }
catch (mu::Parser::exception_type &e) {
1293 g_log.
error() <<
"Cannot convert formula unit to workspace unit"
1294 <<
" Formula unit which cannot be passed is " << resultUnitStr
1295 <<
". Muparser error message is: " << e.GetMsg() <<
'\n';
1306 if (!fitParam.getTie().empty()) {
1307 std::ostringstream str;
1314 if (!fitParam.getConstraint().empty()) {
1315 IConstraint *constraint = ConstraintFactory::Instance().createInitialized(
this, fitParam.getConstraint());
1316 if (!fitParam.getConstraintPenaltyFactor().empty()) {
1318 double penalty = std::stod(fitParam.getConstraintPenaltyFactor());
1321 g_log.
warning() <<
"Can't set penalty factor for constraint\n";
1343 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1345 const auto &wsUnit = ws->getAxis(0)->unit();
1346 if (outUnit->unitID() == wsUnit->unitID())
1351 double factor(0.0), power(0.0);
1352 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1353 return factor * std::pow(
value, power);
1355 std::vector<double> singleValue(1,
value);
1357 return singleValue.front();
1370 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1372 const auto &wsUnit = ws->getAxis(0)->unit();
1373 if (outUnit->unitID() == wsUnit->unitID())
1377 double factor, power;
1378 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1379 auto iend = values.end();
1380 for (
auto itr = values.begin(); itr != iend; ++itr)
1381 (*itr) = factor * std::pow(*itr, power);
1386 if (sample ==
nullptr) {
1387 g_log.
error() <<
"No sample defined instrument. Cannot convert units for function\n"
1388 <<
"Ignore conversion.";
1391 const auto &spectrumInfo = ws->spectrumInfo();
1392 double l1 = spectrumInfo.l1();
1394 auto emode = ws->getEMode();
1397 spectrumInfo.getDetectorValues(*wsUnit, *outUnit, emode,
false, wsIndex,
pmap);
1399 std::vector<double> emptyVec;
1400 wsUnit->toTOF(values, emptyVec, l1, emode,
pmap);
1401 outUnit->fromTOF(values, emptyVec, l1, emode,
pmap);
1402 }
catch (std::exception &) {
1403 throw std::runtime_error(
"Unable to perform unit conversion to " + outUnit->unitID());
1422 std::string str(
value);
1439 throw std::runtime_error(
"Function " +
name() +
" doesn't have children.");
1444 std::vector<std::string> names;
1459 throw std::out_of_range(
"Function attribute index out of range.");
1473 throw std::invalid_argument(
"ParamFunctionAttributeHolder::getAttribute - Unknown attribute '" +
name +
"'");
1522 std::ostringstream msg;
1523 msg <<
"Attribute (" <<
name <<
") already exists.";
1524 throw std::invalid_argument(msg.str());
1543 value.setValidator(validatorClone);
1544 value.evaluateValidator();
1548 throw std::invalid_argument(
"ParamFunctionAttributeHolder::setAttribute - Unknown attribute '" +
name +
"'");
1574 throw std::invalid_argument(
"IFunction: Cannot set an empty covariance matrix");
1577 if (covar->numRows() !=
nParams() || covar->numCols() !=
nParams()) {
1578 throw std::invalid_argument(
"IFunction: Covariance matrix has a wrong size");
1605 for (
size_t i = 0; i <
nParams(); ++i) {
1614 for (
size_t i = 0; i <
nParams(); ++i) {
1623 for (
size_t i = 0; i <
nParams(); ++i) {
1636 for (
size_t i = 0; i <
nParams(); ++i) {
1655 return std::vector<IFunction_sptr>(1, FunctionFactory::Instance().createInitialized(
asString()));
1666 std::list<TieNode> orderedTieNodes;
1667 for (
size_t i = 0; i <
nParams(); ++i) {
1668 auto const parTie =
getTie(i);
1675 auto const rhsParameters = parTie->getRHSParameters();
1676 newNode.right.reserve(rhsParameters.size());
1677 for (
auto &&p : rhsParameters) {
1680 if (newNode < newNode) {
1681 throw std::runtime_error(
"Parameter is tied to itself: " + parTie->asString(
this));
1683 bool before(
false), after(
false);
1684 size_t indexBefore(0), indexAfter(0);
1685 for (
auto &&node : orderedTieNodes) {
1686 if (newNode < node) {
1688 indexBefore = node.left;
1690 if (node < newNode) {
1692 indexAfter = node.left;
1697 std::string message =
"Circular dependency in ties:\n" + parTie->asString(
this) +
'\n';
1699 if (indexAfter != indexBefore) {
1702 throw std::runtime_error(message);
1704 orderedTieNodes.push_front(newNode);
1706 orderedTieNodes.emplace_back(newNode);
1710 for (
auto &&node : orderedTieNodes) {
1711 auto const parTie =
getTie(node.left);
1723MANTID_API_DLL std::shared_ptr<Mantid::API::IFunction>
1724IPropertyManager::getValue<std::shared_ptr<Mantid::API::IFunction>>(
const std::string &
name)
const {
1729 std::string message =
"Attempt to assign property " +
name +
" to incorrect type. Expected shared_ptr<IFunction>.";
1730 throw std::runtime_error(message);
1735MANTID_API_DLL std::shared_ptr<const Mantid::API::IFunction>
1736IPropertyManager::getValue<std::shared_ptr<const Mantid::API::IFunction>>(
const std::string &
name)
const {
1738 dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>
> *>(getPointerToProperty(
name));
1740 return prop->operator()();
1742 std::string message =
1743 "Attempt to assign property " +
name +
" to incorrect type. Expected const shared_ptr<IFunction>.";
1744 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.
std::function< double(const double)> m_stepSizeFunction
The function used to calculate the step size.
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.
double calculateStepSize(const double parameterValue) const
Calculate step size for the given parameter value.
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.
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.
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.
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.
virtual 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.
Interface class for detector objects.
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.
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.
DLLExport 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)