Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
Mantid::CurveFitting::FuncMinimisers::DerivMinimizer Class Referenceabstract

A wrapper around the GSL functions implementing a minimizer using derivatives. More...

#include <DerivMinimizer.h>

Inheritance diagram for Mantid::CurveFitting::FuncMinimisers::DerivMinimizer:
Mantid::API::IFuncMinimizer Mantid::Kernel::PropertyManager Mantid::Kernel::IPropertyManager Mantid::CurveFitting::FuncMinimisers::BFGS_Minimizer Mantid::CurveFitting::FuncMinimisers::FRConjugateGradientMinimizer Mantid::CurveFitting::FuncMinimisers::PRConjugateGradientMinimizer Mantid::CurveFitting::FuncMinimisers::SteepestDescentMinimizer

Public Member Functions

void calCovarianceMatrix (gsl_matrix *covar, double epsrel=0.0001)
 Calculate the covariance matrix. More...
 
double costFunctionVal () override
 Return current value of the cost function. More...
 
 DerivMinimizer ()
 Constructor. More...
 
 DerivMinimizer (const double stepSize, const double tolerance)
 Constructor. More...
 
void initialize (API::ICostFunction_sptr function, size_t maxIterations=0) override
 Initialize minimizer, i.e. pass a function to minimize. More...
 
bool iterate (size_t) override
 Do one iteration. More...
 
void setStopGradient (const double value)
 Set maximum value of the gradient at which iterations can stop. More...
 
 ~DerivMinimizer () override
 Destructor. More...
 
- Public Member Functions inherited from Mantid::API::IFuncMinimizer
virtual double costFunctionVal ()=0
 Get value of cost function. More...
 
virtual void finalize ()
 Finalize minimization, eg store additional outputs. More...
 
virtual std::string getError () const
 Get the error string. More...
 
virtual void initialize (API::ICostFunction_sptr function, size_t maxIterations=1000)=0
 Initialize minimizer. More...
 
virtual bool iterate (size_t iteration)=0
 Do one iteration. More...
 
virtual bool minimize (size_t maxIterations=1000)
 Perform iteration with minimizer and return true if successful. More...
 
virtual std::string name () const =0
 Get name of minimizer. More...
 
- Public Member Functions inherited from Mantid::Kernel::PropertyManager
::Json::Value asJson (bool withDefaultValues=false) const override
 Return the property manager serialized as a json object. More...
 
std::string asString (bool withDefaultValues=false) const override
 Return the property manager serialized as a string. More...
 
void clear () override
 Clears the whole property map. More...
 
void declareOrReplaceProperty (std::unique_ptr< Property > p, const std::string &doc="") override
 Add or replace a property in the list of managed properties. More...
 
void declareProperty (const std::string &name, const char *value, const std::string &doc, IValidator_sptr validator=std::make_shared< NullValidator >(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string). More...
 
void declareProperty (const std::string &name, const char *value, const unsigned int direction)
 Add a property of string type to the list of managed properties. More...
 
void declareProperty (const std::string &name, const char *value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc=std::string(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string). More...
 
template<typename T >
void declareProperty (const std::string &name, T value, const std::string &doc, const unsigned int direction=Direction::Input)
 Add a property to the list of managed properties with no validator. More...
 
template<typename T >
void declareProperty (const std::string &name, T value, const unsigned int direction)
 Add a property of the template type to the list of managed properties. More...
 
template<typename T >
void declareProperty (const std::string &name, T value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc="", const unsigned int direction=Direction::Input)
 Add a property of the template type to the list of managed properties. More...
 
void declareProperty (std::unique_ptr< Property > p, const std::string &doc="") override
 Add a property to the list of managed properties. More...
 
virtual void declareProperty (std::unique_ptr< Property > p, const std::string &doc="")=0
 Function to declare properties (i.e. store them) More...
 
bool existsProperty (const std::string &name) const override
 Checks whether the named property is already in the list of managed property. More...
 
void filterByProperty (const TimeSeriesProperty< bool > &filter, const std::vector< std::string > &excludedFromFiltering=std::vector< std::string >()) override
 Filter the managed properties by the given boolean property mask. More...
 
void filterByTime (const Types::Core::DateAndTime &start, const Types::Core::DateAndTime &stop) override
 Filter out a run by time. More...
 
std::vector< std::string > getDeclaredPropertyNames () const noexcept override
 Return the list of declared property names. More...
 
PropertygetPointerToProperty (const std::string &name) const override
 Get a property by name. More...
 
const std::vector< Property * > & getProperties () const override
 Get the list of managed properties. More...
 
TypedValue getProperty (const std::string &name) const override
 Get the value of a property. More...
 
std::string getPropertyValue (const std::string &name) const override
 Get the value of a property as a string. More...
 
bool operator!= (const PropertyManager &other) const
 
PropertyManageroperator+= (const PropertyManager &rhs)
 Addition operator. More...
 
PropertyManageroperator= (const PropertyManager &)
 Assignment operator - performs a deep copy. More...
 
bool operator== (const PropertyManager &other) const
 
size_t propertyCount () const override
 Count the number of properties under management. More...
 
 PropertyManager ()
 Default constructor. More...
 
 PropertyManager (const PropertyManager &)
 copy constructor More...
 
void removeProperty (const std::string &name, const bool delproperty=true) override
 removes the property from properties map More...
 
void resetProperties () override
 Reset property values back to initial values (blank or default values) More...
 
void setProperties (const ::Json::Value &jsonValue, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
 Set the ordered list of properties by a json value collection. More...
 
void setProperties (const ::Json::Value &jsonValue, IPropertyManager *targetPropertyManager, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false)
 Set the ordered list of properties by a json value collection. More...
 
void setProperties (const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
 Set the ordered list of properties by one string of values, separated by semicolons. More...
 
void setProperties (const std::string &propertiesJson, IPropertyManager *targetPropertyManager, const std::unordered_set< std::string > &ignoreProperties, bool createMissing=false)
 Set the ordered list of properties by one string of values, separated by semicolons. More...
 
void setPropertiesWithString (const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >()) override
 Sets all the declared properties from a string. More...
 
void setPropertyOrdinal (const int &index, const std::string &value) override
 Set the value of a property by an index N.B. More...
 
void setPropertyValue (const std::string &name, const std::string &value) override
 Set the value of a property by string N.B. More...
 
void setPropertyValueFromJson (const std::string &name, const Json::Value &value) override
 Set the value of a property by Json::Value. More...
 
void splitByTime (std::vector< SplittingInterval > &splitter, std::vector< PropertyManager * > outputs) const override
 Split a run by time (splits the TimeSeriesProperties contained). More...
 
std::unique_ptr< PropertytakeProperty (const size_t index) override
 removes the property from the properties map and returns a pointer to it More...
 
bool validateProperties () const override
 Validates all the properties in the collection. More...
 
virtual ~PropertyManager () override
 Virtual destructor. More...
 
- Public Member Functions inherited from Mantid::Kernel::IPropertyManager
virtual ::Json::Value asJson (bool withDefaultValues=false) const =0
 Return the property manager serialized as a json object. More...
 
virtual std::string asString (bool withDefaultValues=false) const =0
 Return the property manager serialized as a string. More...
 
virtual void declareOrReplaceProperty (std::unique_ptr< Property > p, const std::string &doc="")=0
 Function to declare properties (i.e. store them) More...
 
void declareProperty (const std::string &name, const char *value, const std::string &doc, IValidator_sptr validator=std::make_shared< NullValidator >(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string). More...
 
void declareProperty (const std::string &name, const char *value, const unsigned int direction)
 Add a property of string type to the list of managed properties. More...
 
void declareProperty (const std::string &name, const char *value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc=std::string(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string). More...
 
template<typename T >
void declareProperty (const std::string &name, T value, const std::string &doc, const unsigned int direction=Direction::Input)
 Add a property to the list of managed properties with no validator. More...
 
template<typename T >
void declareProperty (const std::string &name, T value, const unsigned int direction)
 Add a property of the template type to the list of managed properties. More...
 
template<typename T >
void declareProperty (const std::string &name, T value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc="", const unsigned int direction=Direction::Input)
 Add a property of the template type to the list of managed properties. More...
 
virtual void declareProperty (std::unique_ptr< Property > p, const std::string &doc="")=0
 Function to declare properties (i.e. store them) More...
 
virtual bool existsProperty (const std::string &name) const =0
 Checks whether the named property is already in the list of managed property. More...
 
virtual void filterByProperty (const TimeSeriesProperty< bool > &, const std::vector< std::string > &)=0
 
virtual void filterByTime (const Types::Core::DateAndTime &, const Types::Core::DateAndTime &)=0
 
virtual std::vector< std::string > getDeclaredPropertyNames () const noexcept=0
 Get the list of managed property names. More...
 
virtual PropertygetPointerToProperty (const std::string &name) const =0
 Get a pointer to property by name. More...
 
virtual const std::vector< Property * > & getProperties () const =0
 Get the list of managed properties. More...
 
std::vector< Property * > getPropertiesInGroup (const std::string &group) const
 Get the list of managed properties in a given group. More...
 
virtual TypedValue getProperty (const std::string &name) const =0
 Get the value of a property. More...
 
virtual std::string getPropertyValue (const std::string &name) const =0
 Get the value of a property as a string. More...
 
virtual size_t propertyCount () const =0
 Returns the number of properties under management. More...
 
virtual void removeProperty (const std::string &name, const bool delproperty=true)=0
 Removes the property from management. More...
 
virtual void resetProperties ()=0
 
virtual void setProperties (const ::Json::Value &jsonValue, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false)=0
 Sets all the properties from a json object. More...
 
virtual void setProperties (const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false)=0
 Sets all properties from a string. More...
 
virtual void setPropertiesWithString (const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >())=0
 Sets all the declared properties from a string. More...
 
IPropertyManagersetProperty (const std::string &name, const char *value)
 Specialised version of setProperty template method to handle const char *. More...
 
IPropertyManagersetProperty (const std::string &name, const std::string &value)
 Specialised version of setProperty template method to handle std::string. More...
 
template<typename T >
IPropertyManagersetProperty (const std::string &name, const T &value)
 Templated method to set the value of a PropertyWithValue. More...
 
template<typename T >
IPropertyManagersetProperty (const std::string &name, std::unique_ptr< T > value)
 Templated method to set the value of a PropertyWithValue from a std::unique_ptr. More...
 
void setPropertyGroup (const std::string &name, const std::string &group)
 Set the group for a given property. More...
 
virtual void setPropertyOrdinal (const int &index, const std::string &value)=0
 Set the value of a property by an index. More...
 
void setPropertySettings (const std::string &name, std::unique_ptr< IPropertySettings > settings)
 
virtual void setPropertyValue (const std::string &name, const std::string &value)=0
 Sets property value from a string. More...
 
virtual void setPropertyValueFromJson (const std::string &name, const Json::Value &value)=0
 Sets property value from a Json::Value. More...
 
virtual void splitByTime (std::vector< SplittingInterval > &, std::vector< PropertyManager * >) const =0
 
virtual std::unique_ptr< PropertytakeProperty (const size_t index)=0
 Removes the property from management and returns a pointer to it. More...
 
void updatePropertyValues (const IPropertyManager &other)
 Update values of the existing properties. More...
 
virtual bool validateProperties () const =0
 Validates all the properties in the collection. More...
 
virtual ~IPropertyManager ()=default
 

Protected Member Functions

virtual const gsl_multimin_fdfminimizer_type * getGSLMinimizerType ()=0
 Return a concrete type to initialize m_gslSolver with. More...
 
- Protected Member Functions inherited from Mantid::Kernel::PropertyManager
PropertygetPointerToPropertyOrdinal (const int &index) const override
 Get a property by an index. More...
 
PropertygetPointerToPropertyOrNull (const std::string &name) const
 Get a property by name. More...
 
- Protected Member Functions inherited from Mantid::Kernel::IPropertyManager
virtual void afterPropertySet (const std::string &)
 Override this method to perform a custom action right after a property was set. More...
 
virtual void clear ()=0
 Clears all properties under management. More...
 
virtual PropertygetPointerToPropertyOrdinal (const int &index) const =0
 Get a property by an index. More...
 
template<typename T >
getValue (const std::string &name) const
 Templated method to get the value of a property. More...
 
template<>
MANTID_KERNEL_DLL PropertyManager_sptr getValue (const std::string &name) const
 
template<>
MANTID_KERNEL_DLL PropertyManager_const_sptr getValue (const std::string &name) const
 

Static Protected Member Functions

static void dfun (const gsl_vector *x, void *params, gsl_vector *g)
 Used by the GSL. More...
 
static double fun (const gsl_vector *x, void *params)
 Used by the GSL. More...
 
static void fundfun (const gsl_vector *x, void *params, double *f, gsl_vector *g)
 Used by the GSL. More...
 

Protected Attributes

API::ICostFunction_sptr m_costFunction
 Function to minimize. More...
 
gsl_multimin_function_fdf m_gslMultiminContainer
 GSL container. More...
 
gsl_multimin_fdfminimizer * m_gslSolver
 pointer to the GSL solver doing the work More...
 
double m_stepSize
 First trial step size. More...
 
double m_stopGradient
 the norm of the gradient at which iterations stop More...
 
double m_tolerance
 Tolerance. More...
 
gsl_vector * m_x
 GSL vector with function parameters. More...
 
- Protected Attributes inherited from Mantid::API::IFuncMinimizer
std::string m_errorString
 Error string. More...
 

Private Member Functions

void initGSLMMin ()
 simply init the values for the gsl minimizer More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Mantid::Kernel::PropertyManager
static std::string getInvalidValuesFilterLogName (const std::string &logName)
 Gets the correct log name for the matching invalid values log for a given log name. More...
 
static std::string getLogNameFromInvalidValuesFilter (const std::string &logName)
 
static bool isAnInvalidValuesFilterLog (const std::string &logName)
 
- Static Public Attributes inherited from Mantid::Kernel::PropertyManager
static const std::string INVALID_VALUES_SUFFIX = "_invalid_values"
 

Detailed Description

A wrapper around the GSL functions implementing a minimizer using derivatives.

Concrete classes must implement the getGSLMinimizerType() method.

Author
Roman Tolchenov, Tessella plc

Definition at line 27 of file DerivMinimizer.h.

Constructor & Destructor Documentation

◆ DerivMinimizer() [1/2]

Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::DerivMinimizer ( )

Constructor.

Definition at line 81 of file DerivMinimizer.cpp.

References initGSLMMin().

◆ DerivMinimizer() [2/2]

Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::DerivMinimizer ( const double  stepSize,
const double  tolerance 
)

Constructor.

Parameters
stepSize:: Initial step size.
tolerance:: Tolerance.

Definition at line 91 of file DerivMinimizer.cpp.

References initGSLMMin().

◆ ~DerivMinimizer()

Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::~DerivMinimizer ( )
override

Destructor.

Definition at line 107 of file DerivMinimizer.cpp.

References m_gslSolver, and m_x.

Member Function Documentation

◆ calCovarianceMatrix()

void Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::calCovarianceMatrix ( gsl_matrix *  covar,
double  epsrel = 0.0001 
)

Calculate the covariance matrix.

◆ costFunctionVal()

double Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::costFunctionVal ( )
overridevirtual

Return current value of the cost function.

Implements Mantid::API::IFuncMinimizer.

Definition at line 172 of file DerivMinimizer.cpp.

References m_gslSolver.

◆ dfun()

void Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::dfun ( const gsl_vector *  x,
void *  params,
gsl_vector *  g 
)
staticprotected

Used by the GSL.

Used by the GSL to calculate the derivatives.

Parameters
x:: Vector with parameters
params:: Pointer to a DerivMinimizer
g:: Buffer for the derivatives

Definition at line 38 of file DerivMinimizer.cpp.

References m_costFunction, n, and Mantid::Geometry::x.

Referenced by initialize().

◆ fun()

double Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::fun ( const gsl_vector *  x,
void *  params 
)
staticprotected

Used by the GSL.

Used by the GSL to calculate the cost function.

Parameters
x:: Vector with parameters
params:: Pointer to a DerivMinimizer

Definition at line 19 of file DerivMinimizer.cpp.

References m_costFunction, n, and Mantid::Geometry::x.

Referenced by initialize().

◆ fundfun()

void Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::fundfun ( const gsl_vector *  x,
void *  params,
double *  f,
gsl_vector *  g 
)
staticprotected

Used by the GSL.

Used by the GSL to calculate the cost function and the derivatives.

Parameters
x:: Vector with parameters
params:: Pointer to a DerivMinimizer
f:: Buffer for the fanction value
g:: Buffer for the derivatives

Definition at line 62 of file DerivMinimizer.cpp.

References m_costFunction, n, and Mantid::Geometry::x.

Referenced by initialize().

◆ getGSLMinimizerType()

virtual const gsl_multimin_fdfminimizer_type * Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::getGSLMinimizerType ( )
protectedpure virtual

◆ initGSLMMin()

void Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::initGSLMMin ( )
private

simply init the values for the gsl minimizer

Definition at line 96 of file DerivMinimizer.cpp.

References m_gslMultiminContainer.

Referenced by DerivMinimizer().

◆ initialize()

void Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::initialize ( API::ICostFunction_sptr  function,
size_t  maxIterations = 0 
)
overridevirtual

Initialize minimizer, i.e. pass a function to minimize.

Initialize the minimizer.

Parameters
function:: A cost function to minimize.
maxIterations:: Maximum number of iterations.

Implements Mantid::API::IFuncMinimizer.

Definition at line 119 of file DerivMinimizer.cpp.

References dfun(), fun(), fundfun(), getGSLMinimizerType(), m_costFunction, m_gslMultiminContainer, m_gslSolver, m_stepSize, m_tolerance, m_x, and UNUSED_ARG.

◆ iterate()

bool Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::iterate ( size_t  )
overridevirtual

Do one iteration.

Perform one iteration.

Returns
:: true to continue, false to stop.

Implements Mantid::API::IFuncMinimizer.

Definition at line 144 of file DerivMinimizer.cpp.

References Mantid::API::IFuncMinimizer::m_errorString, m_gslSolver, m_stopGradient, and Mantid::API::IFuncMinimizer::name().

◆ setStopGradient()

void Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::setStopGradient ( const double  value)

Set maximum value of the gradient at which iterations can stop.

Parameters
value:: New value for the gradient, must be positive.

Definition at line 165 of file DerivMinimizer.cpp.

References m_stopGradient, and value.

Member Data Documentation

◆ m_costFunction

API::ICostFunction_sptr Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::m_costFunction
protected

Function to minimize.

Definition at line 51 of file DerivMinimizer.h.

Referenced by dfun(), fun(), fundfun(), and initialize().

◆ m_gslMultiminContainer

gsl_multimin_function_fdf Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::m_gslMultiminContainer
protected

GSL container.

Definition at line 57 of file DerivMinimizer.h.

Referenced by initGSLMMin(), and initialize().

◆ m_gslSolver

gsl_multimin_fdfminimizer* Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::m_gslSolver
protected

pointer to the GSL solver doing the work

Definition at line 54 of file DerivMinimizer.h.

Referenced by costFunctionVal(), initialize(), iterate(), and ~DerivMinimizer().

◆ m_stepSize

double Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::m_stepSize
protected

First trial step size.

Definition at line 65 of file DerivMinimizer.h.

Referenced by initialize().

◆ m_stopGradient

double Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::m_stopGradient
protected

the norm of the gradient at which iterations stop

Definition at line 63 of file DerivMinimizer.h.

Referenced by iterate(), and setStopGradient().

◆ m_tolerance

double Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::m_tolerance
protected

Tolerance.

Definition at line 67 of file DerivMinimizer.h.

Referenced by initialize().

◆ m_x

gsl_vector* Mantid::CurveFitting::FuncMinimisers::DerivMinimizer::m_x
protected

GSL vector with function parameters.

Definition at line 60 of file DerivMinimizer.h.

Referenced by initialize(), and ~DerivMinimizer().


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