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() : m_isParallel(false), m_handler(nullptr), m_chiSquared(0.0) {}
97 if (!Kernel::UsageService::Instance().isEnabled()) {
100 if (std::find(EXCLUDEUSAGE.cbegin(), EXCLUDEUSAGE.cend(),
name()) == EXCLUDEUSAGE.cend() && !
m_isRegistered) {
109 auto clonedFunction = FunctionFactory::Instance().createInitialized(this->
asString());
110 for (
size_t i = 0; i < this->
nParams(); i++) {
112 clonedFunction->setError(i,
error);
114 return clonedFunction;
188 if (status ==
Tied) {
204 if (status ==
Tied) {
220 auto newTie = std::make_unique<ParameterTie>(
this, parName, expr, isDefault);
222 if (!isDefault && newTie->isConstant()) {
238void IFunction::tie(
const std::string &parName,
const std::string &expr,
bool isDefault) {
242 addTie(std::move(tiePtr));
256 std::map<size_t, std::pair<size_t, std::string>> oldTies;
261 for (
const auto &t : list) {
262 if (t.name() ==
"=" && t.size() >= 2) {
263 size_t n = t.size() - 1;
264 const std::string expr = t[
n].str();
265 for (
size_t i =
n; i != 0;) {
267 const auto &parName = t[i].name();
272 oldTies[iPar] =
insertTie(std::move(parTie));
280 }
catch (std::runtime_error &) {
281 for (
const auto &[iPar, oldTie] : oldTies) {
282 auto [oldIdx, oldExp] = oldTie;
284 if (!oldExp.empty()) {
307 std::ostringstream tieStream;
309 for (
auto &parTie :
m_ties) {
310 if (parTie->isDefault())
317 tieStream << parTie->asString(
this);
319 return tieStream.str();
329 std::size_t existingTieIndex =
331 [&](
const auto &m_tie) { return getParameterIndex(*m_tie) == iPar; }));
332 std::string oldExp =
"";
333 const auto oldTie =
getTie(iPar);
335 const auto oldTieStr = oldTie->asString();
336 oldExp = oldTieStr.substr(oldTieStr.find(
"=") + 1);
339 if (existingTieIndex <
m_ties.size()) {
340 m_ties[existingTieIndex] = std::move(
tie);
347 return {existingTieIndex, oldExp};
349 return {existingTieIndex,
""};
360 const auto [oldIdx, oldExp] =
insertTie(std::move(
tie));
365 }
catch (std::runtime_error &) {
367 if (!oldExp.empty()) {
391 for (
auto &parTie :
m_ties) {
421 throw std::out_of_range(
"Function parameter index out of range.");
439 if (it !=
m_ties.cend()) {
448 for (
size_t i = 0; i <
nParams(); ++i) {
458 size_t iPar = ic->parameterIndex();
460 [&iPar](
const auto &constraint) { return constraint->parameterIndex() == iPar; });
487 [&iPar](
const auto &constraint) { return iPar == constraint->getLocalIndex(); });
500 [&iPar](
const auto &constraint) { return iPar == constraint->getLocalIndex(); });
503 (*it)->setPenaltyFactor(c);
505 g_log.
warning() << parName <<
" does not have constraint so setConstraintPenaltyFactor failed"
515 constraint->setParamToSatisfyConstraint();
522 std::ostringstream stream;
525 if (constrint->isDefault())
532 stream << constrint->asString();
552 std::ostringstream ostr;
553 ostr <<
"name=" << this->
name();
556 for (
const auto &attName : attr) {
558 if (!attValue.empty() && attValue !=
"\"\"") {
559 ostr <<
',' << attName <<
'=' << attValue;
562 std::vector<std::string> ties;
564 for (
size_t i = 0; i <
nParams(); i++) {
565 std::ostringstream paramOut;
567 ostr <<
',' << paramOut.str();
570 ties.emplace_back(paramOut.str());
577 if (!constraints.empty()) {
578 ostr <<
",constraints=(" << constraints <<
")";
583 if (!tiesString.empty()) {
584 ties.emplace_back(tiesString);
591 ostr << parentLocalAttributesStr;
605 for (
auto it = list.
begin(); it != list.
end(); ++it) {
607 if (expr.terms()[0].str().compare(
"penalty") == 0) {
610 if ((it + 1) != list.
end()) {
611 auto next_expr = *(it + 1);
612 if (next_expr.terms()[0].str().compare(
"penalty") == 0) {
613 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
614 double penalty_factor = std::stof(next_expr.terms()[1].str(), NULL);
615 c->setPenaltyFactor(penalty_factor);
618 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
622 auto c = std::unique_ptr<IConstraint>(ConstraintFactory::Instance().createInitialized(
this, expr, isDefault));
632 std::vector<std::string> out;
633 for (
size_t i = 0; i <
nParams(); ++i) {
643 if (handler && handler->function().get() !=
this) {
644 throw std::runtime_error(
"Function handler points to a different function");
676 std::string apply(
const std::string & )
const override {
return "std::string"; }
678 std::string apply(
const int & )
const override {
return "int"; }
680 std::string apply(
const double & )
const override {
return "double"; }
682 std::string apply(
const bool & )
const override {
return "bool"; }
684 std::string apply(
const std::vector<double> & )
const override {
return "std::vector<double>"; }
699 explicit AttValue(
bool quoteString =
false)
704 std::string apply(
const std::string &str)
const override {
705 return (
m_quoteString) ? std::string(
"\"" + str +
"\"") : str;
708 std::string apply(
const int &i)
const override {
return std::to_string(i); }
710 std::string apply(
const double &d)
const override {
return boost::lexical_cast<std::string>(d); }
712 std::string apply(
const bool &b)
const override {
return b ?
"true" :
"false"; }
714 std::string apply(
const std::vector<double> &v)
const override {
715 std::string res =
"(";
717 for (
size_t i = 0; i < v.size() - 1; ++i) {
718 res += boost::lexical_cast<std::string>(v[i]) +
",";
720 res += boost::lexical_cast<std::string>(v.back());
733 AttValue
tmp(m_quoteValue);
742 return asQuotedString();
745 return boost::get<std::string>(
m_data);
747 throw std::runtime_error(
"Trying to access a " + type() +
760 attr = boost::get<std::string>(
m_data);
762 throw std::runtime_error(
"Trying to access a " + type() +
770 std::string quoted(attr);
771 if (*(attr.begin()) !=
'\"')
772 quoted =
"\"" + attr;
773 if (*(quoted.end() - 1) !=
'\"')
786 attr = boost::get<std::string>(
m_data);
788 throw std::runtime_error(
"Trying to access a " + type() +
792 std::string unquoted(attr);
795 if (*(attr.begin()) ==
'\"')
796 unquoted = std::string(attr.begin() + 1, attr.end() - 1);
797 if (*(unquoted.end() - 1) ==
'\"')
798 unquoted.resize(unquoted.size() - 1);
808 return boost::get<int>(
m_data);
810 throw std::runtime_error(
"Trying to access a " + type() +
821 return boost::get<double>(
m_data);
823 throw std::runtime_error(
"Trying to access a " + type() +
834 return boost::get<bool>(
m_data);
836 throw std::runtime_error(
"Trying to access a " + type() +
847 return boost::get<std::vector<double>>(
m_data);
849 throw std::runtime_error(
"Trying to access a " + type() +
860 evaluateValidator(str);
863 boost::get<std::string>(
m_data) = str;
865 throw std::runtime_error(
"Trying to access a " + type() +
876 evaluateValidator(
d);
879 boost::get<double>(
m_data) =
d;
881 throw std::runtime_error(
"Trying to access a " + type() +
892 evaluateValidator(i);
895 boost::get<int>(
m_data) = i;
897 throw std::runtime_error(
"Trying to access a " + type() +
908 evaluateValidator(b);
911 boost::get<bool>(
m_data) = b;
913 throw std::runtime_error(
"Trying to access a " + type() +
925 evaluateValidator(v);
928 auto &data = boost::get<std::vector<double>>(
m_data);
929 data.assign(v.begin(), v.end());
931 throw std::runtime_error(
"Trying to access a " + type() +
940 return boost::get<std::string>(
m_data).empty();
942 throw std::runtime_error(
"Trying to access a " + type() +
" attribute as string");
962 void apply(std::string &str)
const override {
967 void apply(
int &i)
const override {
970 std::istringstream istr(
m_value +
" ");
973 throw std::invalid_argument(
"Failed to set int attribute "
977 evaluateValidator(tempi);
981 void apply(
double &d)
const override {
984 std::istringstream istr(
m_value +
" ");
987 throw std::invalid_argument(
"Failed to set double attribute "
991 evaluateValidator(tempd);
995 void apply(
bool &b)
const override {
999 evaluateValidator(tempb);
1004 void apply(std::vector<double> &v)
const override {
1016 Kernel::StringTokenizer
tokenizer(
m_value,
",", Kernel::StringTokenizer::TOK_TRIM);
1021 std::vector<double> tempVec(newSize);
1023 for (
size_t i = 0; i < tempVec.size(); ++i) {
1024 tempVec[i] = boost::lexical_cast<double>(tokenizer[i]);
1026 evaluateValidator(tempVec);
1030 for (
size_t i = 0; i < v.size(); ++i) {
1031 v[i] = boost::lexical_cast<double>(tokenizer[i]);
1036 template <
typename T>
void evaluateValidator(T &inputData)
const {
1038 IFunction::ValidatorEvaluator::evaluate(inputData,
m_validator);
1070 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1079 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1090 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1101 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1119 const size_t nParam =
nParams();
1129 nData = minusStep.
size();
1133 for (
size_t iP = 0; iP < nParam; iP++) {
1138 const double paramPstep = val + step;
1145 step = paramPstep - val;
1146 for (
size_t i = 0; i < nData; i++) {
1161 return defaultStepSize(parameterValue);
1163 return sqrtEpsilonStepSize(parameterValue);
1167 throw std::invalid_argument(
"An invalid method for calculating the step size was provided.");
1193 const auto ¶mMap =
workspace->constInstrumentParameters();
1196 size_t numDetectors =
workspace->getSpectrum(wi).getDetectorIDs().size();
1197 if (numDetectors > 1) {
1203 const auto &detectorInfo =
workspace->detectorInfo();
1204 const auto &specDef =
workspace->spectrumInfo().spectrumDefinition(wi);
1205 for (
size_t k = 0; k < specDef.size(); ++k) {
1208 detectorPtr = &detectorInfo.detector(specDef[k].first);
1216 <<
" as none of the detector ids can be found on the instrument\n";
1221 const auto &spectrumInfo =
workspace->spectrumInfo();
1222 if (!spectrumInfo.hasDetectors(wi)) {
1224 <<
" as no detector ids can be found for this workspace on the instrument\n";
1228 detectorPtr = &spectrumInfo.detector(wi);
1233 <<
" as the detector id for this workspace can't be found on the instrument\n";
1238 for (
size_t i = 0; i <
nParams(); i++) {
1244 paramMap.getRecursiveFittingParameter(detectorPtr,
parameterName(i), this->
name());
1247 param = paramMap.getRecursive(detectorPtr,
parameterName(i),
"fitting");
1255 if (
name() == fitParam.getFunction()) {
1258 if (testWithLocation ==
nullptr ||
1259 (!fitParam.getLookUpTable().containData() && fitParam.getFormula().empty())) {
1262 double centreValue = testWithLocation->centre();
1265 if (fitParam.getFormula().empty())
1266 centreUnit = fitParam.getLookUpTable().getXUnit();
1268 if (!fitParam.getFormulaUnit().empty()) {
1270 centreUnit = Kernel::UnitFactory::Instance().create(fitParam.getFormulaUnit());
1272 g_log.
warning() << fitParam.getFormulaUnit() <<
" Is not an recognised formula unit for parameter "
1273 << fitParam.getName() <<
"\n";
1282 <<
" centre of peak before any unit conversion is " << centreValue <<
'\n';
1285 <<
" centre of peak after any unit conversion is " << centreValue <<
'\n';
1288 double paramValue = fitParam.getValue(centreValue);
1295 if (fitParam.getFormula().empty()) {
1299 <<
" before y-unit conversion\n";
1302 <<
" after y-unit conversion\n";
1306 std::string resultUnitStr = fitParam.getResultUnit();
1308 if (!resultUnitStr.empty()) {
1309 std::vector<std::string> allUnitStr = Kernel::UnitFactory::Instance().getKeys();
1310 for (
auto &iUnit : allUnitStr) {
1311 size_t found = resultUnitStr.find(iUnit);
1312 if (found != std::string::npos) {
1313 size_t len = iUnit.size();
1314 std::stringstream readDouble;
1317 resultUnitStr.replace(found, len, readDouble.str());
1323 p.SetExpr(resultUnitStr);
1325 <<
" before result-unit conversion (using " << resultUnitStr <<
")\n";
1326 paramValue *= p.Eval();
1328 <<
" after result-unit conversion\n";
1329 }
catch (mu::Parser::exception_type &e) {
1330 g_log.
error() <<
"Cannot convert formula unit to workspace unit"
1331 <<
" Formula unit which cannot be passed is " << resultUnitStr
1332 <<
". Muparser error message is: " << e.GetMsg() <<
'\n';
1343 if (!fitParam.getTie().empty()) {
1344 std::ostringstream str;
1351 if (!fitParam.getConstraint().empty()) {
1352 IConstraint *constraint = ConstraintFactory::Instance().createInitialized(
this, fitParam.getConstraint());
1353 if (!fitParam.getConstraintPenaltyFactor().empty()) {
1355 double penalty = std::stod(fitParam.getConstraintPenaltyFactor());
1358 g_log.
warning() <<
"Can't set penalty factor for constraint\n";
1380 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1382 const auto &wsUnit = ws->getAxis(0)->unit();
1383 if (outUnit->unitID() == wsUnit->unitID())
1388 double factor(0.0), power(0.0);
1389 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1390 return factor * std::pow(
value, power);
1392 std::vector<double> singleValue(1,
value);
1394 return singleValue.front();
1407 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1409 const auto &wsUnit = ws->getAxis(0)->unit();
1410 if (outUnit->unitID() == wsUnit->unitID())
1414 double factor, power;
1415 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1416 auto iend = values.end();
1417 for (
auto itr = values.begin(); itr !=
iend; ++itr)
1418 (*itr) = factor * std::pow(*itr, power);
1423 if (sample ==
nullptr) {
1424 g_log.
error() <<
"No sample defined instrument. Cannot convert units for function\n"
1425 <<
"Ignore conversion.";
1428 const auto &spectrumInfo = ws->spectrumInfo();
1429 double l1 = spectrumInfo.l1();
1431 auto emode = ws->getEMode();
1434 spectrumInfo.getDetectorValues(*wsUnit, *outUnit, emode,
false, wsIndex,
pmap);
1436 std::vector<double> emptyVec;
1437 wsUnit->toTOF(values, emptyVec, l1, emode,
pmap);
1438 outUnit->fromTOF(values, emptyVec, l1, emode,
pmap);
1439 }
catch (std::exception &) {
1440 throw std::runtime_error(
"Unable to perform unit conversion to " + outUnit->unitID());
1459 std::string str(
value);
1476 throw std::runtime_error(
"Function " +
name() +
" doesn't have children.");
1481 std::vector<std::string> names;
1496 throw std::out_of_range(
"Function attribute index out of range.");
1510 throw std::invalid_argument(
"ParamFunctionAttributeHolder::getAttribute - Unknown attribute '" +
name +
"'");
1559 std::ostringstream msg;
1560 msg <<
"Attribute (" <<
name <<
") already exists.";
1561 throw std::invalid_argument(msg.str());
1580 value.setValidator(validatorClone);
1581 value.evaluateValidator();
1585 throw std::invalid_argument(
"ParamFunctionAttributeHolder::setAttribute - Unknown attribute '" +
name +
"'");
1611 throw std::invalid_argument(
"IFunction: Cannot set an empty covariance matrix");
1614 if (covar->numRows() !=
nParams() || covar->numCols() !=
nParams()) {
1615 throw std::invalid_argument(
"IFunction: Covariance matrix has a wrong size");
1642 for (
size_t i = 0; i <
nParams(); ++i) {
1651 for (
size_t i = 0; i <
nParams(); ++i) {
1660 for (
size_t i = 0; i <
nParams(); ++i) {
1673 for (
size_t i = 0; i <
nParams(); ++i) {
1692 return std::vector<IFunction_sptr>(1, FunctionFactory::Instance().createInitialized(
asString()));
1703 std::list<TieNode> orderedTieNodes;
1704 for (
size_t i = 0; i <
nParams(); ++i) {
1705 auto const parTie =
getTie(i);
1712 auto const rhsParameters = parTie->getRHSParameters();
1713 newNode.right.reserve(rhsParameters.size());
1714 for (
auto &&p : rhsParameters) {
1717 if (newNode < newNode) {
1718 throw std::runtime_error(
"Parameter is tied to itself: " + parTie->asString(
this));
1720 bool before(
false), after(
false);
1721 size_t indexBefore(0), indexAfter(0);
1722 for (
auto &&node : orderedTieNodes) {
1723 if (newNode < node) {
1725 indexBefore = node.left;
1727 if (node < newNode) {
1729 indexAfter = node.left;
1734 std::string message =
"Circular dependency in ties:\n" + parTie->asString(
this) +
'\n';
1736 if (indexAfter != indexBefore) {
1739 throw std::runtime_error(message);
1741 orderedTieNodes.push_front(newNode);
1743 orderedTieNodes.emplace_back(newNode);
1747 for (
auto &&node : orderedTieNodes) {
1748 auto const parTie =
getTie(node.left);
1760MANTID_API_DLL std::shared_ptr<Mantid::API::IFunction>
1761IPropertyManager::getValue<std::shared_ptr<Mantid::API::IFunction>>(
const std::string &
name)
const {
1766 std::string message =
"Attempt to assign property " +
name +
" to incorrect type. Expected shared_ptr<IFunction>.";
1767 throw std::runtime_error(message);
1772MANTID_API_DLL std::shared_ptr<const Mantid::API::IFunction>
1773IPropertyManager::getValue<std::shared_ptr<const Mantid::API::IFunction>>(
const std::string &
name)
const {
1775 dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>
> *>(getPointerToProperty(
name));
1777 return prop->operator()();
1779 std::string message =
1780 "Attempt to assign property " +
name +
" to incorrect type. Expected const shared_ptr<IFunction>.";
1781 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.
Interface class for detector objects.
Exception for when an item is not found in a collection.
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.
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)