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) {}
101 if (std::find(EXCLUDEUSAGE.cbegin(), EXCLUDEUSAGE.cend(),
name()) == EXCLUDEUSAGE.cend() && !
m_isRegistered) {
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) {
214void IFunction::tie(
const std::string &parName,
const std::string &expr,
bool isDefault) {
215 auto ti = std::make_unique<ParameterTie>(
this, parName, expr, isDefault);
216 if (!isDefault && ti->isConstant()) {
237 for (
const auto &t : list) {
238 if (t.name() ==
"=" && t.size() >= 2) {
239 size_t n = t.size() - 1;
240 const std::string
value = t[
n].str();
241 for (
size_t i =
n; i != 0;) {
262 std::ostringstream tieStream;
265 if (
tie->isDefault())
272 tieStream <<
tie->asString(
this);
274 return tieStream.str();
285 std::find_if(
m_ties.begin(),
m_ties.end(), [&](
const auto &m_tie) { return getParameterIndex(*m_tie) == iPar; });
288 *it = std::move(
tie);
340 throw std::out_of_range(
"Function parameter index out of range.");
358 if (it !=
m_ties.cend()) {
367 for (
size_t i = 0; i <
nParams(); ++i) {
377 size_t iPar = ic->parameterIndex();
379 [&iPar](
const auto &constraint) { return constraint->parameterIndex() == iPar; });
406 if (iPar == (**it).getLocalIndex()) {
420 [&iPar](
const auto &constraint) { return iPar == constraint->getLocalIndex(); });
423 (*it)->setPenaltyFactor(c);
425 g_log.
warning() << parName <<
" does not have constraint so setConstraintPenaltyFactor failed"
435 constraint->setParamToSatisfyConstraint();
442 std::ostringstream stream;
445 if (constrint->isDefault())
452 stream << constrint->asString();
472 std::ostringstream ostr;
473 ostr <<
"name=" << this->
name();
476 for (
const auto &attName : attr) {
478 if (!attValue.empty() && attValue !=
"\"\"") {
479 ostr <<
',' << attName <<
'=' << attValue;
482 std::vector<std::string> ties;
484 for (
size_t i = 0; i <
nParams(); i++) {
485 std::ostringstream paramOut;
487 ostr <<
',' << paramOut.str();
490 ties.emplace_back(paramOut.str());
497 if (!constraints.empty()) {
498 ostr <<
",constraints=(" << constraints <<
")";
503 if (!tiesString.empty()) {
504 ties.emplace_back(tiesString);
511 ostr << parentLocalAttributesStr;
525 for (
auto it = list.
begin(); it != list.
end(); ++it) {
527 if (expr.terms()[0].str().compare(
"penalty") == 0) {
530 if ((it + 1) != list.
end()) {
531 auto next_expr = *(it + 1);
532 if (next_expr.terms()[0].str().compare(
"penalty") == 0) {
534 double penalty_factor = std::stof(next_expr.terms()[1].str(), NULL);
535 c->setPenaltyFactor(penalty_factor);
552 std::vector<std::string> out;
553 for (
size_t i = 0; i <
nParams(); ++i) {
563 if (handler && handler->function().get() !=
this) {
564 throw std::runtime_error(
"Function handler points to a different function");
596 std::string apply(
const std::string & )
const override {
return "std::string"; }
598 std::string apply(
const int & )
const override {
return "int"; }
600 std::string apply(
const double & )
const override {
return "double"; }
602 std::string apply(
const bool & )
const override {
return "bool"; }
604 std::string apply(
const std::vector<double> & )
const override {
return "std::vector<double>"; }
619 explicit AttValue(
bool quoteString =
false)
624 std::string apply(
const std::string &str)
const override {
625 return (
m_quoteString) ? std::string(
"\"" + str +
"\"") : str;
628 std::string apply(
const int &i)
const override {
return std::to_string(i); }
630 std::string apply(
const double &d)
const override {
return boost::lexical_cast<std::string>(d); }
632 std::string apply(
const bool &b)
const override {
return b ?
"true" :
"false"; }
634 std::string apply(
const std::vector<double> &v)
const override {
635 std::string res =
"(";
637 for (
size_t i = 0; i < v.size() - 1; ++i) {
638 res += boost::lexical_cast<std::string>(v[i]) +
",";
640 res += boost::lexical_cast<std::string>(v.back());
653 AttValue
tmp(m_quoteValue);
662 return asQuotedString();
665 return boost::get<std::string>(
m_data);
667 throw std::runtime_error(
"Trying to access a " + type() +
680 attr = boost::get<std::string>(
m_data);
682 throw std::runtime_error(
"Trying to access a " + type() +
690 std::string quoted(attr);
691 if (*(attr.begin()) !=
'\"')
692 quoted =
"\"" + attr;
693 if (*(quoted.end() - 1) !=
'\"')
706 attr = boost::get<std::string>(
m_data);
708 throw std::runtime_error(
"Trying to access a " + type() +
712 std::string unquoted(attr);
715 if (*(attr.begin()) ==
'\"')
716 unquoted = std::string(attr.begin() + 1, attr.end() - 1);
717 if (*(unquoted.end() - 1) ==
'\"')
718 unquoted = std::string(unquoted.begin(), unquoted.end() - 1);
728 return boost::get<int>(
m_data);
730 throw std::runtime_error(
"Trying to access a " + type() +
741 return boost::get<double>(
m_data);
743 throw std::runtime_error(
"Trying to access a " + type() +
754 return boost::get<bool>(
m_data);
756 throw std::runtime_error(
"Trying to access a " + type() +
767 return boost::get<std::vector<double>>(
m_data);
769 throw std::runtime_error(
"Trying to access a " + type() +
780 evaluateValidator(str);
783 boost::get<std::string>(
m_data) = str;
785 throw std::runtime_error(
"Trying to access a " + type() +
796 evaluateValidator(
d);
799 boost::get<double>(
m_data) =
d;
801 throw std::runtime_error(
"Trying to access a " + type() +
812 evaluateValidator(i);
815 boost::get<int>(
m_data) = i;
817 throw std::runtime_error(
"Trying to access a " + type() +
828 evaluateValidator(b);
831 boost::get<bool>(
m_data) = b;
833 throw std::runtime_error(
"Trying to access a " + type() +
845 evaluateValidator(v);
848 auto &
value = boost::get<std::vector<double>>(
m_data);
849 value.assign(v.begin(), v.end());
851 throw std::runtime_error(
"Trying to access a " + type() +
860 return boost::get<std::string>(
m_data).empty();
862 throw std::runtime_error(
"Trying to access a " + type() +
" attribute as string");
882 void apply(std::string &str)
const override {
887 void apply(
int &i)
const override {
890 std::istringstream istr(
m_value +
" ");
893 throw std::invalid_argument(
"Failed to set int attribute "
897 evaluateValidator(tempi);
901 void apply(
double &d)
const override {
904 std::istringstream istr(
m_value +
" ");
907 throw std::invalid_argument(
"Failed to set double attribute "
911 evaluateValidator(tempd);
915 void apply(
bool &b)
const override {
919 evaluateValidator(tempb);
924 void apply(std::vector<double> &v)
const override {
936 Kernel::StringTokenizer
tokenizer(
m_value,
",", Kernel::StringTokenizer::TOK_TRIM);
941 std::vector<double> tempVec(newSize);
943 for (
size_t i = 0; i < tempVec.size(); ++i) {
944 tempVec[i] = boost::lexical_cast<double>(tokenizer[i]);
946 evaluateValidator(tempVec);
950 for (
size_t i = 0; i < v.size(); ++i) {
951 v[i] = boost::lexical_cast<double>(tokenizer[i]);
956 template <
typename T>
void evaluateValidator(T &inputData)
const {
958 IFunction::ValidatorEvaluator::evaluate(inputData,
m_validator);
990 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
999 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1010 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1021 throw std::runtime_error(
"Attempt to use an inactive parameter " +
parameterName(i));
1039 const size_t nParam =
nParams();
1049 nData = minusStep.
size();
1053 for (
size_t iP = 0; iP < nParam; iP++) {
1058 const double paramPstep = val + step;
1065 step = paramPstep - val;
1066 for (
size_t i = 0; i < nData; i++) {
1091 throw std::invalid_argument(
"An invalid method for calculating the step size was provided.");
1112 const auto ¶mMap =
workspace->constInstrumentParameters();
1115 size_t numDetectors =
workspace->getSpectrum(wi).getDetectorIDs().size();
1116 if (numDetectors > 1) {
1121 auto firstDetectorId = *
workspace->getSpectrum(wi).getDetectorIDs().begin();
1123 const auto &detectorInfo =
workspace->detectorInfo();
1124 const auto detectorIndex = detectorInfo.indexOf(firstDetectorId);
1125 const auto &detector = detectorInfo.detector(
detectorIndex);
1126 detectorPtr = &detector;
1129 const auto &spectrumInfo =
workspace->spectrumInfo();
1130 const auto &detector = spectrumInfo.detector(wi);
1131 detectorPtr = &detector;
1134 for (
size_t i = 0; i <
nParams(); i++) {
1143 if (
name() == fitParam.getFunction()) {
1146 if (testWithLocation ==
nullptr ||
1147 (!fitParam.getLookUpTable().containData() && fitParam.getFormula().empty())) {
1150 double centreValue = testWithLocation->centre();
1153 if (fitParam.getFormula().empty())
1154 centreUnit = fitParam.getLookUpTable().getXUnit();
1156 if (!fitParam.getFormulaUnit().empty()) {
1160 g_log.
warning() << fitParam.getFormulaUnit() <<
" Is not an recognised formula unit for parameter "
1161 << fitParam.getName() <<
"\n";
1170 <<
" centre of peak before any unit conversion is " << centreValue <<
'\n';
1173 <<
" centre of peak after any unit conversion is " << centreValue <<
'\n';
1176 double paramValue = fitParam.getValue(centreValue);
1183 if (fitParam.getFormula().empty()) {
1187 <<
" before y-unit conversion\n";
1190 <<
" after y-unit conversion\n";
1194 std::string resultUnitStr = fitParam.getResultUnit();
1196 if (!resultUnitStr.empty()) {
1198 for (
auto &iUnit : allUnitStr) {
1199 size_t found = resultUnitStr.find(iUnit);
1200 if (found != std::string::npos) {
1201 size_t len = iUnit.size();
1202 std::stringstream readDouble;
1205 resultUnitStr.replace(found, len, readDouble.str());
1211 p.SetExpr(resultUnitStr);
1213 <<
" before result-unit conversion (using " << resultUnitStr <<
")\n";
1214 paramValue *= p.Eval();
1216 <<
" after result-unit conversion\n";
1217 }
catch (mu::Parser::exception_type &e) {
1218 g_log.
error() <<
"Cannot convert formula unit to workspace unit"
1219 <<
" Formula unit which cannot be passed is " << resultUnitStr
1220 <<
". Muparser error message is: " << e.GetMsg() <<
'\n';
1231 if (!fitParam.getTie().empty()) {
1232 std::ostringstream str;
1239 if (!fitParam.getConstraint().empty()) {
1241 if (!fitParam.getConstraintPenaltyFactor().empty()) {
1243 double penalty = std::stod(fitParam.getConstraintPenaltyFactor());
1246 g_log.
warning() <<
"Can't set penalty factor for constraint\n";
1268 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1270 const auto &wsUnit = ws->getAxis(0)->unit();
1271 if (outUnit->unitID() == wsUnit->unitID())
1276 double factor(0.0), power(0.0);
1277 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1278 return factor * std::pow(
value, power);
1280 std::vector<double> singleValue(1,
value);
1282 return singleValue.front();
1295 const std::shared_ptr<const MatrixWorkspace> &ws,
size_t wsIndex)
const {
1297 const auto &wsUnit = ws->getAxis(0)->unit();
1298 if (outUnit->unitID() == wsUnit->unitID())
1302 double factor, power;
1303 if (wsUnit->quickConversion(*outUnit, factor, power)) {
1304 auto iend = values.end();
1305 for (
auto itr = values.begin(); itr != iend; ++itr)
1306 (*itr) = factor * std::pow(*itr, power);
1311 if (sample ==
nullptr) {
1312 g_log.
error() <<
"No sample defined instrument. Cannot convert units for function\n"
1313 <<
"Ignore conversion.";
1316 const auto &spectrumInfo = ws->spectrumInfo();
1317 double l1 = spectrumInfo.l1();
1319 auto emode = ws->getEMode();
1322 spectrumInfo.getDetectorValues(*wsUnit, *outUnit, emode,
false, wsIndex,
pmap);
1323 std::vector<double> emptyVec;
1325 wsUnit->toTOF(values, emptyVec, l1, emode,
pmap);
1326 outUnit->fromTOF(values, emptyVec, l1, emode,
pmap);
1327 }
catch (std::exception &) {
1328 throw std::runtime_error(
"Unable to perform unit conversion to " + outUnit->unitID());
1347 std::string str(
value);
1364 throw std::runtime_error(
"Function " +
name() +
" doesn't have children.");
1369 std::vector<std::string> names;
1384 throw std::out_of_range(
"Function attribute index out of range.");
1398 throw std::invalid_argument(
"ParamFunctionAttributeHolder::getAttribute - Unknown attribute '" +
name +
"'");
1447 std::ostringstream msg;
1448 msg <<
"Attribute (" <<
name <<
") already exists.";
1449 throw std::invalid_argument(msg.str());
1468 value.setValidator(validatorClone);
1469 value.evaluateValidator();
1473 throw std::invalid_argument(
"ParamFunctionAttributeHolder::setAttribute - Unknown attribute '" +
name +
"'");
1499 throw std::invalid_argument(
"IFunction: Cannot set an empty covariance matrix");
1502 if (covar->numRows() !=
nParams() || covar->numCols() !=
nParams()) {
1503 throw std::invalid_argument(
"IFunction: Covariance matrix has a wrong size");
1530 for (
size_t i = 0; i <
nParams(); ++i) {
1539 for (
size_t i = 0; i <
nParams(); ++i) {
1548 for (
size_t i = 0; i <
nParams(); ++i) {
1561 for (
size_t i = 0; i <
nParams(); ++i) {
1586 std::list<TieNode> orderedTieNodes;
1587 for (
size_t i = 0; i <
nParams(); ++i) {
1595 auto const rhsParameters =
tie->getRHSParameters();
1596 newNode.right.reserve(rhsParameters.size());
1597 for (
auto &&p : rhsParameters) {
1600 if (newNode < newNode) {
1601 throw std::runtime_error(
"Parameter is tied to itself: " +
tie->asString(
this));
1603 bool before(
false), after(
false);
1604 size_t indexBefore(0), indexAfter(0);
1605 for (
auto &&node : orderedTieNodes) {
1606 if (newNode < node) {
1608 indexBefore = node.left;
1610 if (node < newNode) {
1612 indexAfter = node.left;
1617 std::string message =
"Circular dependency in ties:\n" +
tie->asString(
this) +
'\n';
1619 if (indexAfter != indexBefore) {
1622 throw std::runtime_error(message);
1624 orderedTieNodes.push_front(newNode);
1626 orderedTieNodes.emplace_back(newNode);
1629 for (
auto &&node : orderedTieNodes) {
1641MANTID_API_DLL std::shared_ptr<Mantid::API::IFunction>
1642IPropertyManager::getValue<std::shared_ptr<Mantid::API::IFunction>>(
const std::string &name)
const {
1647 std::string message =
"Attempt to assign property " + name +
" to incorrect type. Expected shared_ptr<IFunction>.";
1648 throw std::runtime_error(message);
1653MANTID_API_DLL std::shared_ptr<const Mantid::API::IFunction>
1654IPropertyManager::getValue<std::shared_ptr<const Mantid::API::IFunction>>(
const std::string &name)
const {
1655 auto *prop =
dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>
> *>(getPointerToProperty(name));
1657 return prop->operator()();
1659 std::string message =
1660 "Attempt to assign property " + name +
" to incorrect type. Expected const shared_ptr<IFunction>.";
1661 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.
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.
void sortTies()
Put all ties in order in which they will be applied correctly.
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.
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).
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.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ 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)