25 #ifndef LSST_AFW_MATH_FUNCTION_H 26 #define LSST_AFW_MATH_FUNCTION_H 35 #include "boost/format.hpp" 36 #include "boost/serialization/nvp.hpp" 37 #include "boost/serialization/vector.hpp" 38 #include "boost/serialization/void_cast.hpp" 39 #include "boost/serialization/export.hpp" 50 using boost::serialization::make_nvp;
81 template <
typename ReturnT>
164 pexExcept::InvalidParameterError,
165 (boost::format(
"params has %d entries instead of %d") % params.
size() %
_params.
size())
179 os <<
"parameters: [ ";
198 friend class boost::serialization::access;
199 template <
class Archive>
200 void serialize(Archive& ar,
unsigned int const version) {
201 ar& make_nvp(
"params", _params);
212 template <
typename ReturnT>
249 virtual ReturnT operator()(
double x)
const = 0;
262 friend class boost::serialization::access;
263 template <
class Archive>
264 void serialize(Archive& ar,
unsigned const int version) {
276 template <
typename ReturnT>
315 virtual ReturnT operator()(
double x,
double y)
const = 0;
325 "getDFuncDParameters is not implemented for this class");
333 friend class boost::serialization::access;
334 template <
class Archive>
335 void serialize(Archive& ar,
unsigned const int version) {
350 template <
typename ReturnT>
398 os <<
"order=" << order <<
" invalid: must be >= 0";
401 return (order + 1) * (order + 2) / 2;
419 int order =
static_cast<int>(
420 0.5 + ((-3.0 + (
std::sqrt(1.0 + (8.0 * static_cast<double>(nParameters))))) / 2.0));
423 os <<
"nParameters=" << nParameters <<
" invalid: order is not an integer";
443 for (
unsigned int i = 0; i < numParams; ++i) {
444 dummy->setParameter(i, 0.0);
447 for (
unsigned int i = 0; i < numParams; ++i) {
448 dummy->setParameter(i, 1.0);
449 deriv[i] = (*dummy)(x, y);
450 dummy->setParameter(i, 0.0);
463 friend class boost::serialization::access;
464 template <
class Archive>
465 void serialize(Archive& ar,
unsigned const int version) {
467 ar& make_nvp(
"order", _order);
474 template <
typename ReturnT>
483 ReturnT operator()(
double)
const {
return static_cast<ReturnT
>(0); }
486 friend class boost::serialization::access;
487 template <
class Archive>
488 void serialize(Archive& ar,
unsigned int const version) {
496 template <
typename ReturnT>
505 ReturnT operator()(
double,
double)
const {
return static_cast<ReturnT
>(0); }
508 friend class boost::serialization::access;
509 template <
class Archive>
510 void serialize(Archive& ar,
unsigned int const version) {
518 #endif // #ifndef LSST_AFW_MATH_FUNCTION_H
int _order
order of polynomial
virtual bool isLinearCombination() const
Is the function a linear combination of its parameters?
virtual bool isLinearCombination() const
Is the function a linear combination of its parameters?
std::shared_ptr< Function2< ReturnT > > clone() const
Return a pointer to a deep copy of this function.
Function2(unsigned int nParams)
Construct a Function2 given the number of function parameters.
std::shared_ptr< Function1< ReturnT > > clone() const
Return a pointer to a deep copy of this function.
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.
A Function taking two arguments.
Base class for 2-dimensional polynomials of the form:
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
std::vector< double > _params
A base class for image defects.
virtual double getParameter(unsigned int ind) const
Get one function parameter without range checking.
std::vector< double > const & getParameters() const
Return all function parameters.
virtual std::vector< double > getDFuncDParameters(double, double) const
Return the derivative of the Function with respect to its parameters.
Function(unsigned int nParams)
Construct a Function given the number of function parameters.
virtual ~Function()=default
A Function taking one argument.
Function & operator=(Function const &)=default
a class used in function calls to indicate that no Function1 is being provided
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Function(std::vector< double > const ¶ms)
Construct a Function given the function parameters.
#define LSST_EXCEPT(type,...)
Function2(std::vector< double > const ¶ms)
Construct a Function2 given the function parameters.
virtual std::vector< double > getDFuncDParameters(double x, double y) const
Return the derivative of the Function with respect to its parameters.
void setParameters(std::vector< double > const ¶ms)
Set all function parameters.
Citizen(const std::type_info &)
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the function.
int getOrder() const
Get the polynomial order.
void setParameter(unsigned int ind, double newValue)
Set one function parameter without range checking.
Function1(std::vector< double > const ¶ms)
Construct a Function1 given the function parameters.
virtual void computeCache(int const n)
virtual std::string toString(std::string const &) const
Return a string representation of the function.
A CRTP facade class for subclasses of Persistable.
static int orderFromNParameters(int nParameters)
Compute polynomial order from the number of parameters.
unsigned int getNParameters() const
Return the number of function parameters.
BasePolynomialFunction2()
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the function.