5 #ifndef BPP_NUMERIC_FUNCTION_FUNCTIONS_H 6 #define BPP_NUMERIC_FUNCTION_FUNCTIONS_H 9 #include "../AbstractParametrizable.h" 10 #include "../ParameterExceptions.h" 11 #include "../ParameterList.h" 12 #include "../Parametrizable.h" 15 #include "../../Clonable.h" 16 #include "../../Exceptions.h" 111 virtual void enableFirstOrderDerivatives(
bool yn) = 0;
118 virtual bool enableFirstOrderDerivatives()
const = 0;
127 virtual double getFirstOrderDerivative(
const std::string& variable)
const = 0;
141 return getFirstOrderDerivative(variable);
166 virtual void enableSecondOrderDerivatives(
bool yn) = 0;
173 virtual bool enableSecondOrderDerivatives()
const = 0;
182 virtual double getSecondOrderDerivative(
const std::string& variable)
const = 0;
196 return getSecondOrderDerivative(variable);
208 virtual double getSecondOrderDerivative(
const std::string& variable1,
const std::string& variable2)
const = 0;
220 virtual double d2f(
const std::string& variable1,
const std::string& variable2,
const ParameterList& parameters)
223 return getSecondOrderDerivative(variable1, variable2);
249 return function_->hasParameter(name);
254 function_->setParameters(parameters);
259 return function_->getParameters();
264 return function_->parameter(name);
269 return function_->getValue();
274 return function_->f(parameters);
279 return function_->getParameterValue(name);
284 function_->setAllParametersValues(parameters);
289 function_->setParameterValue(name, value);
294 function_->setParametersValues(parameters);
299 return function_->matchParametersValues(parameters);
304 return function_->removeConstraint(name);
307 void setConstraint(
const std::string& name, std::shared_ptr<ConstraintInterface> constraint)
override 309 return function_->setConstraint(name, constraint);
314 return function_->getNumberOfParameters();
319 function_->setNamespace(prefix);
324 return function_->getNamespace();
329 return function_->getParameterNameWithoutNamespace(name);
335 return function_->getParameters_();
355 std::dynamic_pointer_cast<
FirstOrderDerivable>(function_)->enableFirstOrderDerivatives(yn);
360 return std::dynamic_pointer_cast<
FirstOrderDerivable>(function_)->enableFirstOrderDerivatives();
365 return std::dynamic_pointer_cast<
FirstOrderDerivable>(function_)->getFirstOrderDerivative(variable);
390 return std::dynamic_pointer_cast<
SecondOrderDerivable>(function_)->enableSecondOrderDerivatives();
395 return std::dynamic_pointer_cast<
SecondOrderDerivable>(function_)->getSecondOrderDerivative(variable);
400 return std::dynamic_pointer_cast<
SecondOrderDerivable>(function_)->getSecondOrderDerivative(variable1, variable2);
419 constraintMatch_(false) {}
429 function_->setParameters(parameters);
430 constraintMatch_ =
false;
434 constraintMatch_ =
true;
440 return constraintMatch_ ? -std::log(0.) : function_->getValue();
453 function_->setAllParametersValues(parameters);
454 constraintMatch_ =
false;
458 constraintMatch_ =
true;
466 function_->setParameterValue(name, value);
467 constraintMatch_ =
false;
471 constraintMatch_ =
true;
479 function_->setParametersValues(parameters);
480 constraintMatch_ =
false;
484 constraintMatch_ =
true;
492 bool test = function_->matchParametersValues(parameters);
493 constraintMatch_ =
false;
498 constraintMatch_ =
true;
522 return constraintMatch_ ? -std::log(0.) : (std::dynamic_pointer_cast<
FirstOrderDerivable>(function_)->getFirstOrderDerivative(variable));
528 return getFirstOrderDerivative(variable);
551 return constraintMatch_ ? -std::log(0.) : (std::dynamic_pointer_cast<
SecondOrderDerivable>(function_)->getSecondOrderDerivative(variable));
557 return getSecondOrderDerivative(variable);
562 return constraintMatch_ ? -std::log(0.) : (std::dynamic_pointer_cast<
SecondOrderDerivable>(function_)->getSecondOrderDerivative(variable1, variable2));
565 double d2f(
const std::string& variable1,
const std::string& variable2,
const ParameterList& parameters)
568 return getSecondOrderDerivative(variable1, variable2);
601 return x * x + y * y;
607 #endif // BPP_NUMERIC_FUNCTION_FUNCTIONS_H virtual bool matchParametersValues(const ParameterList ¶meters)=0
Update the parameters from parameters.
double getValue() const override
Get the value of the function at the current point.
This is the abstract class for first order derivable functions.
Wrapper class for optimization under constraints.
FirstOrderDerivableWrapper(std::shared_ptr< FirstOrderDerivable > function)
void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
void enableFirstOrderDerivatives(bool yn)
Tell if derivatives must be computed.
double d2f(const std::string &variable, const ParameterList ¶meters)
std::string getNamespace() const override
bool enableFirstOrderDerivatives() const
Tell if derivatives must be computed.
double getSecondOrderDerivative(const std::string &variable) const
Get the second order derivative of the function at the current point.
virtual double d2f(const std::string &variable1, const std::string &variable2, const ParameterList ¶meters)
Get the value of the cross derivative of the function according to a given set of parameters...
void setAllParametersValues(const ParameterList ¶meters) override
Set the parameters values to be equals to those of parameters.
A partial implementation of the Parametrizable interface.
virtual double d2f(const std::string &variable, const ParameterList ¶meters)
Get the value of the second order derivative of the function according to a given set of parameters...
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const
virtual double df(const std::string &variable, const ParameterList ¶meters)
Get the value of the first derivative of the function according to a given set of parameters...
double getFirstOrderDerivative(const std::string &variable) const
Get the derivative of the function at the current point.
bool matchParametersValues(const ParameterList ¶meters) override
Update the parameters from parameters.
std::string getParameterNameWithoutNamespace(const std::string &name) const override
Resolves a parameter name according to the current namespace.
Wrapper class for optimization under constraints.
This class is designed to facilitate the manipulation of parameters.
Clonable * clone() const
Create a copy of this object and send a pointer to it.
double getFirstOrderDerivative(const std::string &variable) const
virtual const Parameter & parameter(const std::string &name) const =0
Get the parameter with specified name.
bool enableSecondOrderDerivatives() const
Tell if derivatives must be computed.
This is the function abstract class.
virtual ~InfinityDerivableSecondOrderWrapper()
SecondOrderDerivableWrapper(std::shared_ptr< SecondOrderDerivable > function)
void setParameters(const ParameterList ¶meters) override
Set the point where the function must be computed.
void enableSecondOrderDerivatives(bool yn)
Tell if derivatives must be computed.
This is the interface for all objects that imply parameters.
void removeConstraint(const std::string &name) override
Remove the constraint associated with one parameter, if any.
The parameter list object.
void setParameterValue(const std::string &name, double value) override
Set the value of parameter with name name to be equal to value.
FunctionWrapper(const FunctionWrapper &fw)
void setConstraint(const std::string &name, std::shared_ptr< ConstraintInterface > constraint) override
Set/Change the constraint associated with one parameter.
virtual ~FunctionInterface()
void setParametersValues(const ParameterList ¶meters) override
Update the parameters from parameters.
double getValue() const override
Get the value of the function at the current point.
Wrapper class for optimization under constraints.
virtual void setParameters(const ParameterList ¶meters)=0
Set the point where the function must be computed.
void setParametersValues(const ParameterList ¶meters) override
Update the parameters from parameters.
InfinityFunctionWrapper(std::shared_ptr< FunctionInterface > function)
General class that wraps a function into another one. This class is meant to be derivated and just pr...
void setAllParametersValues(const ParameterList ¶meters) override
Set the parameters values to be equals to those of parameters.
General class that wraps a function into another one. This class is meant to be derivated and just pr...
TestFunction(double x=0, double y=0)
General class that wraps a function into another one. This class is meant to be derivated and just pr...
virtual ~InfinityFunctionWrapper()
virtual ~FirstOrderDerivable()
void setParameters(const ParameterList ¶meters) override
Set the point where the function must be computed.
bool matchParametersValues(const ParameterList ¶meters) override
Update the parameters from parameters.
FunctionWrapper(std::shared_ptr< FunctionInterface > function)
virtual Clonable * clone() const =0
Create a copy of this object and send a pointer to it.
InfinityDerivableFirstOrderWrapper(std::shared_ptr< FirstOrderDerivable > function)
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const
Get the value of the cross derivative of the function according to a given set of parameters...
bool hasParameter(const std::string &name) const override
Tell if there is a parameter with specified name.
double getParameterValue(const std::string &name) const override
Get the value for parameter of name 'name'.
InfinityDerivableSecondOrderWrapper(std::shared_ptr< FirstOrderDerivable > function)
The Clonable interface (allow an object to be cloned).
A simple function with two parameters, mostly for testing and debugging :)
void setParameterValue(const std::string &name, double value) override
Set the value of parameter with name name to be equal to value.
const Parameter & parameter(const std::string &name) const override
Get the parameter with specified name.
InfinityDerivableFirstOrderWrapper * clone() const
Create a copy of this object and send a pointer to it.
size_t getNumberOfParameters() const override
Get the number of parameters.
virtual double getValue() const
Get the value of this parameter.
InfinityDerivableSecondOrderWrapper * clone() const
Create a copy of this object and send a pointer to it.
double f(const ParameterList ¶meters) override
Get the value of the function according to a given set of parameters.
void setParameters(const ParameterList ¶meters)
Set the point where the function must be computed.
Exception thrown when a value do not match a given constraint.
double getSecondOrderDerivative(const std::string &variable) const
std::shared_ptr< FunctionInterface > function_
InfinityFunctionWrapper * clone() const override
Create a copy of this object and send a pointer to it.
ParameterList & getParameters_() override
Get all parameters available.
virtual ~InfinityDerivableFirstOrderWrapper()
double d2f(const std::string &variable1, const std::string &variable2, const ParameterList ¶meters)
void setNamespace(const std::string &prefix) override
Set the namespace for the parameter names.
FunctionWrapper & operator=(const FunctionWrapper &fw)
double getValue() const
Get the value of the function at the current point.
double df(const std::string &variable, const ParameterList ¶meters)
double f(const ParameterList ¶meters) override
Get the value of the function according to a given set of parameters.
virtual ~SecondOrderDerivable()
virtual double f(const ParameterList ¶meters)
Get the value of the function according to a given set of parameters.
This is the abstract class for second order derivable functions.
const ParameterList & getParameters() const override
Get all parameters available.
virtual double getValue() const =0
Get the value of the function at the current point.