bpp-core3  3.0.0
ReparametrizationFunctionWrapper.h
Go to the documentation of this file.
1 //
2 // File: ReparametrizationFunctionWrapper.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2009-01-30 09:30:00
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for numerical calculus.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_NUMERIC_FUNCTION_REPARAMETRIZATIONFUNCTIONWRAPPER_H
42 #define BPP_NUMERIC_FUNCTION_REPARAMETRIZATIONFUNCTIONWRAPPER_H
43 
44 
45 #include "../AbstractParametrizable.h"
46 #include "../TransformedParameter.h"
47 #include "Functions.h"
48 
49 namespace bpp
50 {
58  public virtual Function,
60 {
61 private:
64 
65 public:
72  ReparametrizationFunctionWrapper(Function* function, bool verbose = true) :
74  function_(function),
76  {
77  init_(verbose);
78  }
79 
89  ReparametrizationFunctionWrapper(Function* function, const ParameterList& parameters, bool verbose = true) :
91  function_(function),
92  functionParameters_(function->getParameters().getCommonParametersWith(parameters))
93  {
94  init_(verbose);
95  }
96 
99  function_(rfw.function_),
101 
103  {
104  AbstractParametrizable::operator=(rfw),
105  function_ = rfw.function_;
107  return *this;
108  }
109 
111 
113 
114 private:
115  void init_(bool verbose);
116 
117 public:
118  virtual const Function& getFunction() const { return *function_; }
119 
120  virtual Function& getFunction() { return *function_; }
121 
122  void setParameters(const ParameterList& parameters)
123  {
124 // parameters.printParameters(std::cout);
125  matchParametersValues(parameters);
126  // We only set parameters that have been changed:
127 // functionParameters_.printParameters(std::cout);
129  }
130 
131  double getValue() const
132  {
133  return function_->getValue();
134  }
135 
136  void fireParameterChanged (const ParameterList& parameters);
137 };
138 
146  public virtual DerivableFirstOrder,
148 {
149 public:
157  ReparametrizationFunctionWrapper(function, verbose)
158  {}
159 
169  ReparametrizationDerivableFirstOrderWrapper(DerivableFirstOrder* function, const ParameterList& parameters, bool verbose = true) :
170  ReparametrizationFunctionWrapper(function, parameters, verbose)
171  {}
172 
174 
176 
177 private:
178  void init_(bool verbose);
179 
180 public:
182 
184 
185  double getFirstOrderDerivative(const std::string& variable) const
186  {
187  return dynamic_cast<const DerivableFirstOrder&>(getFunction()).getFirstOrderDerivative(variable)
188  * dynamic_cast<const TransformedParameter&>(getParameter(variable)).getFirstOrderDerivative();
189  }
190 };
191 
192 
200  public virtual DerivableSecondOrder,
202 {
203 public:
212  {}
213 
223  ReparametrizationDerivableSecondOrderWrapper(DerivableSecondOrder* function, const ParameterList& parameters, bool verbose = true) :
224  ReparametrizationDerivableFirstOrderWrapper(function, parameters, verbose)
225  {}
226 
228 
230 
231 private:
232  void init_(bool verbose);
233 
234 public:
236 
238 
239  double getSecondOrderDerivative(const std::string& variable) const
240  {
241  return dynamic_cast<const DerivableSecondOrder&>(getFunction()).getSecondOrderDerivative(variable)
242  * std::pow(dynamic_cast<const TransformedParameter&>(getParameter(variable)).getFirstOrderDerivative(), 2)
243  + dynamic_cast<const DerivableSecondOrder&>(getFunction()).getFirstOrderDerivative(variable)
244  * dynamic_cast<const TransformedParameter&>(getParameter(variable)).getSecondOrderDerivative();
245  }
246 
247  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const
248  {
249  return dynamic_cast<const DerivableSecondOrder&>(getFunction()).getSecondOrderDerivative(variable1, variable2)
250  * dynamic_cast<const TransformedParameter&>(getParameter(variable1)).getFirstOrderDerivative()
251  * dynamic_cast<const TransformedParameter&>(getParameter(variable2)).getFirstOrderDerivative();
252  }
253 };
254 } // end of namespace bpp.
255 #endif // BPP_NUMERIC_FUNCTION_REPARAMETRIZATIONFUNCTIONWRAPPER_H
A partial implementation of the Parametrizable interface.
const ParameterList & getParameters() const
Get all parameters available.
const Parameter & getParameter(const std::string &name) const
Get the parameter with specified name.
bool matchParametersValues(const ParameterList &parameters)
Update the parameters from parameters.
This is the abstract class for first order derivable functions.
Definition: Functions.h:133
This is the abstract class for second order derivable functions.
Definition: Functions.h:188
This is the function abstract class.
Definition: Functions.h:89
virtual double getValue() const =0
Get the value of the function at the current point.
virtual void setParameters(const ParameterList &parameters)=0
Set the point where the function must be computed.
The parameter list object.
Definition: ParameterList.h:65
virtual std::vector< std::string > getParameterNames() const
Get all parameter names in the list.
virtual ParameterList createSubList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
Function wrapper that remove simple constraints on parameters. Also transform first order derivatives...
ReparametrizationDerivableFirstOrderWrapper * clone() const
Create a copy of this object and send a pointer to it.
bool enableFirstOrderDerivatives() const
Tell if derivatives must be computed.
void enableFirstOrderDerivatives(bool yn)
Tell if derivatives must be computed.
ReparametrizationDerivableFirstOrderWrapper(DerivableFirstOrder *function, const ParameterList &parameters, bool verbose=true)
Build a new reparametrization wrapper for the given function, using only the specified parameters.
ReparametrizationDerivableFirstOrderWrapper(DerivableFirstOrder *function, bool verbose=true)
Build a new reparametrization wrapper for the given function, using all available parameters.
double getFirstOrderDerivative(const std::string &variable) const
Get the derivative of the function at the current point.
Function wrapper that remove simple constraints on parameters. Also transform first and second order ...
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.
double getSecondOrderDerivative(const std::string &variable) const
Get the second order derivative of the function at the current point.
ReparametrizationDerivableSecondOrderWrapper(DerivableSecondOrder *function, bool verbose=true)
Build a new reparametrization wrapper for the given function, using all available parameters.
ReparametrizationDerivableSecondOrderWrapper * clone() const
Create a copy of this object and send a pointer to it.
void enableSecondOrderDerivatives(bool yn)
Tell if derivatives must be computed.
ReparametrizationDerivableSecondOrderWrapper(DerivableSecondOrder *function, const ParameterList &parameters, bool verbose=true)
Build a new reparametrization wrapper for the given function, using only the specified parameters.
bool enableSecondOrderDerivatives() const
Tell if derivatives must be computed.
Function wrapper that remove simple constraints on parameters.
ReparametrizationFunctionWrapper(const ReparametrizationFunctionWrapper &rfw)
ReparametrizationFunctionWrapper & operator=(const ReparametrizationFunctionWrapper &rfw)
double getValue() const
Get the value of the function at the current point.
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
ReparametrizationFunctionWrapper * clone() const
Create a copy of this object and send a pointer to it.
ReparametrizationFunctionWrapper(Function *function, const ParameterList &parameters, bool verbose=true)
Build a new reparametrization wrapper for the given function, using only the specified parameters.
ReparametrizationFunctionWrapper(Function *function, bool verbose=true)
Build a new reparametrization wrapper for the given function, using all available parameters.
void setParameters(const ParameterList &parameters)
Set the point where the function must be computed.
The TransformedParameter abstract class.