25 #ifndef LSST_AFW_MATH_FUNCTION_H
26 #define LSST_AFW_MATH_FUNCTION_H
40 #include "boost/format.hpp"
41 #include "boost/serialization/nvp.hpp"
42 #include "boost/serialization/vector.hpp"
43 #include "boost/serialization/void_cast.hpp"
44 #include "boost/serialization/export.hpp"
56 using boost::serialization::make_nvp;
88 template<
typename ReturnT>
100 unsigned int nParams)
102 lsst::daf::base::
Citizen(typeid(this)),
111 std::vector<double>
const ¶ms)
113 lsst::daf::base::
Citizen(typeid(this)),
176 std::vector<double>
const ¶ms)
178 if (
_params.size() != params.size()) {
179 throw LSST_EXCEPT(pexExcept::InvalidParameterError,
181 params.size() %
_params.size()).str());
192 virtual std::string
toString(std::string
const&)
const {
193 std::stringstream os;
194 os <<
"parameters: [ ";
195 for (std::vector<double>::const_iterator i =
_params.begin(); i !=
_params.end(); ++i) {
196 if (i !=
_params.begin()) os <<
", ";
213 friend class boost::serialization::access;
214 template <
class Archive>
215 void serialize(Archive& ar,
unsigned int const version) {
216 ar & make_nvp(
"params",
_params);
228 template<
typename ReturnT>
233 typedef std::shared_ptr<Function1<ReturnT> >
Ptr;
241 unsigned int nParams)
250 std::vector<double>
const ¶ms)
272 virtual std::string
toString(std::string
const& prefix=
"")
const {
283 friend class boost::serialization::access;
284 #ifndef SWIG // SWIG doesn't like base_object
285 template <
class Archive>
286 void serialize(Archive& ar,
unsigned const int version) {
287 ar & make_nvp(
"fn", boost::serialization::base_object<
Function<ReturnT> >(*
this));
299 template<
typename ReturnT>
304 typedef std::shared_ptr<Function2<ReturnT> >
Ptr;
312 unsigned int nParams)
323 std::vector<double>
const ¶ms)
343 virtual ReturnT
operator() (
double x,
double y)
const = 0;
345 virtual std::string
toString(std::string
const& prefix=
"")
const {
352 throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError,
353 "getDFuncDParameters is not implemented for this class");
362 #ifndef SWIG // SWIG doesn't like base_object
363 template <
class Archive>
364 void serialize(Archive& ar,
unsigned const int version) {
365 ar & make_nvp(
"fn", boost::serialization::base_object<
Function<ReturnT> >(*
this));
383 template<
typename ReturnT>
411 std::vector<double> params)
433 std::ostringstream os;
434 os <<
"order=" << order <<
" invalid: must be >= 0";
435 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
437 return (order + 1) * (order + 2) / 2;
455 int order =
static_cast<int>(
456 0.5 + ((-3.0 + (std::sqrt(1.0 + (8.0 * static_cast<double>(nParameters))))) / 2.0));
458 std::ostringstream os;
459 os <<
"nParameters=" << nParameters <<
" invalid: order is not an integer";
460 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
475 std::vector<double> deriv(numParams);
478 for (
unsigned int i = 0; i < numParams; ++i) {
479 dummy->setParameter(i, 0.0);
482 for (
unsigned int i = 0; i < numParams; ++i) {
483 dummy->setParameter(i, 1.0);
484 deriv[i] = (*dummy)(
x,
y);
485 dummy->setParameter(i, 0.0);
499 #ifndef SWIG // SWIG doesn't like base_object
500 template <
class Archive>
501 void serialize(Archive& ar,
unsigned const int version) {
503 ar & make_nvp(
"order",
_order);
512 template<
typename ReturnT>
520 ReturnT
operator() (
double)
const {
return static_cast<ReturnT
>(0); }
524 #ifndef SWIG // SWIG doesn't like base_object
525 template <
class Archive>
526 void serialize(Archive& ar,
unsigned int const version) {
535 template<
typename ReturnT>
543 ReturnT
operator() (
double,
double)
const {
return static_cast<ReturnT
>(0); }
547 #ifndef SWIG // SWIG doesn't like base_object
548 template <
class Archive>
549 void serialize(Archive& ar,
unsigned int const version) {
558 #endif // #ifndef LSST_AFW_MATH_FUNCTION_H
friend class boost::serialization::access
friend class boost::serialization::access
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
int _order
order of polynomial
void serialize(Archive &ar, unsigned int const version)
virtual ReturnT operator()(double x, double y) const =0
Citizen(const std::type_info &)
virtual std::vector< double > getDFuncDParameters(double, double) const
Return the derivative of the Function with respect to its parameters.
Function2< ReturnT >::Ptr Function2Ptr
Function2< ReturnT >::Ptr clone() const
Return a pointer to a deep copy of this function.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the function.
Include files required for standard LSST Exception handling.
void serialize(Archive &ar, unsigned int const version)
Function2(unsigned int nParams)
Construct a Function2 given the number of function parameters.
std::vector< double > const & getParameters() const
Return all function parameters.
friend class boost::serialization::access
ReturnT operator()(double) const
BasePolynomialFunction2(std::vector< double > params)
Construct a polynomial function with specified parameters.
Function1(unsigned int nParams)
Construct a Function1 given the number of function parameters.
virtual ReturnT operator()(double x) const =0
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the function.
A Function taking two arguments.
Base class for 2-dimensional polynomials of the form:
ReturnT operator()(double, double) const
A base class for objects that can be persisted via afw::table::io Archive classes.
BasePolynomialFunction2(unsigned int order)
Construct a polynomial function of specified order.
static int nParametersFromOrder(int order)
Compute number of parameters from polynomial order.
a class used in function calls to indicate that no Function2 is being provided
metadata import lsst afw display as afwDisplay n
virtual bool isLinearCombination() const
Is the function a linear combination of its parameters?
std::vector< double > _params
virtual std::string toString(std::string const &) const
Return a string representation of the function.
Function(unsigned int nParams)
Construct a Function given the number of function parameters.
A Function taking one argument.
int getOrder() const
Get the polynomial order.
virtual std::vector< double > getDFuncDParameters(double x, double y) const
Return the derivative of the Function with respect to its parameters.
std::shared_ptr< Function2< ReturnT > > Ptr
void serialize(Archive &ar, unsigned const int version)
a class used in function calls to indicate that no Function1 is being provided
virtual Ptr clone() const =0
Return a pointer to a deep copy of this function.
void serialize(Archive &ar, unsigned const int version)
std::shared_ptr< Function1< ReturnT > > Ptr
Function(std::vector< double > const ¶ms)
Construct a Function given the function parameters.
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
unsigned int getNParameters() const
Return the number of function parameters.
Function2(std::vector< double > const ¶ms)
Construct a Function2 given the function parameters.
virtual Ptr clone() const =0
Return a pointer to a deep copy of this function.
virtual ~BasePolynomialFunction2()
void setParameters(std::vector< double > const ¶ms)
Set all function parameters.
void serialize(Archive &ar, unsigned int const version)
virtual double getParameter(unsigned int ind) const
Get one function parameter without range checking.
void setParameter(unsigned int ind, double newValue)
Set one function parameter without range checking.
void serialize(Archive &ar, unsigned const int version)
Function1(std::vector< double > const ¶ms)
Construct a Function1 given the function parameters.
virtual bool isLinearCombination() const
Is the function a linear combination of its parameters?
virtual void computeCache(int const n)
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
friend class boost::serialization::access
A CRTP facade class for subclasses of Persistable.
static int orderFromNParameters(int nParameters)
Compute polynomial order from the number of parameters.
BasePolynomialFunction2()
Function1< ReturnT >::Ptr clone() const
Return a pointer to a deep copy of this function.