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>
161 (boost::format(
"params has %d entries instead of %d") % params.
size() %
_params.
size())
175 os <<
"parameters: [ ";
194 friend class boost::serialization::access;
195 template <
class Archive>
196 void serialize(Archive& ar,
unsigned int const version) {
197 ar& make_nvp(
"params", _params);
208 template <
typename ReturnT>
245 virtual ReturnT operator()(
double x)
const = 0;
258 friend class boost::serialization::access;
259 template <
class Archive>
260 void serialize(Archive& ar,
unsigned const int version) {
272 template <
typename ReturnT>
311 virtual ReturnT operator()(
double x,
double y)
const = 0;
321 "getDFuncDParameters is not implemented for this class");
329 friend class boost::serialization::access;
330 template <
class Archive>
331 void serialize(Archive& ar,
unsigned const int version) {
346 template <
typename ReturnT>
393 os <<
"order=" << order <<
" invalid: must be >= 0";
396 return (order + 1) * (order + 2) / 2;
414 int order =
static_cast<int>(
415 0.5 + ((-3.0 + (
std::sqrt(1.0 + (8.0 * static_cast<double>(nParameters))))) / 2.0));
418 os <<
"nParameters=" << nParameters <<
" invalid: order is not an integer";
438 for (
unsigned int i = 0; i < numParams; ++i) {
439 dummy->setParameter(i, 0.0);
442 for (
unsigned int i = 0; i < numParams; ++i) {
443 dummy->setParameter(i, 1.0);
444 deriv[i] = (*dummy)(
x,
y);
445 dummy->setParameter(i, 0.0);
458 friend class boost::serialization::access;
459 template <
class Archive>
460 void serialize(Archive& ar,
unsigned const int version) {
462 ar& make_nvp(
"order", _order);
469 template <
typename ReturnT>
478 ReturnT operator()(
double)
const {
return static_cast<ReturnT
>(0); }
481 friend class boost::serialization::access;
482 template <
class Archive>
483 void serialize(Archive& ar,
unsigned int const version) {
491 template <
typename ReturnT>
500 ReturnT operator()(
double,
double)
const {
return static_cast<ReturnT
>(0); }
503 friend class boost::serialization::access;
504 template <
class Archive>
505 void serialize(Archive& ar,
unsigned int const version) {
513 #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.