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 boost::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 boost::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");
361 friend class boost::serialization::access;
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
virtual Ptr clone() const =0
Return a pointer to a deep copy of this function.
friend class boost::serialization::access
int _order
order of polynomial
Function(unsigned int nParams)
Construct a Function given the number of function parameters.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the function.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
void serialize(Archive &ar, unsigned int const version)
virtual std::vector< double > getDFuncDParameters(double, double) const
std::vector< double > const & getParameters() const
Return 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.
int getOrder() const
Get the polynomial order.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the function.
void setParameter(unsigned int ind, double newValue)
Set one function parameter without range checking.
friend class boost::serialization::access
virtual bool isLinearCombination() const
Is the function a linear combination of its parameters?
Function2< ReturnT >::Ptr Function2Ptr
A Function taking two arguments.
Base class for 2-dimensional polynomials of the form:
unsigned int getNParameters() const
Return the number of function parameters.
A base class for objects that can be persisted via afw::table::io Archive classes.
Function1(std::vector< double > const ¶ms)
Construct a Function1 given the function parameters.
static int nParametersFromOrder(int order)
Compute number of parameters from polynomial order.
virtual std::vector< double > getDFuncDParameters(double x, double y) const
Function(std::vector< double > const ¶ms)
Construct a Function given the function parameters.
a class used in function calls to indicate that no Function2 is being provided
Function2< ReturnT >::Ptr clone() const
Return a pointer to a deep copy of this function.
static int orderFromNParameters(int nParameters)
Compute polynomial order from the number of parameters.
virtual std::string toString(std::string const &) const
Return a string representation of the function.
virtual void computeCache(int const n)
virtual ~BasePolynomialFunction2()
ReturnT operator()(double, double) const
void serialize(Archive &ar, unsigned const int version)
BasePolynomialFunction2(std::vector< double > params)
Construct a polynomial function with specified parameters.
A Function taking one argument.
Function2(unsigned int nParams)
Construct a Function2 given the number of function parameters.
Function1< ReturnT >::Ptr clone() const
Return a pointer to a deep copy of this function.
a class used in function calls to indicate that no Function1 is being provided
Function2(std::vector< double > const ¶ms)
Construct a Function2 given the function parameters.
ReturnT operator()(double) const
virtual ReturnT operator()(double x) const =0
#define LSST_EXCEPT(type,...)
Function1(unsigned int nParams)
Construct a Function1 given the number of function parameters.
std::vector< double > _params
Citizen(const std::type_info &)
void serialize(Archive &ar, unsigned const int version)
virtual ReturnT operator()(double x, double y) const =0
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
void serialize(Archive &ar, unsigned const int version)
boost::shared_ptr< Function2< ReturnT > > Ptr
virtual bool isLinearCombination() const
Is the function a linear combination of its parameters?
friend class boost::serialization::access
void serialize(Archive &ar, unsigned int const version)
BasePolynomialFunction2(unsigned int order)
Construct a polynomial function of specified order.
A CRTP facade class for subclasses of Persistable.
BasePolynomialFunction2()
boost::shared_ptr< Function1< ReturnT > > Ptr
void setParameters(std::vector< double > const ¶ms)
Set all function parameters.
virtual Ptr clone() const =0
Return a pointer to a deep copy of this function.
Include files required for standard LSST Exception handling.