LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lsst.afw.math::PolynomialFunction2< ReturnT > Class Template Reference

2-dimensional polynomial function with cross terms More...

#include <FunctionLibrary.h>

Inheritance diagram for lsst.afw.math::PolynomialFunction2< ReturnT >:
lsst.afw.math::BasePolynomialFunction2< ReturnT > lsst.afw.math::Function2< ReturnT > lsst.afw.table.io::PersistableFacade< Function2< ReturnT > > lsst.afw.math::Function< ReturnT > lsst::daf::base::Citizen lsst.afw.table.io::PersistableFacade< Function< ReturnT > > lsst.afw.table.io::Persistable

Public Types

typedef Function2< ReturnT >::Ptr Function2Ptr
 
- Public Types inherited from lsst.afw.math::BasePolynomialFunction2< ReturnT >
typedef Function2< ReturnT >::Ptr Function2Ptr
 
- Public Types inherited from lsst.afw.math::Function2< ReturnT >
typedef boost::shared_ptr
< Function2< ReturnT > > 
Ptr
 
- Public Types inherited from lsst::daf::base::Citizen
enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback )(const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback )(const Citizen *ptr)
 

Public Member Functions

 PolynomialFunction2 (unsigned int order)
 Construct a polynomial function of specified order. More...
 
 PolynomialFunction2 (std::vector< double > params)
 Construct a polynomial function with specified parameters. More...
 
virtual ~PolynomialFunction2 ()
 
virtual Function2Ptr clone () const
 Return a pointer to a deep copy of this function. More...
 
virtual ReturnT operator() (double x, double y) const
 
virtual std::vector< double > getDFuncDParameters (double x, double y) const
 
virtual std::string toString (std::string const &prefix) const
 Return a string representation of the function. More...
 
virtual bool isPersistable () const
 Return true if this particular object can be persisted using afw::table::io. More...
 
- Public Member Functions inherited from lsst.afw.math::BasePolynomialFunction2< ReturnT >
 BasePolynomialFunction2 (unsigned int order)
 Construct a polynomial function of specified order. More...
 
 BasePolynomialFunction2 (std::vector< double > params)
 Construct a polynomial function with specified parameters. More...
 
virtual ~BasePolynomialFunction2 ()
 
int getOrder () const
 Get the polynomial order. More...
 
virtual bool isLinearCombination () const
 Is the function a linear combination of its parameters? More...
 
- Public Member Functions inherited from lsst.afw.math::Function2< ReturnT >
 Function2 (unsigned int nParams)
 Construct a Function2 given the number of function parameters. More...
 
 Function2 (std::vector< double > const &params)
 Construct a Function2 given the function parameters. More...
 
virtual ~Function2 ()
 
- Public Member Functions inherited from lsst.afw.math::Function< ReturnT >
 Function (unsigned int nParams)
 Construct a Function given the number of function parameters. More...
 
 Function (std::vector< double > const &params)
 Construct a Function given the function parameters. More...
 
virtual ~Function ()
 
unsigned int getNParameters () const
 Return the number of function parameters. More...
 
virtual double getParameter (unsigned int ind) const
 Get one function parameter without range checking. More...
 
std::vector< double > const & getParameters () const
 Return all function parameters. More...
 
void setParameter (unsigned int ind, double newValue)
 Set one function parameter without range checking. More...
 
void setParameters (std::vector< double > const &params)
 Set all function parameters. More...
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 
- Public Member Functions inherited from lsst.afw.table.io::Persistable
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file. More...
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory. More...
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object. More...
 
virtual ~Persistable ()
 

Protected Member Functions

virtual std::string getPersistenceName () const
 Return the unique name used to persist this object and look up its factory. More...
 
virtual void write (afw::table::io::OutputArchiveHandle &handle) const
 Write the object to one or more catalogs. More...
 
 PolynomialFunction2 ()
 
- Protected Member Functions inherited from lsst.afw.math::BasePolynomialFunction2< ReturnT >
 BasePolynomialFunction2 ()
 
- Protected Member Functions inherited from lsst.afw.math::Function2< ReturnT >
 Function2 ()
 
- Protected Member Functions inherited from lsst.afw.math::Function< ReturnT >
virtual std::string getPythonModule () const
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More...
 
 Function ()
 
- Protected Member Functions inherited from lsst.afw.table.io::Persistable
 Persistable ()
 
 Persistable (Persistable const &other)
 
void operator= (Persistable const &other)
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, unsigned int const version)
 

Private Attributes

double _oldY
 value of y for which _xCoeffs is valid More...
 
std::vector< double > _xCoeffs
 working vector More...
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst.afw.math::BasePolynomialFunction2< ReturnT >
static int nParametersFromOrder (int order)
 Compute number of parameters from polynomial order. More...
 
static int orderFromNParameters (int nParameters)
 Compute polynomial order from the number of parameters. More...
 
- Static Public Member Functions inherited from lsst.afw.table.io::PersistableFacade< Function2< ReturnT > >
static boost::shared_ptr
< Function2< ReturnT > > 
readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static boost::shared_ptr
< Function2< ReturnT > > 
readFits (std::string const &fileName, int hdu=0)
 Read an object from a regular FITS file. More...
 
static boost::shared_ptr
< Function2< ReturnT > > 
readFits (fits::MemFileManager &manager, int hdu=0)
 Read an object from a FITS file in memory. More...
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector
< const Citizen * > * 
census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 
- Static Public Member Functions inherited from lsst.afw.table.io::PersistableFacade< Function< ReturnT > >
static boost::shared_ptr
< Function< ReturnT > > 
readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static boost::shared_ptr
< Function< ReturnT > > 
readFits (std::string const &fileName, int hdu=0)
 Read an object from a regular FITS file. More...
 
static boost::shared_ptr
< Function< ReturnT > > 
readFits (fits::MemFileManager &manager, int hdu=0)
 Read an object from a FITS file in memory. More...
 
- Protected Types inherited from lsst.afw.table.io::Persistable
typedef io::OutputArchiveHandle OutputArchiveHandle
 
- Protected Attributes inherited from lsst.afw.math::BasePolynomialFunction2< ReturnT >
int _order
 order of polynomial More...
 
- Protected Attributes inherited from lsst.afw.math::Function< ReturnT >
std::vector< double > _params
 
bool _isCacheValid
 

Detailed Description

template<typename ReturnT>
class lsst.afw.math::PolynomialFunction2< ReturnT >

2-dimensional polynomial function with cross terms

f(x,y) = c0 (0th order)

Intermediate products for the most recent y are cached, so when computing for a set of x, y it is more efficient to change x before you change y.

Definition at line 524 of file FunctionLibrary.h.

Member Typedef Documentation

template<typename ReturnT>
typedef Function2<ReturnT>::Ptr lsst.afw.math::PolynomialFunction2< ReturnT >::Function2Ptr

Definition at line 526 of file FunctionLibrary.h.

Constructor & Destructor Documentation

template<typename ReturnT>
lsst.afw.math::PolynomialFunction2< ReturnT >::PolynomialFunction2 ( unsigned int  order)
inlineexplicit

Construct a polynomial function of specified order.

The polynomial will have (order + 1) * (order + 2) / 2 coefficients

The parameters are initialized to zero.

Parameters
orderorder of polynomial (0 for constant)

Definition at line 535 of file FunctionLibrary.h.

537  :
538  BasePolynomialFunction2<ReturnT>(order),
539  _oldY(0),
540  _xCoeffs(this->_order + 1)
541  {}
int _order
order of polynomial
Definition: Function.h:492
double _oldY
value of y for which _xCoeffs is valid
std::vector< double > _xCoeffs
working vector
template<typename ReturnT>
lsst.afw.math::PolynomialFunction2< ReturnT >::PolynomialFunction2 ( std::vector< double >  params)
inlineexplicit

Construct a polynomial function with specified parameters.

The order of the polynomial is determined from the length of the params vector: order = (sqrt(1 + 8 * length) - 3) / 2 and if this is not an integer then the length is unsuitable

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif params length is unsuitable
lsst::pex::exceptions::Exceptionif an internal sanity check fails
Parameters
paramspolynomial coefficients (const, x, y, x^2, xy, y^2...); length must be one of 1, 3, 6, 10, 15...

Definition at line 553 of file FunctionLibrary.h.

556  :
557  BasePolynomialFunction2<ReturnT>(params),
558  _oldY(0),
559  _xCoeffs(this->_order + 1)
560  {}
int _order
order of polynomial
Definition: Function.h:492
double _oldY
value of y for which _xCoeffs is valid
std::vector< double > _xCoeffs
working vector
template<typename ReturnT>
virtual lsst.afw.math::PolynomialFunction2< ReturnT >::~PolynomialFunction2 ( )
inlinevirtual

Definition at line 562 of file FunctionLibrary.h.

562 {}
template<typename ReturnT>
lsst.afw.math::PolynomialFunction2< ReturnT >::PolynomialFunction2 ( )
inlineexplicitprotected

Definition at line 641 of file FunctionLibrary.h.

641 : BasePolynomialFunction2<ReturnT>(), _oldY(0), _xCoeffs(0) {}
double _oldY
value of y for which _xCoeffs is valid
std::vector< double > _xCoeffs
working vector

Member Function Documentation

template<typename ReturnT>
virtual Function2Ptr lsst.afw.math::PolynomialFunction2< ReturnT >::clone ( ) const
inlinevirtual

Return a pointer to a deep copy of this function.

This function exists instead of a copy constructor so one can obtain a copy of an actual function instead of a useless copy of the base class.

Every non-virtual function must override this method.

Returns
a pointer to a deep copy of the function

Implements lsst.afw.math::Function2< ReturnT >.

Definition at line 564 of file FunctionLibrary.h.

564  {
565  return Function2Ptr(new PolynomialFunction2(this->_params));
566  }
Function2< ReturnT >::Ptr Function2Ptr
std::vector< double > _params
Definition: Function.h:204
template<typename ReturnT >
std::vector< double > lsst.afw.math::PolynomialFunction2< ReturnT >::getDFuncDParameters ( double  x,
double  y 
) const
virtual

Return the coefficients of the Function's parameters, evaluated at (x, y) I.e. given c0, c1, c2, c3 ... return 1, x, y, x^2 ...

Reimplemented from lsst.afw.math::BasePolynomialFunction2< ReturnT >.

Definition at line 36 of file Function.cc.

36  {
37  std::vector<double> coeffs(this->getNParameters());
38 
39  //
40  // Go through params order by order, evaluating x^r y^s; we do this by first evaluating
41  // y^s for a complete order, then going through again multiplying by x^r
42  //
43  int i0 = 0; // starting index for this order's coefficients
44  for (int order = 0; order <= this->_order; ++order) {
45  coeffs[i0] = 1;
46  double zn = y; // y^s
47  for (int i = 1; i <= order; ++i) {
48  coeffs[i0 + i] = zn;
49  zn *= y;
50  }
51 
52  zn = x; // x^r
53  for (int i = order - 1; i >= 0; --i) {
54  coeffs[i0 + i] *= zn;
55  zn *= x;
56  }
57 
58 
59  i0 += order + 1;
60  }
61 
62  assert (i0 == static_cast<int>(coeffs.size()));
63 
64  return coeffs;
65 }
int y
int _order
order of polynomial
Definition: Function.h:492
unsigned int getNParameters() const
Return the number of function parameters.
Definition: Function.h:125
int x
template<typename ReturnT>
virtual std::string lsst.afw.math::PolynomialFunction2< ReturnT >::getPersistenceName ( ) const
protectedvirtual

Return the unique name used to persist this object and look up its factory.

Must be less than ArchiveIndexSchema::MAX_NAME_LENGTH characters.

Reimplemented from lsst.afw.table.io::Persistable.

template<typename ReturnT>
virtual bool lsst.afw.math::PolynomialFunction2< ReturnT >::isPersistable ( ) const
inlinevirtual

Return true if this particular object can be persisted using afw::table::io.

Reimplemented from lsst.afw.table.io::Persistable.

Definition at line 627 of file FunctionLibrary.h.

627 { return true; }
template<typename ReturnT>
virtual ReturnT lsst.afw.math::PolynomialFunction2< ReturnT >::operator() ( double  x,
double  y 
) const
inlinevirtual

Implements lsst.afw.math::Function2< ReturnT >.

Definition at line 568 of file FunctionLibrary.h.

568  {
569  /* Solve as follows:
570  - f(x,y) = Cx0 + Cx1 x + Cx2 x^2 + Cx3 x^3 + ...
571  where:
572  Cx0 = P0 + P2 y + P5 y^2 + P9 y^3 + ...
573  Cx1 = P1 + P4 y + P8 y2 + ...
574  Cx2 = P3 + P7 y + ...
575  Cx3 = P6 + ...
576  ...
577 
578  Compute Cx0, Cx1...Cxn by solving 1-d polynomials in y in the usual way.
579  These values are cached and only recomputed for new values of Y or if the parameters change.
580 
581  Then compute f(x,y) by solving the 1-d polynomial in x in the usual way.
582  */
583  const int maxXCoeffInd = this->_order;
584 
585  if ((y != _oldY) || !this->_isCacheValid) {
586  // update _xCoeffs cache
587  // note: paramInd is decremented in both of the following loops
588  int paramInd = static_cast<int>(this->_params.size()) - 1;
589 
590  // initialize _xCoeffs to coeffs for pure y^n; e.g. for 3rd order:
591  // _xCoeffs[0] = _params[9], _xCoeffs[1] = _params[8], ... _xCoeffs[3] = _params[6]
592  for (int xCoeffInd = 0; xCoeffInd <= maxXCoeffInd; ++xCoeffInd, --paramInd) {
593  _xCoeffs[xCoeffInd] = this->_params[paramInd];
594  }
595 
596  // finish computing _xCoeffs
597  for (int xCoeffInd = 0, endXCoeffInd = maxXCoeffInd; paramInd >= 0; --paramInd) {
598  _xCoeffs[xCoeffInd] = (_xCoeffs[xCoeffInd] * y) + this->_params[paramInd];
599  ++xCoeffInd;
600  if (xCoeffInd >= endXCoeffInd) {
601  xCoeffInd = 0;
602  --endXCoeffInd;
603  }
604  }
605 
606  _oldY = y;
607  this->_isCacheValid = true;
608  }
609 
610  // use _xCoeffs to compute result
611  double retVal = _xCoeffs[maxXCoeffInd];
612  for (int xCoeffInd = maxXCoeffInd - 1; xCoeffInd >= 0; --xCoeffInd) {
613  retVal = (retVal * x) + _xCoeffs[xCoeffInd];
614  }
615  return static_cast<ReturnT>(retVal);
616  }
int y
int _order
order of polynomial
Definition: Function.h:492
double _oldY
value of y for which _xCoeffs is valid
std::vector< double > _xCoeffs
working vector
int x
std::vector< double > _params
Definition: Function.h:204
template<typename ReturnT>
template<class Archive >
void lsst.afw.math::PolynomialFunction2< ReturnT >::serialize ( Archive &  ar,
unsigned int const  version 
)
inlineprivate

Definition at line 646 of file FunctionLibrary.h.

646  {
647  ar & make_nvp("fn2", boost::serialization::base_object<BasePolynomialFunction2<ReturnT> >(*this));
648  ar & make_nvp("yCoeffs", this->_xCoeffs); // sets size of _xCoeffs; name is historical
649  }
std::vector< double > _xCoeffs
working vector
template<typename ReturnT>
virtual std::string lsst.afw.math::PolynomialFunction2< ReturnT >::toString ( std::string const &  ) const
inlinevirtual

Return a string representation of the function.

Returns
a string representation of the function

Reimplemented from lsst.afw.math::Function2< ReturnT >.

Definition at line 620 of file FunctionLibrary.h.

620  {
621  std::ostringstream os;
622  os << "PolynomialFunction2 [" << this->_order << "]: ";
623  os << Function2<ReturnT>::toString(prefix);
624  return os.str();
625  }
int _order
order of polynomial
Definition: Function.h:492
template<typename ReturnT>
virtual void lsst.afw.math::PolynomialFunction2< ReturnT >::write ( afw::table::io::OutputArchiveHandle handle) const
protectedvirtual

Write the object to one or more catalogs.

The handle object passed to this function provides an interface for adding new catalogs and adding nested objects to the same archive (while checking for duplicates). See OutputArchiveHandle for more information.

Reimplemented from lsst.afw.table.io::Persistable.

Friends And Related Function Documentation

template<typename ReturnT>
friend class boost::serialization::access
friend

Definition at line 644 of file FunctionLibrary.h.

Member Data Documentation

template<typename ReturnT>
double lsst.afw.math::PolynomialFunction2< ReturnT >::_oldY
mutableprivate

value of y for which _xCoeffs is valid

Definition at line 636 of file FunctionLibrary.h.

template<typename ReturnT>
std::vector<double> lsst.afw.math::PolynomialFunction2< ReturnT >::_xCoeffs
mutableprivate

working vector

Definition at line 637 of file FunctionLibrary.h.


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