25using namespace CurveFitting;
27using namespace Kernel;
33Logger
g_log(
"TabulatedFunction");
54 const size_t nData)
const {
63 std::vector<double> xData(
m_xData);
64 for (
double &
value : xData) {
68 const double xStart = xData.front();
69 const double xEnd = xData.back();
71 if (xStart >= xValues[nData - 1] || xEnd <= xValues[0])
74 while (i < nData - 1 && xValues[i] < xStart) {
79 for (; i < nData; i++) {
80 double xi = xValues[i];
81 while (j <
size() - 1 && xi > xData[j])
88 }
else if (xi > xData[j]) {
91 double x0 = xData[j - 1];
95 out[i] = y0 + (y1 - y0) * (xi - x0) / (x1 - x0);
114 eval(scaling, xshift, xscale, out, xValues, nData);
128 std::vector<double>
tmp(nData);
130 eval(1.0, xshift, xscale,
tmp.data(), xValues, nData);
131 for (
size_t i = 0; i < nData; ++i) {
135 const double dx = (xValues[nData - 1] - xValues[0]) /
static_cast<double>(nData);
136 std::vector<double> tmpplus(nData);
137 std::vector<double> tmpminus(nData);
141 eval(scaling, xshift + dx, xscale, tmpplus.data(), xValues, nData);
142 eval(scaling, xshift - dx, xscale, tmpminus.data(), xValues, nData);
143 for (
size_t i = 0; i < nData; ++i) {
144 out->
set(i, 1, (tmpplus[i] - tmpminus[i]) / (2 * dx));
147 eval(scaling, xshift, xscale + dx, tmpplus.data(), xValues, nData);
148 eval(scaling, xshift, xscale - dx, tmpminus.data(), xValues, nData);
149 for (
size_t i = 0; i < nData; ++i) {
150 out->
set(i, 2, (tmpplus[i] - tmpminus[i]) / (2 * dx));
166 if (attName ==
"FileName") {
167 std::string fileName =
value.asUnquotedString();
168 if (fileName.empty()) {
173 std::string
error = fval.isValid(fileName);
184 }
else if (attName ==
"Workspace") {
185 std::string wsName =
value.asString();
186 if (!wsName.empty()) {
193 }
else if (attName ==
"X") {
210 }
else if (attName ==
"Y") {
242 if (attName ==
"X") {
244 }
else if (attName ==
"Y") {
255 loadAlg->initialize();
256 loadAlg->setChild(
true);
257 loadAlg->setLogging(
false);
259 loadAlg->setPropertyValue(
"Filename", fname);
260 loadAlg->setPropertyValue(
"OutputWorkspace",
"_TabulatedFunction_fit_data_");
262 }
catch (std::runtime_error &) {
263 throw std::runtime_error(
"Unable to load Nexus file for TabulatedFunction function.");
279 throw std::runtime_error(
"Unable to set " + wsName +
" as workspace attribute. Expected a MatrixWorkspace.");
298 throw std::invalid_argument(this->
name() +
": X and Y vectors have different sizes.");
300 g_log.
debug() <<
"Re-setting isn't required.";
307 throw std::invalid_argument(
"Data not set for function " + this->
name());
318 m_xData.assign(xData.begin(), xData.end());
319 m_yData.assign(yData.begin(), yData.end());
double value
The value of the point.
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
std::map< DeltaEMode::Type, std::string > index
static Kernel::Logger g_log
Logger instance.
Attribute is a non-fitting parameter.
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
std::string asString() const
Returns string value if attribute is a string, throws exception otherwise.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
void declareAttribute(const std::string &name, const API::IFunction::Attribute &defaultValue)
Declare a single attribute.
virtual void setAttribute(const std::string &name, const Attribute &)
Set a value to attribute attName.
virtual std::vector< std::string > getAttributeNames() const
Returns a list of attribute names.
void storeAttributeValue(const std::string &name, const API::IFunction::Attribute &value)
Store an attribute's value.
virtual size_t nAttributes() const
Returns the number of attributes associated with the function.
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.
Base MatrixWorkspace Abstract Class.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
double getParameter(size_t i) const override
Get i-th parameter.
static const int defaultIndexValue
The default value for the workspace index.
void load(const std::string &fname)
Call the appropriate load function.
size_t nAttributes() const override
Returns the number of attributes associated with the function.
size_t size() const
Size of the data.
std::shared_ptr< API::MatrixWorkspace > m_workspace
Temporary workspace holder.
std::vector< double > m_yData
Stores y-values.
void loadWorkspace(const std::string &wsName) const
Load the points from a MatrixWorkspace.
bool m_explicitXY
Flag of explicit x-y data setup.
bool m_setupFinished
Flag of completing data setup.
void eval(double scaling, double xshift, double xscale, double *out, const double *xValues, const size_t nData) const
Evaluate the function for a list of arguments and given scaling factor.
void function1D(double *out, const double *xValues, const size_t nData) const override
Calculate the function values.
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names.
std::string name() const override
overwrite IFunction base class methods
void setAttribute(const std::string &attName, const IFunction::Attribute &value) override
Set a value to attribute attName.
void clear() const
Clear all data.
std::vector< double > m_xData
Stores x-values.
void setupData() const
Fill in the x and y value containers (m_xData and m_yData)
TabulatedFunction()
Constructor.
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
function derivatives
Attribute getAttribute(const std::string &attName) const override
Return a value of attribute attName.
Records the filename and the description of failure.
FileValidator is a validator that checks that a filepath is valid.
void debug(const std::string &msg)
Logs at debug level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class