Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Mantid::PythonInterface::IFunction1DAdapter Class Reference

Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived from IFunction1D. More...

#include <IFunction1DAdapter.h>

Inheritance diagram for Mantid::PythonInterface::IFunction1DAdapter:
Mantid::API::ParamFunction Mantid::API::IFunction1D Mantid::PythonInterface::IFunctionAdapter Mantid::API::IFunction Mantid::API::IFunction Mantid::API::IFunction

Public Types

using Base = API::IFunction1D
 
- Public Types inherited from Mantid::API::IFunction
enum  ParameterStatus { Active , Fixed , FixedByDefault , Tied }
 Describe parameter status in relation to fitting: Active: Fit varies such parameter directly. More...
 
enum class  StepSizeMethod { DEFAULT , SQRT_EPSILON }
 Describes the method in which the step size will be calculated: DEFAULT: Uses the traditional Mantid method of calculating the step size. More...
 

Public Member Functions

 IFunction1DAdapter (const IFunction1DAdapter &)=delete
 Disable copy operator - The PyObject must be supplied to construct the object. More...
 
 IFunction1DAdapter (PyObject *self)
 A constructor that looks like a Python init method. More...
 
IFunction1DAdapteroperator= (const IFunction1DAdapter &)=delete
 Disable assignment operator. More...
 
Virtual methods
void function1D (double *out, const double *xValues, const size_t nData) const override
 Translates between the C++ signature & the Python signature called by Fit. More...
 
boost::python::object function1D (const boost::python::object &xvals) const
 Python-type signature. More...
 
void functionDeriv1D (API::Jacobian *out, const double *xValues, const size_t nData) override
 Derivatives of function with respect to active parameters (C++ override) More...
 
- Public Member Functions inherited from Mantid::API::ParamFunction
IFunction_sptr getContainingFunction (const ParameterReference &ref) const
 Get the containing function. More...
 
IFunction_sptr getContainingFunction (IFunction_sptr fun)
 Get the containing function. More...
 
double getError (const std::string &name) const override
 Get the fitting error for a parameter by name. More...
 
double getError (size_t i) const override
 Get the fitting error for a parameter. More...
 
double getParameter (const std::string &name) const override
 Get parameter by name. More...
 
double getParameter (size_t i) const override
 Get i-th parameter. More...
 
size_t getParameterIndex (const ParameterReference &ref) const override
 Return parameter index from a parameter reference. More...
 
bool hasParameter (const std::string &name) const override
 Check if function has a parameter with this name. More...
 
bool isExplicitlySet (size_t i) const override
 Checks if a parameter has been set explicitly. More...
 
size_t nParams () const override
 Total number of parameters. More...
 
std::string parameterDescription (size_t i) const override
 Returns the description of parameter i. More...
 
size_t parameterIndex (const std::string &name) const override
 Returns the index of parameter name. More...
 
std::string parameterName (size_t i) const override
 Returns the name of parameter i. More...
 
 ParamFunction ()
 Default constructor. More...
 
void setError (const std::string &name, double err) override
 Set the fitting error for a parameter by name. More...
 
void setError (size_t i, double err) override
 Set the fitting error for a parameter. More...
 
void setParameter (const std::string &name, const double &value, bool explicitlySet=true) override
 Set parameter by name. More...
 
void setParameter (size_t, const double &value, bool explicitlySet=true) override
 Set i-th parameter. More...
 
void setParameterDescription (const std::string &name, const std::string &description) override
 Set description of parameter by name. More...
 
void setParameterDescription (size_t, const std::string &description) override
 Set i-th parameter description. More...
 
- Public Member Functions inherited from Mantid::API::IFunction
std::string asString () const
 Writes itself into a string. More...
 
bool cancellationRequestReceived () const
 Returns true if a progress reporter is set & evalaution has been requested to stop. More...
 
virtual const std::vector< std::string > categories () const
 Function to return all of the categories that contain this algorithm. More...
 
virtual const std::string category () const
 The categories the Fit function belong to. More...
 
virtual const std::string categorySeparator () const
 Function to return the sperator token for the category string. More...
 
virtual std::shared_ptr< IFunctionclone () const
 Virtual copy constructor. More...
 
virtual int64_t estimateNoProgressCalls () const
 Returns an estimate of the number of progress reports a single evaluation of the function will have. More...
 
virtual void function (const FunctionDomain &domain, FunctionValues &values) const =0
 Evaluates the function for all arguments in the domain. More...
 
virtual void functionDeriv (const FunctionDomain &domain, Jacobian &jacobian)
 Derivatives of function with respect to active parameters. More...
 
 IFunction ()
 Constructor. More...
 
 IFunction (const IFunction &)=delete
 No copying. More...
 
virtual void initialize ()
 Iinialize the function. More...
 
virtual void iterationFinished ()
 Called at the end of an iteration. More...
 
virtual void iterationStarting ()
 Called at the start of each iteration. More...
 
virtual std::string name () const =0
 Returns the function's name. More...
 
IFunctionoperator= (const IFunction &)=delete
 No copying. More...
 
virtual void registerFunctionUsage (bool internal)
 Registers the usage of the algorithm with the UsageService. More...
 
void reportProgress (const std::string &msg="") const
 Reports progress with an optional message. More...
 
virtual void setMatrixWorkspace (std::shared_ptr< const API::MatrixWorkspace > workspace, size_t wi, double startX, double endX)
 Set matrix workspace. More...
 
void setProgressReporter (std::shared_ptr< Kernel::ProgressBase > reporter)
 Attach a progress reporter. More...
 
virtual void setWorkspace (std::shared_ptr< const Workspace > ws)
 Set the workspace. More...
 
virtual ~IFunction ()
 Virtual destructor. More...
 
bool isFixed (size_t i) const
 Check if a parameter i is fixed. More...
 
bool isFixedByDefault (size_t i) const
 Check if a parameter i is fixed by default (not by user). More...
 
void fix (size_t i, bool isDefault=false)
 Removes a parameter i from the list of active. More...
 
void unfix (size_t i)
 Restores a declared parameter i to the active status. More...
 
void fixParameter (const std::string &name, bool isDefault=false)
 Fix a parameter. More...
 
void unfixParameter (const std::string &name)
 Free a parameter. More...
 
void fixAll (bool isDefault=false)
 Fix all parameters. More...
 
void unfixAll ()
 Free all parameters. More...
 
void unfixAllDefault ()
 Free all parameters fixed by default. More...
 
void fixAllActive (bool isDefault=false)
 Fix all active parameters. More...
 
std::vector< std::string > getParameterNames () const
 Return a vector with all parameter names. More...
 
virtual std::string nameOfActive (size_t i) const
 Returns the name of active parameter i. More...
 
virtual std::string descriptionOfActive (size_t i) const
 Returns the name of active parameter i. More...
 
bool isActive (size_t i) const
 Check if an active parameter i is actually active. More...
 
virtual void tie (const std::string &parName, const std::string &expr, bool isDefault=false)
 Tie a parameter to other parameters (or a constant) More...
 
virtual void addTies (const std::string &ties, bool isDefault=false)
 Add several ties. More...
 
virtual void applyTies ()
 Apply the ties. More...
 
virtual void removeTie (const std::string &parName)
 Removes the tie off a parameter. More...
 
virtual void clearTies ()
 Remove all ties. More...
 
virtual bool removeTie (size_t i)
 Removes i-th parameter's tie. More...
 
virtual ParameterTiegetTie (size_t i) const
 Get the tie of i-th parameter. More...
 
virtual bool ignoreTie (const ParameterTie &) const
 Ignore a tie. More...
 
void sortTies ()
 Put all ties in order in which they will be applied correctly. More...
 
std::string writeTies () const
 Write a parameter tie to a string. More...
 
virtual void addConstraints (const std::string &str, bool isDefault=false)
 Add a list of conatraints from a string. More...
 
virtual void addConstraint (std::unique_ptr< IConstraint > ic)
 Add a constraint to function. More...
 
virtual IConstraintgetConstraint (size_t i) const
 Get constraint of i-th parameter. More...
 
virtual void removeConstraint (const std::string &parName)
 Remove a constraint. More...
 
virtual void setConstraintPenaltyFactor (const std::string &parName, const double &c)
 Set a constraint penalty. More...
 
std::string writeConstraints () const
 Write a parameter constraint to a string. More...
 
virtual void clearConstraints ()
 Remove all constraints. More...
 
virtual size_t nAttributes () const
 Returns the number of attributes associated with the function. More...
 
virtual std::vector< std::string > getAttributeNames () const
 Returns a list of attribute names. More...
 
virtual std::string attributeName (size_t index) const
 Get name of ith attribute. More...
 
virtual Attribute getAttribute (const std::string &name) const
 Return a value of attribute attName. More...
 
virtual bool hasAttribute (const std::string &name) const
 Check if attribute attName exists. More...
 
template<typename T >
void setAttributeValue (const std::string &attName, const T &value)
 Set an attribute value. More...
 
void setAttributeValue (const std::string &attName, const char *value)
 Overload for const char* values. More...
 
void setAttributeValue (const std::string &attName, const std::string &value)
 Set string attribute by value. More...
 
virtual std::shared_ptr< IFunctiongetFunction (size_t i) const
 Returns the pointer to i-th child function. More...
 
virtual std::size_t nFunctions () const
 Number of child functions. More...
 
virtual void setUpForFit ()
 Set up the function for a fit. More...
 
virtual size_t getValuesSize (const FunctionDomain &domain) const
 Get number of values for a given domain. More...
 
virtual size_t getNumberDomains () const
 Get number of domains required by this function. More...
 
virtual std::vector< std::shared_ptr< IFunction > > createEquivalentFunctions () const
 Split this function (if needed) into a list of independent functions. More...
 
void calNumericalDeriv (const FunctionDomain &domain, Jacobian &jacobian)
 Calculate numerical derivatives. More...
 
double calculateStepSize (const double parameterValue) const
 Calculate step size for the given parameter value. More...
 
void setCovarianceMatrix (const std::shared_ptr< Kernel::Matrix< double > > &covar)
 Set the covariance matrix. More...
 
std::shared_ptr< const Kernel::Matrix< double > > getCovarianceMatrix () const
 Get the covariance matrix. More...
 
void setReducedChiSquared (double chi2)
 Set the reduced chi^2. More...
 
double getReducedChiSquared () const
 Get the reduced chi^2. More...
 
void setParallel (bool on)
 Set the parallel hint. More...
 
bool isParallel () const
 Get the parallel hint. More...
 
void setHandler (std::unique_ptr< FunctionHandler > handler)
 Set a function handler. More...
 
FunctionHandlergetHandler () const
 Return the handler. More...
 
virtual void setStepSizeMethod (const StepSizeMethod method)
 Sets the StepSizeMethod to use when calculation the step size. More...
 
- Public Member Functions inherited from Mantid::API::IFunction1D
virtual void derivative (const FunctionDomain &domain, FunctionValues &values, const size_t order=1) const
 
virtual void derivative1D (double *out, const double *xValues, const size_t nData, const size_t order) const
 Function to calculate the derivatives of the data set. More...
 
void function (const FunctionDomain &domain, FunctionValues &values) const override
 Evaluates the function for all arguments in the domain. More...
 
virtual void function1D (double *out, const double *xValues, const size_t nData) const =0
 Function you want to fit to. More...
 
void functionDeriv (const FunctionDomain &domain, Jacobian &jacobian) override
 Derivatives of function with respect to active parameters. More...
 
virtual void functionDeriv1D (Jacobian *jacobian, const double *xValues, const size_t nData)
 Derivatives of function with respect to active parameters. More...
 
- Public Member Functions inherited from Mantid::PythonInterface::IFunctionAdapter
double activeParameter (size_t i) const override
 Override this method to make fitted parameters different from the declared. More...
 
const std::string category () const override
 Specify a category for the function. More...
 
void declareAttribute (const std::string &name, const boost::python::object &defaultValue)
 Declare an attribute with an initial value. More...
 
void declareAttribute (const std::string &name, const boost::python::object &defaultValue, const boost::python::object &validator)
 Declare an attribute with an initial value and validator. More...
 
void declareFitParameter (const std::string &name, double initValue, const std::string &description)
 Declare a named parameter with initial value & description. More...
 
void declareFitParameterNoDescr (const std::string &name, double initValue)
 Declare a named parameter with initial value. More...
 
void declareFitParameterZeroInit (const std::string &name)
 Declare a named parameter with initial value = 0.0. More...
 
 IFunctionAdapter (const IFunctionAdapter &)=delete
 The PyObject must be supplied to construct the object. More...
 
 IFunctionAdapter (PyObject *self, std::string functionMethod, std::string derivMethod)
 A constructor that looks like a Python init method. More...
 
void init () override
 Declare all attributes & parameters. More...
 
std::string name () const override
 Returns the name of the function. More...
 
IFunctionAdapteroperator= (const IFunctionAdapter &)=delete
 Disable assignment operator. More...
 
void setActiveParameter (size_t i, double value) override
 Override this method to make fitted parameters different from the declared. More...
 
void setAttribute (const std::string &attName, const API::IFunction::Attribute &attr) override
 Called by the framework when an attribute has been set. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Mantid::PythonInterface::IFunctionAdapter
static boost::python::list createPythonEquivalentFunctions (const IFunction &self)
 Split this function (if needed) into a list of independent functions. More...
 
static PyObject * getAttributeValue (const IFunction &self, const API::IFunction::Attribute &attr)
 Returns the attribute's value as a Python object. More...
 
static PyObject * getAttributeValue (const IFunction &self, const std::string &name)
 Get a named attribute value. More...
 
static void setAttributePythonValue (IFunction &self, const std::string &name, const boost::python::object &value)
 Set the attribute's value. More...
 
- Protected Types inherited from Mantid::API::IFunction1D
template<typename FunctionType >
using Function1DMethod = void(FunctionType::*)(double *, const double *, const size_t) const
 
- Protected Member Functions inherited from Mantid::API::ParamFunction
void clearAllParameters ()
 Nonvirtual member which removes all declared parameters. More...
 
void declareParameter (const std::string &name, double initValue=0, const std::string &description="") override
 Declare a new parameter. More...
 
virtual double * getParameterAddress (size_t i)
 Get the address of the parameter. For use in UserFunction with mu::Parser. More...
 
ParameterStatus getParameterStatus (size_t i) const override
 Get status of parameter. More...
 
void setParameterStatus (size_t i, ParameterStatus status) override
 Change status of parameter. More...
 
- Protected Member Functions inherited from Mantid::API::IFunction
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) More...
 
void convertValue (std::vector< double > &values, Kernel::Unit_sptr &outUnit, const std::shared_ptr< const MatrixWorkspace > &ws, size_t wsIndex) const
 Convert values from unit defined in workspace (ws) to outUnit. More...
 
virtual void declareAttributes ()
 Override to declare function attributes. More...
 
virtual void declareParameters ()
 Override to declare function parameters. More...
 
void declareAttribute (const std::string &name, const API::IFunction::Attribute &defaultValue)
 Declare a single attribute. More...
 
void declareAttribute (const std::string &name, const API::IFunction::Attribute &defaultValue, const Kernel::IValidator &validator)
 Declare a single attribute with validator. More...
 
void checkAttributeName (const std::string &name)
 Check Attribute to declare does not already exist. More...
 
void storeAttributeValue (const std::string &name, const API::IFunction::Attribute &value)
 Store an attribute's value. More...
 
void storeReadOnlyAttribute (const std::string &name, const API::IFunction::Attribute &value) const
 A read-only ("mutable") attribute can be stored in a const method. More...
 
virtual void addTie (std::unique_ptr< ParameterTie > tie)
 Add a new tie. Derived classes must provide storage for ties. More...
 
bool hasOrderedTies () const
 
void applyOrderedTies ()
 
virtual std::string writeToString (const std::string &parentLocalAttributesStr="") const
 Writes itself into a string. More...
 
- Protected Member Functions inherited from Mantid::API::IFunction1D
template<typename EvaluationMethod >
void calcNumericalDerivative1D (Jacobian *jacobian, EvaluationMethod func1D, const double *xValues, const size_t nData)
 Calculate a numerical derivative for the 1D data. More...
 
virtual void histogram1D (double *out, double left, const double *right, const size_t nBins) const
 Calculate histogram data for the given bin boundaries. More...
 
virtual void histogramDerivative1D (Jacobian *jacobian, double left, const double *right, const size_t nBins) const
 Derivatives of the histogram1D with respect to active parameters. More...
 
- Protected Member Functions inherited from Mantid::PythonInterface::IFunctionAdapter
bool derivativeOverridden () const
 
void evaluateDerivative (API::Jacobian *out, const double *xValues, const size_t nData) const
 Evaluate the derivative by calling the overridden method. More...
 
void evaluateFunction (double *out, const double *xValues, const size_t nData) const
 Evaluate the function by calling the overridden method. More...
 
PyObject * getSelf () const
 
- Protected Attributes inherited from Mantid::API::IFunction
bool m_isParallel
 Flag to hint that the function is being used in parallel computations. More...
 
std::unique_ptr< FunctionHandlerm_handler
 Pointer to a function handler. More...
 
std::shared_ptr< Kernel::ProgressBasem_progReporter
 Pointer to the progress handler. More...
 
- Static Protected Attributes inherited from Mantid::API::IFunction1D
static Kernel::Logger g_log
 Logger instance. More...
 

Detailed Description

Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived from IFunction1D.

This is essentially a transparent layer that handles the function calls up into Python.

Definition at line 34 of file IFunction1DAdapter.h.

Member Typedef Documentation

◆ Base

Definition at line 38 of file IFunction1DAdapter.h.

Constructor & Destructor Documentation

◆ IFunction1DAdapter() [1/2]

Mantid::PythonInterface::IFunction1DAdapter::IFunction1DAdapter ( PyObject *  self)

A constructor that looks like a Python init method.

Construct the "wrapper" and stores the reference to the PyObject.

Parameters
selfA reference to the calling Python object

Definition at line 24 of file IFunction1DAdapter.cpp.

◆ IFunction1DAdapter() [2/2]

Mantid::PythonInterface::IFunction1DAdapter::IFunction1DAdapter ( const IFunction1DAdapter )
delete

Disable copy operator - The PyObject must be supplied to construct the object.

Member Function Documentation

◆ function1D() [1/2]

boost::python::object Mantid::PythonInterface::IFunction1DAdapter::function1D ( const boost::python::object &  xvals) const

Python-type signature.

Python-type signature version of above to be called directly from Python.

Parameters
xvalsThe input X values in read-only numpy array

Definition at line 41 of file IFunction1DAdapter.cpp.

References Mantid::PythonInterface::IFunctionAdapter::getSelf().

◆ function1D() [2/2]

void Mantid::PythonInterface::IFunction1DAdapter::function1D ( double *  out,
const double *  xValues,
const size_t  nData 
) const
overridevirtual

Translates between the C++ signature & the Python signature called by Fit.

Base-class method

Parameters
outThe 1D data array of size nData that stores the output values
xValuesThe input X values
nDataThe size of the two arrays

Implements Mantid::API::IFunction1D.

Definition at line 33 of file IFunction1DAdapter.cpp.

References Mantid::PythonInterface::IFunctionAdapter::evaluateFunction().

Referenced by export_IFunction1D().

◆ functionDeriv1D()

void Mantid::PythonInterface::IFunction1DAdapter::functionDeriv1D ( API::Jacobian out,
const double *  xValues,
const size_t  nData 
)
overridevirtual

Derivatives of function with respect to active parameters (C++ override)

If a Python override exists then call that, otherwise call the base class method.

Parameters
outThe Jacobian matrix storing the partial derivatives of the function w.r.t to the parameters
xValuesThe input X values
nDataThe size of the two arrays

Reimplemented from Mantid::API::IFunction1D.

Definition at line 53 of file IFunction1DAdapter.cpp.

References Mantid::PythonInterface::IFunctionAdapter::derivativeOverridden(), Mantid::PythonInterface::IFunctionAdapter::evaluateDerivative(), and Mantid::API::IFunction1D::functionDeriv1D().

◆ operator=()

IFunction1DAdapter & Mantid::PythonInterface::IFunction1DAdapter::operator= ( const IFunction1DAdapter )
delete

Disable assignment operator.


The documentation for this class was generated from the following files: