bpp-core  2.2.0
ReparametrizationFunctionWrapper.h
Go to the documentation of this file.
1 //
2 // File: ReparametrizationFunctionWrapper.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Jan 30 09:30 2009
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for numerical calculus.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _REPARAMETRIZATIONFUNCTIONWRAPPER_H_
41 #define _REPARAMETRIZATIONFUNCTIONWRAPPER_H_
42 
43 #include "Functions.h"
44 #include "../AbstractParametrizable.h"
45 #include "../TransformedParameter.h"
46 
47 namespace bpp {
48 
56  public virtual Function,
58 {
59  private:
62 
63  public:
70  ReparametrizationFunctionWrapper(Function* function, bool verbose=true) :
72  function_(function),
74  {
75  init_(verbose);
76  }
77 
87  ReparametrizationFunctionWrapper(Function* function, const ParameterList& parameters, bool verbose=true) :
89  function_(function),
90  functionParameters_(function->getParameters().getCommonParametersWith(parameters))
91  {
92  init_(verbose);
93  }
94 
97  function_(rfw.function_),
99 
101  {
102  AbstractParametrizable::operator=(rfw),
103  function_ = rfw.function_;
105  return *this;
106  }
107 
109 
110 #if defined(NO_VIRTUAL_COV)
111  Clonable* clone() const { return new ReparametrizationFunctionWrapper(*this); }
112 #else
114 #endif
115 
116  private:
117  void init_(bool verbose);
118 
119  public:
120  virtual const Function& getFunction() const { return *function_; }
121 
122  virtual Function& getFunction() { return *function_; }
123 
124  void setParameters(const ParameterList& parameters)
126  {
127 // parameters.printParameters(std::cout);
128  matchParametersValues(parameters);
129  //We only set parameters that have been changed:
130 // functionParameters_.printParameters(std::cout);
131  function_->setParameters(functionParameters_.subList(parameters.getParameterNames()));
132  }
133 
134  double getValue() const throw (Exception)
135  {
136  return function_->getValue();
137  }
138 
139  void fireParameterChanged (const ParameterList &parameters);
140 
141 };
142 
150  public virtual DerivableFirstOrder,
152 {
153 
154  public:
162  ReparametrizationFunctionWrapper(function, verbose)
163  {}
164 
174  ReparametrizationDerivableFirstOrderWrapper(DerivableFirstOrder* function, const ParameterList& parameters, bool verbose=true) :
175  ReparametrizationFunctionWrapper(function, parameters, verbose)
176  {}
177 
179 
180 #if defined(NO_VIRTUAL_COV)
181  Clonable* clone() const { return new ReparametrizationDerivableFirstOrderWrapper(*this); }
182 #else
184 #endif
185 
186  private:
187  void init_(bool verbose);
188 
189  public:
191 
193 
194  double getFirstOrderDerivative(const std::string& variable) const throw (Exception)
195  {
196  return dynamic_cast<const DerivableFirstOrder&>(getFunction()).getFirstOrderDerivative(variable)
197  * dynamic_cast<const TransformedParameter&>(getParameter(variable)).getFirstOrderDerivative();
198  }
199 
200 };
201 
202 
210  public virtual DerivableSecondOrder,
212 {
213 
214  public:
223  {}
224 
234  ReparametrizationDerivableSecondOrderWrapper(DerivableSecondOrder* function, const ParameterList& parameters, bool verbose=true) :
235  ReparametrizationDerivableFirstOrderWrapper(function, parameters, verbose)
236  {}
237 
239 
240 #if defined(NO_VIRTUAL_COV)
241  Clonable* clone() const { return new ReparametrizationDerivableSecondOrderWrapper(*this); }
242 #else
244 #endif
245 
246  private:
247  void init_(bool verbose);
248 
249  public:
251 
253 
254  double getSecondOrderDerivative(const std::string& variable) const throw (Exception)
255  {
256  return dynamic_cast<const DerivableSecondOrder&>(getFunction()).getSecondOrderDerivative(variable)
257  * pow(dynamic_cast<const TransformedParameter&>(getParameter(variable)).getFirstOrderDerivative(), 2)
258  + dynamic_cast<const DerivableSecondOrder&>(getFunction()).getFirstOrderDerivative(variable)
259  * dynamic_cast<const TransformedParameter&>(getParameter(variable)).getSecondOrderDerivative();
260  }
261 
262  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const throw (Exception)
263  {
264  return dynamic_cast<const DerivableSecondOrder&>(getFunction()).getSecondOrderDerivative(variable1, variable2)
265  * dynamic_cast<const TransformedParameter&>(getParameter(variable1)).getFirstOrderDerivative()
266  * dynamic_cast<const TransformedParameter&>(getParameter(variable2)).getFirstOrderDerivative();
267  }
268 
269 };
270 
271 } //end of namespace bpp.
272 
273 #endif //_REPARAMETRIZATIONFUNCTIONWRAPPER_H_
274 
ReparametrizationFunctionWrapper(const ReparametrizationFunctionWrapper &rfw)
Exception thrown when a parameter is not found, for instance in a ParameterList.
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 enableSecondOrderDerivatives() const
Tell if derivatives must be computed.
virtual ParameterList subList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
virtual void setParameters(const ParameterList &parameters)=0
Set the point where the function must be computed.
ReparametrizationFunctionWrapper & operator=(const ReparametrizationFunctionWrapper &rfw)
This class allows to perform a correspondence analysis.
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
A partial implementation of the Parametrizable interface.
This is the function abstract class.
Definition: Functions.h:86
double getFirstOrderDerivative(const std::string &variable) const
Get the derivative of the function at the current point.
void enableFirstOrderDerivatives(bool yn)
Tell if derivatives must be computed.
The parameter list object.
Definition: ParameterList.h:61
double getValue() const
Get the value of the function at the current point.
ReparametrizationFunctionWrapper(Function *function, const ParameterList &parameters, bool verbose=true)
Build a new reparametrization wrapper for the given function, using only the specified parameters...
ReparametrizationDerivableSecondOrderWrapper(DerivableSecondOrder *function, const ParameterList &parameters, bool verbose=true)
Build a new reparametrization wrapper for the given function, using only the specified parameters...
Function wrapper that remove simple constraints on parameters. Also transform first and second order ...
double getSecondOrderDerivative(const std::string &variable) const
Get the second order derivative of the function at the current point.
ReparametrizationDerivableFirstOrderWrapper(DerivableFirstOrder *function, const ParameterList &parameters, bool verbose=true)
Build a new reparametrization wrapper for the given function, using only the specified parameters...
bool enableFirstOrderDerivatives() const
Tell if derivatives must be computed.
bool matchParametersValues(const ParameterList &parameters)
Update the parameters from parameters.
const Parameter & getParameter(const std::string &name) const
Get the parameter with specified name.
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.
ReparametrizationFunctionWrapper(Function *function, bool verbose=true)
Build a new reparametrization wrapper for the given function, using all available parameters...
ReparametrizationDerivableFirstOrderWrapper * clone() const
Create a copy of this object and send a pointer to it.
void enableSecondOrderDerivatives(bool yn)
Tell if derivatives must be computed.
Exception base class.
Definition: Exceptions.h:57
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:99
const ParameterList & getParameters() const
Get all parameters available.
This is the abstract class for second order derivable functions.
Definition: Functions.h:189
This is the abstract class for first order derivable functions.
Definition: Functions.h:129
Function wrapper that remove simple constraints on parameters.
Exception thrown when a value do not match a given constraint.
Function wrapper that remove simple constraints on parameters. Also transform first order derivatives...
ReparametrizationFunctionWrapper * clone() const
Create a copy of this object and send a pointer to it.
void setParameters(const ParameterList &parameters)
Set the point where the function must be computed.
The TransformedParameter abstract class.
ReparametrizationDerivableFirstOrderWrapper(DerivableFirstOrder *function, bool verbose=true)
Build a new reparametrization wrapper for the given function, using all available parameters...
virtual double getValue() const =0
Get the value of the function at the current point.