bpp-core3  3.0.0
AutoCorrelationTransitionMatrix.cpp
Go to the documentation of this file.
1 //
2 // File: AutoCorrelationTransitionMatrix.cpp
3 // Authors:
4 // Laurent Guéguen
5 // Created: lundi 10 février 2014, à 09h 56
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++Development Team, (November 16, 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 
42 #include "../../Text/TextTools.h"
43 #include "../Matrix/MatrixTools.h"
44 #include "../VectorTools.h"
46 
47 using namespace bpp;
48 using namespace std;
49 
52  AbstractParametrizable(prefix),
53  vAutocorrel_()
54 {
55  size_t size = (size_t)getNumberOfStates();
56 
57  for (size_t i = 0; i < size; i++)
58  {
59  vAutocorrel_.push_back(1. / (double)size);
60  addParameter_(new Parameter(prefix + "lambda" + TextTools::toString(i + 1), 1. / (double)size, Parameter::PROP_CONSTRAINT_EX));
61  }
62 
63  for (size_t i = 0; i < size; i++)
64  {
65  eqFreq_[i] = 1. / (double)size;
66  }
67 }
68 
69 
73  vAutocorrel_(aptm.vAutocorrel_)
74 {}
75 
77 {
79  AbstractParametrizable::operator=(aptm);
80 
82 
83  return *this;
84 }
85 
87 {
88  if (!upToDate_)
89  {
90  for (size_t i = 0; i < vAutocorrel_.size(); ++i)
91  {
92  for (size_t j = 0; j < vAutocorrel_.size(); ++j)
93  {
94  pij_(i, j) = (i == j) ? vAutocorrel_[i] : (1 - vAutocorrel_[i]) / static_cast<double>(getNumberOfStates() - 1);
95  }
96  }
97 
98  upToDate_ = true;
99  }
100 
101  return pij_;
102 }
103 
105 {
106  return eqFreq_;
107 }
108 
110 {
111  size_t salph = getNumberOfStates();
112 
113  for (size_t i = 0; i < salph; i++)
114  {
115  vAutocorrel_[i] = getParameterValue("lambda" + TextTools::toString(i + 1));
116  }
117 
118  upToDate_ = false;
119 }
Partial implementation of HmmTransitionMatrix.
AbstractHmmTransitionMatrix & operator=(const AbstractHmmTransitionMatrix &hptm)
A partial implementation of the Parametrizable interface.
virtual void addParameter_(Parameter *parameter)
double getParameterValue(const std::string &name) const
Get the value for parameter of name 'name'.
Describe the auto-correlation probabilities inside hidden states of a Hidden Markov Model.
AutoCorrelationTransitionMatrix & operator=(const AutoCorrelationTransitionMatrix &hptm)
AutoCorrelationTransitionMatrix(const HmmStateAlphabet *alph, const std::string &prefix="")
const std::vector< double > & getEquilibriumFrequencies() const
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
const Matrix< double > & getPij() const
Get all transition probabilities as a matrix.
Hidden states alphabet.
The matrix template interface.
Definition: Matrix.h:61
The parameter list object.
Definition: ParameterList.h:65
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:135
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_EX
Definition: Parameter.h:330
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:153