25 #ifndef LSST_AFW_MATH_FUNCTION_H 26 #define LSST_AFW_MATH_FUNCTION_H 34 #include "boost/format.hpp" 35 #include "boost/serialization/nvp.hpp" 36 #include "boost/serialization/vector.hpp" 37 #include "boost/serialization/void_cast.hpp" 38 #include "boost/serialization/export.hpp" 49 using boost::serialization::make_nvp;
80 template <
typename ReturnT>
164 (boost::format(
"params has %d entries instead of %d") % params.
size() %
_params.
size())
178 os <<
"parameters: [ ";
197 friend class boost::serialization::access;
198 template <
class Archive>
199 void serialize(Archive& ar,
unsigned int const version) {
200 ar& make_nvp(
"params", _params);
211 template <
typename ReturnT>
248 virtual ReturnT operator()(
double x)
const = 0;
261 friend class boost::serialization::access;
262 template <
class Archive>
263 void serialize(Archive& ar,
unsigned const int version) {
275 template <
typename ReturnT>
314 virtual ReturnT operator()(
double x,
double y)
const = 0;
324 "getDFuncDParameters is not implemented for this class");
332 friend class boost::serialization::access;
333 template <
class Archive>
334 void serialize(Archive& ar,
unsigned const int version) {
349 template <
typename ReturnT>
397 os <<
"order=" << order <<
" invalid: must be >= 0";
400 return (order + 1) * (order + 2) / 2;
418 int order =
static_cast<int>(
419 0.5 + ((-3.0 + (
std::sqrt(1.0 + (8.0 * static_cast<double>(nParameters))))) / 2.0));
422 os <<
"nParameters=" << nParameters <<
" invalid: order is not an integer";
442 for (
unsigned int i = 0; i < numParams; ++i) {
443 dummy->setParameter(i, 0.0);
446 for (
unsigned int i = 0; i < numParams; ++i) {
447 dummy->setParameter(i, 1.0);
448 deriv[i] = (*dummy)(
x, y);
449 dummy->setParameter(i, 0.0);
462 friend class boost::serialization::access;
463 template <
class Archive>
464 void serialize(Archive& ar,
unsigned const int version) {
466 ar& make_nvp(
"order", _order);
473 template <
typename ReturnT>
482 ReturnT operator()(
double)
const {
return static_cast<ReturnT
>(0); }
485 friend class boost::serialization::access;
486 template <
class Archive>
487 void serialize(Archive& ar,
unsigned int const version) {
495 template <
typename ReturnT>
504 ReturnT operator()(
double,
double)
const {
return static_cast<ReturnT
>(0); }
507 friend class boost::serialization::access;
508 template <
class Archive>
509 void serialize(Archive& ar,
unsigned int const version) {
517 #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.