Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

FunctionWrap Class Reference

A wrapper class for FunctionBase. More...

#include <FunctionWrap.h>

Inheritance diagram for FunctionWrap:
Inheritance graph
[legend]
Collaboration diagram for FunctionWrap:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void addToComposite (FunctionBase *)
 Does nothing.
FunctionBaseclone () const
 Make copy of object, including copy of Python object.
virtual FunctionBaseclone () const
 Creates a new function object by copying an existing one.
virtual int count ()
 Returns 0.
double derivByParm (int, double) const
virtual double derivByParm (int i, double x) const
 Returns the function's derivative at the coordinate value x with respect to the i-th parameter.
virtual unsigned int dimensions () const
 Returns the number of dimensions of the data coordinate.
unsigned int dimensions () const
 FunctionWrap (const FunctionWrap &)
 The copy constructor.
 FunctionWrap (const FunctionBase &base)
 Constructor.
 FunctionWrap ()
 The default constructor.
virtual const std::vector
< double > & 
getParameters () const
 Returns the values of the parameters as a vector.
virtual bool hasDerivatives () const
 Returns true if the Python function has implemented returning partial derivatives.
virtual bool hasDerivatives () const
 Returns true if function can calculate its partial derivatives.
void initialize ()
virtual void initialParameters (const FunctionHelper *helper)
 Sets the FunctionHelper so that the function can calculate a reasonable set of initial parameter values.
void initialParameters (const FunctionHelper *)
virtual double integrate (double lower_limit, double upper_limit) const
 Returns the integral of the function from the lower limit to the higher limit.
virtual bool isComposite () const
 Returns false.
const std::string & name () const
 Returns the name of the function.
virtual double operator() (double x) const
 The function call operator.
double operator() (const std::vector< double > &) const
double operator() (double) const
virtual double operator() (const std::vector< double > &v) const
 The function call operator for multi-dimension coordinate variable.
virtual const std::vector
< std::string > & 
parmNames () const
 Returns a reference to a vector of parameter names.
virtual void removeFromComposite (FunctionBase *)
 Does nothing.
void setName (const std::string &name)
 Sets the name of the function.
virtual std::vector< double >
::const_iterator 
setParameters (std::vector< double >::const_iterator it)
 Sets the parameter values to the value pointed to by the iterator.
virtual void setParameters (const std::vector< double > &incr)
 Sets the parameter values.
void setParmNames (const std::vector< std::string > &names)
 Sets the names of the parameters.
void setParmNames (const std::vector< std::string > &names)
 Sets the names of the parameters and re-sizes the number of parameters available.
virtual int size () const
 Returns the number of parameters.
virtual ~FunctionWrap ()
 The destructor.

Protected Member Functions

virtual void initialize ()
 Initializes the function and parameter names.
virtual void resize ()
 Re-sizes the appropriate vectors maintained in this base class.
void setName (const char *)
 Sets the name of the function.

Protected Attributes

std::string m_name
 The name of the function.
std::vector< std::string > m_parm_names
 The names of the function parameters.
std::vector< double > m_parms
 The parameter values.

Private Member Functions

template<class T >
boost::python::object get_owner (T *me) const
 Find the Python object that owns this object.

Private Attributes

boost::python::object invert_ownership
 The new ownership.

Detailed Description

A wrapper class for FunctionBase.

This class allows one to implement in Python a derived class of FunctionBase.

Note:
This class needs Python 2.3 or later to be fully functional.
Author:
Paul F. Kunz <Paul_Kunz@slac.stanford.edu>

with a lot of help from David Abrahams <dave@boost-consulting.com>

Definition at line 30 of file FunctionWrap.h.


Constructor & Destructor Documentation

FunctionWrap ( const FunctionBase base  ) 

Constructor.

Definition at line 110 of file FunctionWrap.cxx.

FunctionWrap ( const FunctionWrap wrap  ) 

The copy constructor.

Definition at line 116 of file FunctionWrap.cxx.

FunctionWrap (  ) 

The default constructor.

Definition at line 104 of file FunctionWrap.cxx.

~FunctionWrap (  )  [virtual]

The destructor.

Definition at line 122 of file FunctionWrap.cxx.

References FunctionWrap::get_owner().


Member Function Documentation

void addToComposite ( FunctionBase  )  [virtual, inherited]

Does nothing.

Derived classes that are a composite of functions should override this member function and add functions to the composite.

Reimplemented in LinearSumFunction.

Definition at line 166 of file FunctionBase.cxx.

FunctionBase * clone (  )  const

Make copy of object, including copy of Python object.

Note:
One can't call clone() if implemented in the Python class, because if it constructs a new object, it will also destroy it thus leaving a dangling reference for C++. The attempting to do that is commented out in the implementation. Since all the C++ FunctionBase prototypes in the FunctionFactory are created with their default constructor, this implementation just calls the default constructor of the Python class. The net effect should be the same as a call to clone(). See http://mail.python.org/pipermail/c++-sig/2005-July/009262.html

Definition at line 183 of file FunctionWrap.cxx.

References FunctionWrap::get_owner(), and FunctionWrap::invert_ownership.

FunctionBase * clone (  )  const [virtual, inherited]

Creates a new function object by copying an existing one.

The implementation raises an assertion as this member function should be reimplemented in s derived class.

Note:
There's an implementation here to satisfy the SIP interface.

Reimplemented in BrokenPowerLaw, Chi2Dist, ConstantF, Erfc, Exponential, Gaussian, Landau, Linear, LinearSumFunction, LogNormal, LogParabola, Novosibirsk, PowerLaw, Quadratic, and Quadratic2.

Definition at line 52 of file FunctionBase.cxx.

int count (  )  [virtual, inherited]

Returns 0.

Derived classes that are a composite of functions should override this member function to return the number of functions in the composite.

Reimplemented in LinearSumFunction.

Definition at line 174 of file FunctionBase.cxx.

double derivByParm ( int  i,
double  x 
) const
Note:
This member function is only available with Python 2.3 or later.
Bug:
Should attempt to call derivByParm to implement hasDerivatives()

Definition at line 255 of file FunctionWrap.cxx.

References FunctionWrap::get_owner().

double derivByParm ( int  i,
double  x 
) const [virtual, inherited]

Returns the function's derivative at the coordinate value x with respect to the i-th parameter.

Derived classes must implement this function.

Todo:
Provide a numeric method for doing this calculation that will be the default. Derived classes should provide more efficient analytic method if available.
Bug:
Make this function pure when problem compiling python/FunctionWrap under Windows is solved.

Reimplemented in BrokenPowerLaw, Chi2Dist, ConstantF, Erfc, Exponential, Gaussian, Landau, Linear, LinearSumFunction, LogNormal, LogParabola, Novosibirsk, PowerLaw, Quadratic, and Quadratic2.

Definition at line 190 of file FunctionBase.cxx.

unsigned int dimensions (  )  const

Definition at line 148 of file FunctionWrap.cxx.

References FunctionWrap::get_owner().

unsigned int dimensions (  )  const [virtual, inherited]

Returns the number of dimensions of the data coordinate.

This implementation in the base class returns 1. Derived class should override this function if the data coordinate is multi-dimensional.

Definition at line 213 of file FunctionBase.cxx.

object get_owner ( T *  me  )  const [private]
const vector< double > & getParameters (  )  const [virtual, inherited]

Returns the values of the parameters as a vector.

The function is non-const because a derived class may need to create the vector.

Reimplemented in LinearSumFunction.

Definition at line 99 of file FunctionBase.cxx.

References FunctionBase::m_parms.

Referenced by FunctionProjectorXML::createElement(), FuncParmRep::drawProjectedValues(), FunctionRep::parameters(), FunctionProjector::saveParameters(), and FunctionProjector::setParameters().

bool hasDerivatives (  )  const [virtual]

Returns true if the Python function has implemented returning partial derivatives.

Definition at line 170 of file FunctionWrap.cxx.

bool hasDerivatives (  )  const [virtual, inherited]

Returns true if function can calculate its partial derivatives.

This base class implementation returns true. Derived class that can not calculate its partial derivatives should return false. This allows an application to not attempt to use a minimizer that requires derivatives to use this function.

Reimplemented in LogNormal, LogParabola, and Novosibirsk.

Definition at line 126 of file FunctionBase.cxx.

void initialize (  ) 
Note:
This function is only available for Python 2.3 or later.

Definition at line 283 of file FunctionWrap.cxx.

References FunctionWrap::get_owner(), and FunctionBase::resize().

void initialize (  )  [protected, virtual, inherited]

Initializes the function and parameter names.

The derived classes should initialize their names and the vector of parameter names and then invoke the resize() member function.

Note:
Make this member pure when problem compiling python/FunctionWrap under Windows is solved.

Reimplemented in BrokenPowerLaw, Chi2Dist, ConstantF, Erfc, Exponential, Gaussian, Landau, Linear, LinearSumFunction, LogNormal, LogParabola, Novosibirsk, PowerLaw, Quadratic, and Quadratic2.

Definition at line 198 of file FunctionBase.cxx.

void initialParameters ( const FunctionHelper helper  )  [virtual, inherited]

Sets the FunctionHelper so that the function can calculate a reasonable set of initial parameter values.

Reimplemented in BrokenPowerLaw, Chi2Dist, ConstantF, Erfc, Exponential, Gaussian, Landau, Linear, LinearSumFunction, LogNormal, LogParabola, Novosibirsk, PowerLaw, Quadratic, and Quadratic2.

Definition at line 60 of file FunctionBase.cxx.

Referenced by FunctionProjector::initializeFunction().

void initialParameters ( const FunctionHelper  ) 

Definition at line 359 of file FunctionWrap.cxx.

double integrate ( double  a,
double  b 
) const [virtual, inherited]

Returns the integral of the function from the lower limit to the higher limit.

As of now all the integration is done here numerically using the trapezoidal rule. Derived class may implement an analytical expression in place of this numerical method.

Requests:
Override this method in derived classes when calculation of integral can be done analyically.
Requests:
Check if this is the best algorithm. Its looks different from the one found in http://osl.iu.edu/%7Etveldhui/papers/techniques/

Definition at line 138 of file FunctionBase.cxx.

References FunctionBase::operator()().

bool isComposite (  )  const [virtual, inherited]

Returns false.

Derived classes that are a composite of functions should override this member function and return true.

Reimplemented in LinearSumFunction.

Definition at line 161 of file FunctionBase.cxx.

Referenced by FunctionRep::isComposite(), FunctionController::restoreParameters(), and FunctionController::saveParameters().

const string & name (  )  const [inherited]
double operator() ( double  x  )  const [virtual, inherited]

The function call operator.

Bug:
Make this member pure when problem compiling python/FunctionWrap is solved.

Reimplemented in BrokenPowerLaw, Chi2Dist, ConstantF, Erfc, Exponential, Gaussian, Landau, Linear, LinearSumFunction, LogNormal, LogParabola, Novosibirsk, PowerLaw, Quadratic, and Quadratic2.

Definition at line 205 of file FunctionBase.cxx.

Referenced by FunctionBase::integrate(), and FunctionBase::operator()().

double operator() ( const std::vector< double > &  x  )  const
Note:
This function is only available for Python 2.3 or later.

Definition at line 329 of file FunctionWrap.cxx.

References FunctionWrap::get_owner(), and FunctionBase::size().

double operator() ( const std::vector< double > &  v  )  const [virtual, inherited]

The function call operator for multi-dimension coordinate variable.

Returns the value of the function at coordinate represented by v. The implementation in this base class uses the first element of the vector and calls operator () ( double ).

Definition at line 181 of file FunctionBase.cxx.

References FunctionBase::operator()().

double operator() ( double  x  )  const
Note:
This function is only available for Python 2.3 or later.
Requests:
Why is exception being thrown for logParabolic.py and are we handling the fix correctly

Definition at line 303 of file FunctionWrap.cxx.

References FunctionWrap::get_owner().

const vector< string > & parmNames (  )  const [virtual, inherited]

Returns a reference to a vector of parameter names.

Reimplemented in LinearSumFunction.

Definition at line 86 of file FunctionBase.cxx.

References FunctionBase::m_parm_names.

Referenced by FuncParmRep::drawProjectedValues(), and FunctionRep::parmNames().

void removeFromComposite ( FunctionBase  )  [virtual, inherited]

Does nothing.

Derived classes that are a composite of functions should override this member function and remove functions from the composite.

Reimplemented in LinearSumFunction.

Definition at line 170 of file FunctionBase.cxx.

void resize (  )  [protected, virtual, inherited]
void setName ( const char *  name  )  [protected, inherited]

Sets the name of the function.

Definition at line 66 of file FunctionBase.cxx.

References FunctionBase::m_name.

void setName ( const std::string &  name  ) 

Sets the name of the function.

Note:
We have this function here so that FunctionBase::setName can remain protected and yet the Boost.Python and SIP interfaces can call this public member function.

Definition at line 236 of file FunctionWrap.cxx.

vector< double >::const_iterator setParameters ( std::vector< double >::const_iterator  it  )  [virtual, inherited]

Sets the parameter values to the value pointed to by the iterator.

Returns an iterator to a data element one past the last used data element.

Reimplemented in LinearSumFunction.

Definition at line 114 of file FunctionBase.cxx.

References FunctionBase::m_parms, and FunctionBase::size().

void setParameters ( const std::vector< double > &  incr  )  [virtual, inherited]

Sets the parameter values.

Derived classes should implement this function by invoking incrementValues ( vector< double >::const_iterator ) so that they correctly work with the LinearSumFunction class.

Definition at line 106 of file FunctionBase.cxx.

Referenced by FunctionProjector::restoreParameters(), FunctionProjectorXML::setAttributes(), and FunctionProjector::setParameters().

void setParmNames ( const std::vector< std::string > &  names  )  [inherited]

Sets the names of the parameters.

Definition at line 93 of file FunctionBase.cxx.

References FunctionBase::m_parm_names, and FunctionBase::resize().

void setParmNames ( const std::vector< std::string > &  names  ) 

Sets the names of the parameters and re-sizes the number of parameters available.

Definition at line 243 of file FunctionWrap.cxx.

References FunctionBase::m_parm_names, and FunctionBase::resize().

int size (  )  const [virtual, inherited]

Member Data Documentation

boost::python::object invert_ownership [private]

The new ownership.

Definition at line 37 of file FunctionWrap.h.

Referenced by FunctionWrap::clone().

std::string m_name [protected, inherited]
std::vector<std::string> m_parm_names [protected, inherited]
std::vector< double > m_parms [protected, inherited]

The parameter values.

Definition at line 109 of file FunctionBase.h.

Referenced by BrokenPowerLaw::BrokenPowerLaw(), Erfc::calcRed(), Chi2Dist::Chi2Dist(), ConstantF::ConstantF(), Gaussian::derivByMean(), Landau::derivByNorm(), Gaussian::derivByNorm(), Quadratic2::derivByParm(), PowerLaw::derivByParm(), LogParabola::derivByParm(), Exponential::derivByParm(), Erfc::derivByParm(), Chi2Dist::derivByParm(), BrokenPowerLaw::derivByParm(), Landau::derivByPeak(), Landau::derivBySigma(), Gaussian::derivBySigma(), Erfc::Erfc(), Exponential::Exponential(), Gaussian::Gaussian(), LinearSumFunction::getParameters(), FunctionBase::getParameters(), Quadratic2::initialParameters(), Quadratic::initialParameters(), PowerLaw::initialParameters(), Novosibirsk::initialParameters(), LogParabola::initialParameters(), LogNormal::initialParameters(), Linear::initialParameters(), Landau::initialParameters(), Gaussian::initialParameters(), Exponential::initialParameters(), Erfc::initialParameters(), ConstantF::initialParameters(), Chi2Dist::initialParameters(), BrokenPowerLaw::initialParameters(), Landau::Landau(), Linear::Linear(), LogNormal::LogNormal(), LogParabola::LogParabola(), Novosibirsk::Novosibirsk(), Quadratic2::operator()(), Quadratic::operator()(), PowerLaw::operator()(), Novosibirsk::operator()(), LogParabola::operator()(), LogNormal::operator()(), Linear::operator()(), Landau::operator()(), Gaussian::operator()(), Exponential::operator()(), ConstantF::operator()(), Chi2Dist::operator()(), BrokenPowerLaw::operator()(), PowerLaw::PowerLaw(), Quadratic::Quadratic(), Quadratic2::Quadratic2(), FunctionBase::resize(), and FunctionBase::setParameters().


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

Generated for HippoDraw Class Library by doxygen