bpp-core3  3.0.0
Simplex.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_NUMERIC_PROB_SIMPLEX_H
6 #define BPP_NUMERIC_PROB_SIMPLEX_H
7 
8 
9 // From the STL:
10 #include <vector>
11 
12 #include "../AbstractParameterAliasable.h"
13 
14 namespace bpp
15 {
66 class Simplex :
68 {
69 private:
74  size_t dim_;
75 
84  unsigned short method_;
85 
86  std::vector<double> vProb_;
87 
91  std::vector<double> valpha_;
92 
93 public:
108  Simplex(size_t dim, unsigned short method = 0, bool allowNull = false, const std::string& name = "Simplex.");
109 
123  Simplex(const std::vector<double>& probas, unsigned short method = 0, bool allowNull = false, const std::string& name = "Simplex.");
124 
125  virtual ~Simplex() {}
126 
127  Simplex* clone() const { return new Simplex(*this); }
128 
129 public:
130  void fireParameterChanged(const ParameterList& parameters);
131 
132  size_t dimension() const { return dim_; }
133 
134  void setFrequencies(const std::vector<double>&);
135 
136  const std::vector<double>& getFrequencies() const { return vProb_;}
137 
138  std::vector<double>& getFrequencies() { return vProb_;}
139 
140  double prob(size_t i) const { return vProb_[i]; }
141 
142  unsigned short getMethod() const { return method_; }
143 };
144 
164  public Simplex
165 {
166 private:
167  std::vector<double> vValues_;
168 
169 public:
184  OrderedSimplex(size_t dim, unsigned short method = 0, bool allowNull = false, const std::string& name = "Simplex.") :
185  Simplex(dim, method, allowNull, name),
186  vValues_(dim)
187  {
188  const auto& probs = Simplex::getFrequencies();
189 
190  double x = 0;
191  for (auto i = dim; i > 0; i--)
192  {
193  x += probs[i - 1] / (int)i;
194  vValues_[i - 1] = x;
195  }
196  }
197 
198 
213  OrderedSimplex(const std::vector<double>& probas, unsigned short method = 0, bool allowNull = false, const std::string& name = "Simplex.");
214 
215  void fireParameterChanged(const ParameterList& parameters);
216 
217  void setFrequencies(const std::vector<double>&);
218 
219  const std::vector<double>& getFrequencies() const { return vValues_;}
220 };
221 } // end of namespace bpp.
222 
223 #endif // BPP_NUMERIC_PROB_SIMPLEX_H
std::vector< double > & getFrequencies()
Definition: Simplex.h:138
void setFrequencies(const std::vector< double > &)
Definition: Simplex.cpp:209
const std::vector< double > & getFrequencies() const
Definition: Simplex.h:136
Simplex where all values are in decreasing order.
Definition: Simplex.h:163
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
Definition: Simplex.cpp:132
unsigned short getMethod() const
Definition: Simplex.h:142
const std::vector< double > & getFrequencies() const
Definition: Simplex.h:219
std::vector< double > vProb_
Definition: Simplex.h:86
std::vector< double > vValues_
Definition: Simplex.h:167
size_t dim_
The dimension+1 of the space simplex (ie the number of probabilities).
Definition: Simplex.h:74
double prob(size_t i) const
Definition: Simplex.h:140
OrderedSimplex(size_t dim, unsigned short method=0, bool allowNull=false, const std::string &name="Simplex.")
Builds a new Simplex object from a number of probabilities. They are initialized equal.
Definition: Simplex.h:184
A Simplex object, used to define sets of probabilities that sum 1.
Definition: Simplex.h:66
The parameter list object.
Definition: ParameterList.h:27
A partial implementation of the Parametrizable interface.
std::vector< double > valpha_
just used with local ratio (method 2)
Definition: Simplex.h:91
Simplex(size_t dim, unsigned short method=0, bool allowNull=false, const std::string &name="Simplex.")
Builds a new Simplex object from a number of probabilities. They are initialized equal.
Definition: Simplex.cpp:84
virtual ~Simplex()
Definition: Simplex.h:125
unsigned short method_
the method of parametrization.
Definition: Simplex.h:84
size_t dimension() const
Definition: Simplex.h:132
Simplex * clone() const
Create a copy of this object and send a pointer to it.
Definition: Simplex.h:127