bpp-core  2.2.0
DirectionFunction.cpp
Go to the documentation of this file.
1 //
2 // File: DirectionFunction.cpp
3 // Created by: Julien Dutheil
4 // Created on: Wed Apr 11 17:28 2007
5 // From file PowellMultiDimensions.cpp
6 //
7 
8 /*
9  Copyright or © or Copr. CNRS, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for phylogenetic data analysis.
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 #include "DirectionFunction.h"
42 
43 using namespace bpp;
44 using namespace std;
45 
46 /******************************************************************************/
47 
50 {
51  params_ = params;
52  double x = params_[0].getValue();
53  for(unsigned int j = 0; j < p_.size(); j++)
54  {
55  // cout << p_[j].getValue() << " " << x << " " << xi_[j] << endl;
56  xt_[j].setValue((p_[j].getValue()) + x * xi_[j]);
57  }
58  function_->setParameters(xt_);
59 }
60 
61 /******************************************************************************/
62 
63 double DirectionFunction::getValue() const throw (Exception)
64 {
65  return function_->getValue();
66 }
67 
68 /******************************************************************************/
69 
71 {
72  return params_;
73 }
74 
75 /******************************************************************************/
76 
77 void DirectionFunction::init(const ParameterList & p, const vector<double> & xi)
78 {
79  p_ = p;
80  xi_ = xi;
81  if(constraintPolicy_ == AutoParameter::CONSTRAINTS_AUTO) autoParameter();
82  else if(constraintPolicy_ == AutoParameter::CONSTRAINTS_IGNORE) ignoreConstraints();
83  xt_ = p_;
84 }
85 
86 /******************************************************************************/
87 
89 {
90  for(unsigned int i = 0; i < p_.size(); i++)
91  {
92  AutoParameter ap(p_[i]);
93  ap.setMessageHandler(messenger_);
94  p_.setParameter(i, ap);
95  }
96 }
97 
98 /******************************************************************************/
99 
101 {
102  for(unsigned int i = 0; i < p_.size(); i++)
103  {
104  p_[i].removeConstraint();
105  }
106 }
107 
108 /******************************************************************************/
109 
Exception thrown when a parameter is not found, for instance in a ParameterList.
static std::string CONSTRAINTS_IGNORE
void init(const ParameterList &p, const std::vector< double > &xi)
This class allows to perform a correspondence analysis.
STL namespace.
The parameter list object.
Definition: ParameterList.h:61
virtual void setMessageHandler(OutputStream *mh)
Set the message handler for this AutoParameter.
double getValue() const
Get the value of the function at the current point.
The AutoParameter class.
Definition: AutoParameter.h:58
Exception base class.
Definition: Exceptions.h:57
static std::string CONSTRAINTS_AUTO
const ParameterList & getParameters() const
Get all parameters available.
Exception thrown when a value do not match a given constraint.
void setParameters(const ParameterList &parameters)
Set the point where the function must be computed.