25 #ifndef LSST_AFW_MATH_FUNCTION_H 26 #define LSST_AFW_MATH_FUNCTION_H 35 #include "boost/format.hpp" 82 template <
typename ReturnT>
175 os <<
"parameters: [ ";
191 explicit Function() : _params(0), _isCacheValid(false) {}
201 template <
typename ReturnT>
223 ~
Function1() noexcept
override =
default;
238 virtual ReturnT operator()(
double x)
const = 0;
258 template <
typename ReturnT>
282 ~
Function2() noexcept
override =
default;
297 virtual ReturnT operator()(
double x,
double y)
const = 0;
307 "getDFuncDParameters is not implemented for this class");
325 template <
typename ReturnT>
372 os <<
"order=" << order <<
" invalid: must be >= 0";
375 return (order + 1) * (order + 2) / 2;
393 int order =
static_cast<int>(
394 0.5 + ((-3.0 + (
std::sqrt(1.0 + (8.0 * static_cast<double>(nParameters))))) / 2.0));
397 os <<
"nParameters=" << nParameters <<
" invalid: order is not an integer";
417 for (
unsigned int i = 0; i < numParams; ++i) {
418 dummy->setParameter(i, 0.0);
421 for (
unsigned int i = 0; i < numParams; ++i) {
422 dummy->setParameter(i, 1.0);
423 deriv[i] = (*dummy)(
x,
y);
424 dummy->setParameter(i, 0.0);
440 template <
typename ReturnT>
449 ReturnT operator()(
double)
const noexcept(IS_NOTHROW_INIT<ReturnT>)
override {
450 return static_cast<ReturnT
>(0);
457 template <
typename ReturnT>
466 ReturnT operator()(
double,
double)
const noexcept(IS_NOTHROW_INIT<ReturnT>)
override {
467 return static_cast<ReturnT
>(0);
474 #endif // #ifndef LSST_AFW_MATH_FUNCTION_H
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
unsigned int getNParameters() const noexcept
Return the number of function parameters.
std::vector< double > getDFuncDParameters(double x, double y) const override
Return the derivative of the Function with respect to its parameters.
int _order
order of polynomial
bool isLinearCombination() const noexcept override
Is the function a linear combination of its parameters?
bool constexpr IS_NOTHROW_INIT
Test that a Function's return value is nothrow-castable to T.
std::shared_ptr< Function1< ReturnT > > clone() const override
Return a pointer to a deep copy of this function.
~Function() noexcept override=default
Function2(unsigned int nParams)
Construct a Function2 given the number of function parameters.
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
Reports attempts to access elements using an invalid key.
std::vector< double > _params
std::string toString(std::string const &prefix="") const override
Return a string representation of the function.
A base class for image defects.
virtual double getParameter(unsigned int ind) const
Get one function parameter without range checking.
virtual std::vector< double > getDFuncDParameters(double, double) const
Return the derivative of the Function with respect to its parameters.
std::vector< double > const & getParameters() const noexcept
Return all function parameters.
Function(unsigned int nParams)
Construct a Function given the number of function parameters.
virtual bool isLinearCombination() const noexcept
Is the function a linear combination of its parameters?
A Function taking one argument.
Function & operator=(Function const &)=default
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
a class used in function calls to indicate that no Function1 is being provided
Function(std::vector< double > const ¶ms)
Construct a Function given the function parameters.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Function2(std::vector< double > const ¶ms)
Construct a Function2 given the function parameters.
void setParameters(std::vector< double > const ¶ms)
Set all function parameters.
void setParameter(unsigned int ind, double newValue)
Set one function parameter without range checking.
std::string toString(std::string const &prefix="") const override
Return a string representation of the function.
Reports invalid arguments.
Function1(std::vector< double > const ¶ms)
Construct a Function1 given the function parameters.
int getOrder() const noexcept
Get the polynomial order.
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.
std::shared_ptr< Function2< ReturnT > > clone() const override
Return a pointer to a deep copy of this function.
BasePolynomialFunction2()