lsst.afw gba399f52f3+9b61cfce8e
Loading...
Searching...
No Matches
lsst::afw::math::Function< ReturnT > Class Template Reference

Basic Function class. More...

#include <Function.h>

Inheritance diagram for lsst::afw::math::Function< ReturnT >:
lsst::afw::table::io::PersistableFacade< Function< ReturnT > > lsst::afw::math::Function1< Pixel > lsst::afw::math::Function2< double > lsst::afw::math::Function2< Pixel > lsst::afw::math::Function1< ReturnT > lsst::afw::math::Function2< ReturnT > lsst::afw::math::NullFunction2< double > lsst::afw::math::Chebyshev1Function1< ReturnT > lsst::afw::math::GaussianFunction1< ReturnT > lsst::afw::math::IntegerDeltaFunction1< ReturnT > lsst::afw::math::LanczosFunction1< ReturnT > lsst::afw::math::NullFunction1< ReturnT > lsst::afw::math::PolynomialFunction1< ReturnT > lsst::afw::math::BasePolynomialFunction2< ReturnT > lsst::afw::math::DoubleGaussianFunction2< ReturnT > lsst::afw::math::GaussianFunction2< ReturnT > lsst::afw::math::IntegerDeltaFunction2< ReturnT > lsst::afw::math::LanczosFunction2< ReturnT > lsst::afw::math::NullFunction2< ReturnT >

Public Member Functions

 Function (unsigned int nParams)
 Construct a Function given the number of function parameters.
 Function (std::vector< double > const &params)
 Construct a Function given the function parameters.
 Function (Function const &)=default
 Function (Function &&)=default
Function & operator= (Function const &)=default
Function & operator= (Function &&)=default
 ~Function () noexcept override=default
unsigned int getNParameters () const noexcept
 Return the number of function parameters.
virtual double getParameter (unsigned int ind) const
 Get one function parameter without range checking.
std::vector< double > const & getParameters () const noexcept
 Return all function parameters.
virtual bool isLinearCombination () const noexcept
 Is the function a linear combination of its parameters?
void setParameter (unsigned int ind, double newValue)
 Set one function parameter without range checking.
void setParameters (std::vector< double > const &params)
 Set all function parameters.
virtual std::string toString (std::string const &) const
 Return a string representation of the function.

Static Public Member Functions

static std::shared_ptr< Function< ReturnT > > readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object.
static std::shared_ptr< Function< ReturnT > > dynamicCast (std::shared_ptr< Persistable > const &ptr)
 Dynamically cast a shared_ptr.

Protected Member Functions

std::string getPythonModule () const override
 Function ()

Protected Attributes

std::vector< double > _params
bool _isCacheValid

Detailed Description

template<typename ReturnT>
class lsst::afw::math::Function< ReturnT >

Basic Function class.

Function objects are functions whose parameters may be read and changed using getParameters and setParameters. They were designed for use with the Kernel class.

These are simple functors with the restrictions that:

  • Function arguments and parameters are double precision
  • The return type is templated

To create a function for a particular equation, subclass Function or (much more likely) Function1 or Function2. Your subclass must:

  • Have one or more constructors, all of which must initialize _params
  • Define operator() with code to compute the function using this->_params or this->getParams() to reference the parameters
  • If the function is a linear combination of parameters then override the function isLinearCombination.

If you wish to cache any information you may use the _isCacheValid flag; this is automatically set false whenever parameters are changed.

Design Notes: The reason these functions exist (rather than using a pre-existing function class, such as Functor in VisualWorkbench) is because the Kernel class requires function objects with a standard interface for setting and getting function parameters.

The reason isLinearCombination exists is to support refactoring LinearCombinationKernels.

Definition at line 83 of file Function.h.

Constructor & Destructor Documentation

◆ Function() [1/5]

template<typename ReturnT>
lsst::afw::math::Function< ReturnT >::Function ( unsigned int nParams)
inlineexplicit

Construct a Function given the number of function parameters.

The function parameters are initialized to 0.

Parameters
nParamsnumber of function parameters

Definition at line 91 of file Function.h.

◆ Function() [2/5]

template<typename ReturnT>
lsst::afw::math::Function< ReturnT >::Function ( std::vector< double > const & params)
inlineexplicit

Construct a Function given the function parameters.

Parameters
paramsfunction parameters

Definition at line 97 of file Function.h.

◆ Function() [3/5]

template<typename ReturnT>
lsst::afw::math::Function< ReturnT >::Function ( Function< ReturnT > const & )
default

◆ Function() [4/5]

template<typename ReturnT>
lsst::afw::math::Function< ReturnT >::Function ( Function< ReturnT > && )
default

◆ ~Function()

template<typename ReturnT>
lsst::afw::math::Function< ReturnT >::~Function ( )
overridedefaultnoexcept

◆ Function() [5/5]

template<typename ReturnT>
lsst::afw::math::Function< ReturnT >::Function ( )
inlineexplicitprotected

Definition at line 191 of file Function.h.

Member Function Documentation

◆ dynamicCast()

template std::shared_ptr< math::WarpingControl > lsst::afw::table::io::PersistableFacade< Function< ReturnT > >::dynamicCast ( std::shared_ptr< Persistable > const & ptr)
staticinherited

Dynamically cast a shared_ptr.

Dynamically cast a shared pointer and raise on failure.

You must provide an explicit template instantiation in the .cc file for each class that inherits from PersistableFacade. Designed to work around RTTI issues on macOS with hidden symbols;

Exceptions
lsst::pex::exceptions::LogicErrorif the cast fails

param[in] ptr The pointer to be cast.

Returns
The cast pointer.
Exceptions
lsst::pex::exceptions::TypeErrorIf the dynamic cast fails.

Definition at line 218 of file Persistable.cc.

◆ getNParameters()

template<typename ReturnT>
unsigned int lsst::afw::math::Function< ReturnT >::getNParameters ( ) const
inlinenoexcept

Return the number of function parameters.

Returns
the number of function parameters

Definition at line 112 of file Function.h.

◆ getParameter()

template<typename ReturnT>
virtual double lsst::afw::math::Function< ReturnT >::getParameter ( unsigned int ind) const
inlinevirtual

Get one function parameter without range checking.

Returns
the specified function parameter
Parameters
indindex of parameter

Definition at line 119 of file Function.h.

◆ getParameters()

template<typename ReturnT>
std::vector< double > const & lsst::afw::math::Function< ReturnT >::getParameters ( ) const
inlinenoexcept

Return all function parameters.

Returns
the function parameters as a vector

Definition at line 129 of file Function.h.

◆ getPythonModule()

template<typename ReturnT>
std::string lsst::afw::math::Function< ReturnT >::getPythonModule ( ) const
inlineoverrideprotected

Definition at line 188 of file Function.h.

◆ isLinearCombination()

template<typename ReturnT>
virtual bool lsst::afw::math::Function< ReturnT >::isLinearCombination ( ) const
inlinevirtualnoexcept

Is the function a linear combination of its parameters?

Returns
true if the function can be expressed as: sum over i of parameter_i * function_i(args)
Warning
: subclasses must override if true.

Reimplemented in lsst::afw::math::BasePolynomialFunction2< ReturnT >, lsst::afw::math::Chebyshev1Function1< ReturnT >, and lsst::afw::math::PolynomialFunction1< ReturnT >.

Definition at line 138 of file Function.h.

◆ operator=() [1/2]

template<typename ReturnT>
Function & lsst::afw::math::Function< ReturnT >::operator= ( Function< ReturnT > && )
default

◆ operator=() [2/2]

template<typename ReturnT>
Function & lsst::afw::math::Function< ReturnT >::operator= ( Function< ReturnT > const & )
default

◆ readFits()

std::shared_ptr< Function< ReturnT > > lsst::afw::table::io::PersistableFacade< Function< ReturnT > >::readFits ( fits::Fits & fitsfile)
inlinestaticinherited

Read an object from an already open FITS object.

Parameters
[in]fitsfileFITS object to read from, already positioned at the desired HDU.

Definition at line 183 of file Persistable.h.

◆ setParameter()

template<typename ReturnT>
void lsst::afw::math::Function< ReturnT >::setParameter ( unsigned int ind,
double newValue )
inline

Set one function parameter without range checking.

Parameters
indindex of parameter
newValuenew value for parameter

Definition at line 143 of file Function.h.

◆ setParameters()

template<typename ReturnT>
void lsst::afw::math::Function< ReturnT >::setParameters ( std::vector< double > const & params)
inline

Set all function parameters.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif the wrong number of parameters is supplied.
Parameters
paramsvector of function parameters

Definition at line 156 of file Function.h.

◆ toString()

Member Data Documentation

◆ _isCacheValid

template<typename ReturnT>
bool lsst::afw::math::Function< ReturnT >::_isCacheValid
mutableprotected

Definition at line 186 of file Function.h.

◆ _params

template<typename ReturnT>
std::vector<double> lsst::afw::math::Function< ReturnT >::_params
protected

Definition at line 185 of file Function.h.


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