bpp-core3  3.0.0
AutoCorrelationTransitionMatrix.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "../../Text/TextTools.h"
6 #include "../Matrix/MatrixTools.h"
7 #include "../VectorTools.h"
9 
10 using namespace bpp;
11 using namespace std;
12 
13 AutoCorrelationTransitionMatrix::AutoCorrelationTransitionMatrix(std::shared_ptr<const HmmStateAlphabet> alph, const string& prefix) :
15  AbstractParametrizable(prefix),
16  vAutocorrel_()
17 {
18  size_t size = static_cast<size_t>(getNumberOfStates());
19  double p = 1. / static_cast<double>(size);
20 
21  for (size_t i = 0; i < size; ++i)
22  {
23  vAutocorrel_.push_back(1. / static_cast<double>(size));
24  addParameter_(new Parameter(prefix + "lambda" + TextTools::toString(i + 1), p, Parameter::PROP_CONSTRAINT_EX));
25  }
26 
27  for (size_t i = 0; i < size; ++i)
28  {
29  eqFreq_[i] = p;
30  }
31 }
32 
33 
38 {}
39 
41 {
43  AbstractParametrizable::operator=(aptm);
44 
46 
47  return *this;
48 }
49 
51 {
52  if (!upToDate_)
53  {
54  for (size_t i = 0; i < vAutocorrel_.size(); ++i)
55  {
56  for (size_t j = 0; j < vAutocorrel_.size(); ++j)
57  {
58  pij_(i, j) = (i == j) ? vAutocorrel_[i] : (1 - vAutocorrel_[i]) / static_cast<double>(getNumberOfStates() - 1);
59  }
60  }
61 
62  upToDate_ = true;
63  }
64 
65  return pij_;
66 }
67 
69 {
70  return eqFreq_;
71 }
72 
74 {
75  size_t salph = getNumberOfStates();
76 
77  for (size_t i = 0; i < salph; i++)
78  {
79  vAutocorrel_[i] = getParameterValue("lambda" + TextTools::toString(i + 1));
80  }
81 
82  upToDate_ = false;
83 }
The matrix template interface.
Definition: Matrix.h:22
void fireParameterChanged(const ParameterList &parameters) override
Notify the class when one or several parameters have changed.
AutoCorrelationTransitionMatrix & operator=(const AutoCorrelationTransitionMatrix &hptm)
A partial implementation of the Parametrizable interface.
STL namespace.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:97
double getParameterValue(const std::string &name) const override
Get the value for parameter of name &#39;name&#39;.
The parameter list object.
Definition: ParameterList.h:27
Partial implementation of HmmTransitionMatrix.
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_EX
Definition: Parameter.h:312
AutoCorrelationTransitionMatrix(std::shared_ptr< const HmmStateAlphabet > alph, const std::string &prefix="")
virtual void addParameter_(Parameter *parameter)
const Matrix< double > & getPij() const override
Get all transition probabilities as a matrix.
const std::vector< double > & getEquilibriumFrequencies() const override
Describe the auto-correlation probabilities inside hidden states of a Hidden Markov Model...
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:115
AbstractHmmTransitionMatrix & operator=(const AbstractHmmTransitionMatrix &hptm)