bpp-core3  3.0.0
RescaledHmmLikelihood.cpp
Go to the documentation of this file.
1 //
2 // File: RescaledHmmLikelihood.cpp
3 // Authors:
4 // Julien Dutheil
5 // Created: 2007-10-26 11:57:00
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 "../../App/ApplicationTools.h"
43 #include "RescaledHmmLikelihood.h"
44 
45 // from the STL:
46 #include <iostream>
47 #include <algorithm>
48 using namespace bpp;
49 using namespace std;
50 
52  HmmStateAlphabet* hiddenAlphabet,
53  HmmTransitionMatrix* transitionMatrix,
54  HmmEmissionProbabilities* emissionProbabilities,
55  const std::string& prefix) :
57  AbstractParametrizable(prefix),
58  hiddenAlphabet_(hiddenAlphabet),
59  transitionMatrix_(transitionMatrix),
60  emissionProbabilities_(emissionProbabilities),
61  likelihood_(),
62  dLikelihood_(),
63  d2Likelihood_(),
64  backLikelihood_(),
65  backLikelihoodUpToDate_(false),
66  scales_(),
67  dScales_(),
68  d2Scales_(),
69  logLik_(),
70  breakPoints_(),
71  nbStates_(),
72  nbSites_()
73 {
74  if (!hiddenAlphabet)
75  throw Exception("RescaledHmmLikelihood: null pointer passed for HmmStateAlphabet.");
76  if (!transitionMatrix)
77  throw Exception("RescaledHmmLikelihood: null pointer passed for HmmTransitionMatrix.");
78  if (!emissionProbabilities)
79  throw Exception("RescaledHmmLikelihood: null pointer passed for HmmEmissionProbabilities.");
80  if (!hiddenAlphabet_->worksWith(transitionMatrix->getHmmStateAlphabet()))
81  throw Exception("RescaledHmmLikelihood: HmmTransitionMatrix and HmmEmissionProbabilities should point toward the same HmmStateAlphabet object.");
82  if (!hiddenAlphabet_->worksWith(emissionProbabilities->getHmmStateAlphabet()))
83  throw Exception("RescaledHmmLikelihood: HmmTransitionMatrix and HmmEmissionProbabilities should point toward the same HmmStateAlphabet object.");
84  nbStates_ = hiddenAlphabet_->getNumberOfStates();
85  nbSites_ = emissionProbabilities_->getNumberOfPositions();
86 
87  // Manage parameters:
88  addParameters_(hiddenAlphabet_->getParameters());
89  addParameters_(transitionMatrix_->getParameters());
90  addParameters_(emissionProbabilities_->getParameters());
91 
92  // Init arrays:
93  likelihood_.resize(nbSites_ * nbStates_);
94 
95  scales_.resize(nbSites_);
96 
97  // Compute:
99 }
100 
101 void RescaledHmmLikelihood::setNamespace(const std::string& nameSpace)
102 {
104 
105  hiddenAlphabet_->setNamespace(nameSpace);
106  transitionMatrix_->setNamespace(nameSpace);
107  emissionProbabilities_->setNamespace(nameSpace);
108 }
109 
111 {
112  bool alphabetChanged = hiddenAlphabet_->matchParametersValues(pl);
113  bool transitionsChanged = transitionMatrix_->matchParametersValues(pl);
114  bool emissionChanged = emissionProbabilities_->matchParametersValues(pl);
115  // these lines are necessary because the transitions and emissions can depend on the alphabet.
116  // we could use a StateChangeEvent, but this would result in computing some calculations twice in some cases
117  // (when both the alphabet and other parameter changed).
118  if (alphabetChanged && !transitionsChanged)
119  transitionMatrix_->setParametersValues(transitionMatrix_->getParameters());
120  if (alphabetChanged && !emissionChanged)
121  emissionProbabilities_->setParametersValues(emissionProbabilities_->getParameters());
122 
123  computeForward_();
124  backLikelihoodUpToDate_ = false;
125 }
126 
127 /***************************************************************************************************************************/
128 
130 {
131  double x;
132  vector<double> tmp(nbStates_);
133  vector<double> lScales(nbSites_);
134  vector<double> trans(nbStates_ * nbStates_);
135 
136  // Transition probabilities:
137  for (size_t i = 0; i < nbStates_; i++)
138  {
139  size_t ii = i * nbStates_;
140  for (size_t j = 0; j < nbStates_; j++)
141  {
142  trans[ii + j] = transitionMatrix_->Pij(j, i);
143  if (std::isnan(trans[ii + j]))
144  throw Exception("RescaledHmmLikelihood::computeForward_. NaN transition probability");
145  if (trans[ii + j] < 0)
146  throw Exception("RescaledHmmLikelihood::computeForward_. Negative transition probability: " + TextTools::toString(trans[ii + j]));
147  }
148  }
149 
150  // Initialisation:
151  scales_[0] = 0;
152  const vector<double>* emissions = &(*emissionProbabilities_)(0);
153  for (size_t j = 0; j < nbStates_; j++)
154  {
155  size_t jj = j * nbStates_;
156  x = 0;
157  for (size_t k = 0; k < nbStates_; k++)
158  {
159  x += trans[k + jj] * transitionMatrix_->getEquilibriumFrequencies()[k];
160  // cerr << j << "\t" << k << "\t" << trans[k + jj] << "\t" << transitionMatrix_->getEquilibriumFrequencies()[k] << "\t" << trans[k + jj] * transitionMatrix_->getEquilibriumFrequencies()[k] << "\t" << x << endl;
161  }
162  tmp[j] = (*emissions)[j] * x;
163  // cerr << "e[j]=" << (*emissions)[j] << "\t" << tmp[j] << endl;
164  scales_[0] += tmp[j];
165  }
166  for (size_t j = 0; j < nbStates_; j++)
167  {
168  likelihood_[j] = tmp[j] / scales_[0];
169  }
170  lScales[0] = log(scales_[0]);
171 
172  // Recursion:
173  size_t nextBrkPt = nbSites_; // next break point
174  vector<size_t>::const_iterator bpIt = breakPoints_.begin();
175  if (bpIt != breakPoints_.end())
176  nextBrkPt = *bpIt;
177 
178  double a;
179  for (size_t i = 1; i < nbSites_; i++)
180  {
181  size_t ii = i * nbStates_;
182  size_t iip = (i - 1) * nbStates_;
183  scales_[i] = 0;
184  emissions = &(*emissionProbabilities_)(i);
185  if (i < nextBrkPt)
186  {
187  for (size_t j = 0; j < nbStates_; j++)
188  {
189  size_t jj = j * nbStates_;
190  x = 0;
191  for (size_t k = 0; k < nbStates_; k++)
192  {
193  a = trans[jj + k] * likelihood_[iip + k];
194  // if (a < 0)
195  // {
196  // (*ApplicationTools::warning << "Negative value for likelihood at " << i << ", state " << j << ": " << likelihood_[iip + k] << ", Pij = " << trans[jj + k]).endLine();
197  // a = 0;
198  // }
199  x += a;
200  }
201  tmp[j] = (*emissions)[j] * x;
202  if (tmp[j] < 0)
203  {
204  (*ApplicationTools::warning << "Negative probability at " << i << ", state " << j << ": " << (*emissions)[j] << "\t" << x).endLine();
205  tmp[j] = 0;
206  }
207  scales_[i] += tmp[j];
208  }
209  }
210  else // Reset markov chain:
211  {
212  for (size_t j = 0; j < nbStates_; j++)
213  {
214  size_t jj = j * nbStates_;
215  x = 0;
216  for (size_t k = 0; k < nbStates_; k++)
217  {
218  a = trans[jj + k] * transitionMatrix_->getEquilibriumFrequencies()[k];
219  // if (a < 0)
220  // {
221  // (*ApplicationTools::warning << "Negative value for likelihood at " << i << ", state " << j << ": ,Pij = " << trans[jj + k]).endLine();
222  // a = 0;
223  // }
224  x += a;
225  }
226  tmp[j] = (*emissions)[j] * x;
227  // if (tmp[j] < 0)
228  // {
229  // (*ApplicationTools::warning << "Negative emission probability at " << i << ", state " << j << ": " << (*emissions)[j]).endLine();
230  // tmp[j] = 0;
231  // }
232  scales_[i] += tmp[j];
233  }
234  bpIt++;
235  if (bpIt != breakPoints_.end())
236  nextBrkPt = *bpIt;
237  else
238  nextBrkPt = nbSites_;
239  }
240 
241  for (size_t j = 0; j < nbStates_; j++)
242  {
243  if (scales_[i] > 0)
244  likelihood_[ii + j] = tmp[j] / scales_[i];
245  else
246  likelihood_[ii + j] = 0;
247  }
248  lScales[i] = log(scales_[i]);
249  }
250  greater<double> cmp;
251  sort(lScales.begin(), lScales.end(), cmp);
252  logLik_ = 0;
253  for (size_t i = 0; i < nbSites_; ++i)
254  {
255  logLik_ += lScales[i];
256  }
257 }
258 
259 /***************************************************************************************************************************/
260 
262 {
263  if (backLikelihood_.size() == 0)
264  {
265  backLikelihood_.resize(nbSites_);
266  for (size_t i = 0; i < nbSites_; i++)
267  {
268  backLikelihood_[i].resize(nbStates_);
269  }
270  }
271 
272  double x;
273 
274  // Transition probabilities:
275  vector<double> trans(nbStates_ * nbStates_);
276  for (size_t i = 0; i < nbStates_; i++)
277  {
278  size_t ii = i * nbStates_;
279  for (size_t j = 0; j < nbStates_; j++)
280  {
281  trans[ii + j] = transitionMatrix_->Pij(i, j);
282  }
283  }
284 
285 
286  // Initialisation:
287  const vector<double>* emissions = 0;
288  size_t nextBrkPt = 0; // next break point
289  vector<size_t>::const_reverse_iterator bpIt = breakPoints_.rbegin();
290  if (bpIt != breakPoints_.rend())
291  nextBrkPt = *bpIt;
292 
293  for (size_t j = 0; j < nbStates_; j++)
294  {
295  x = 0;
296  backLikelihood_[nbSites_ - 1][j] = 1.;
297  }
298 
299  // Recursion:
300  for (size_t i = nbSites_ - 1; i > 0; i--)
301  {
302  emissions = &(*emissionProbabilities_)(i);
303  if (i > nextBrkPt)
304  {
305  for (size_t j = 0; j < nbStates_; j++)
306  {
307  x = 0;
308  size_t jj = j * nbStates_;
309  for (size_t k = 0; k < nbStates_; k++)
310  {
311  x += (*emissions)[k] * trans[jj + k] * backLikelihood_[i][k];
312  }
313  backLikelihood_[i - 1][j] = x / scales_[i];
314  }
315  }
316  else // Reset markov chain
317  {
318  for (size_t j = 0; j < nbStates_; j++)
319  {
320  backLikelihood_[i - 1][j] = 1.;
321  }
322  bpIt++;
323  if (bpIt != breakPoints_.rend())
324  nextBrkPt = *bpIt;
325  else
326  nextBrkPt = 0;
327  }
328  }
329 
331 }
332 
333 /***************************************************************************************************************************/
334 
336 {
338  double x = 0;
339  for (size_t i = 0; i < nbStates_; i++)
340  {
341  x += probs[i] * (*emissionProbabilities_)(site, i);
342  }
343 
344  return x;
345 }
346 
348 {
349  std::vector< std::vector<double> > vv;
351 
352  Vdouble ret(nbSites_);
353  for (size_t i = 0; i < nbSites_; i++)
354  {
355  ret[i] = 0;
356  for (size_t j = 0; j < nbStates_; j++)
357  {
358  ret[i] += vv[i][j] * (*emissionProbabilities_)(i, j);
359  }
360  }
361 
362  return ret;
363 }
364 
365 /***************************************************************************************************************************/
366 
368 {
371 
372  Vdouble probs(nbStates_);
373 
374  for (size_t j = 0; j < nbStates_; j++)
375  {
376  probs[j] = likelihood_[site * nbStates_ + j] * backLikelihood_[site][j];
377  }
378 
379  return probs;
380 }
381 
382 
383 void RescaledHmmLikelihood::getHiddenStatesPosteriorProbabilities(std::vector< std::vector<double> >& probs, bool append) const
384 {
385  size_t offset = append ? probs.size() : 0;
386  probs.resize(offset + nbSites_);
387  for (size_t i = 0; i < nbSites_; i++)
388  {
389  probs[offset + i].resize(nbStates_);
390  }
391 
394 
395  for (size_t i = 0; i < nbSites_; i++)
396  {
397  size_t ii = i * nbStates_;
398  for (size_t j = 0; j < nbStates_; j++)
399  {
400  probs[offset + i][j] = likelihood_[ii + j] * backLikelihood_[i][j];
401  }
402  }
403 }
404 
405 /***************************************************************************************************************************/
406 
408 {
409  // Init arrays:
410  if (dLikelihood_.size() == 0)
411  {
412  dLikelihood_.resize(nbSites_);
413  for (size_t i = 0; i < nbSites_; i++)
414  {
415  dLikelihood_[i].resize(nbStates_);
416  }
417  }
418  if (dScales_.size() == 0)
419  dScales_.resize(nbSites_);
420 
421  double x;
422  vector<double> tmp(nbStates_), dTmp(nbStates_);
423  vector<double> dLScales(nbSites_);
424 
425  // Transition probabilities:
426  const ColMatrix<double> trans(transitionMatrix_->getPij());
427 
428  // Initialisation:
429  dScales_[0] = 0;
430  const vector<double>* emissions = &(*emissionProbabilities_)(0);
431  const vector<double>* dEmissions = &emissionProbabilities_->getDEmissionProbabilities(0);
432 
433  for (size_t j = 0; j < nbStates_; j++)
434  {
435  dTmp[j] = (*dEmissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
436  tmp[j] = (*emissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
437 
438  dScales_[0] += dTmp[j];
439  }
440 
441  dLScales[0] = dScales_[0] / scales_[0];
442 
443 
444  for (size_t j = 0; j < nbStates_; j++)
445  {
446  dLikelihood_[0][j] = (dTmp[j] * scales_[0] - tmp[j] * dScales_[0]) / pow(scales_[0], 2);
447  }
448 
449  // Recursion:
450 
451  size_t nextBrkPt = nbSites_; // next break point
452  vector<size_t>::const_iterator bpIt = breakPoints_.begin();
453  if (bpIt != breakPoints_.end())
454  nextBrkPt = *bpIt;
455 
456  for (size_t i = 1; i < nbSites_; i++)
457  {
458  size_t iip = (i - 1) * nbStates_;
459 
460  dScales_[i] = 0;
461 
462  emissions = &(*emissionProbabilities_)(i);
463  dEmissions = &emissionProbabilities_->getDEmissionProbabilities(i);
464 
465  if (i < nextBrkPt)
466  {
467  for (size_t j = 0; j < nbStates_; j++)
468  {
469  x = 0;
470  for (size_t k = 0; k < nbStates_; k++)
471  {
472  x += trans(k, j) * likelihood_[iip + k];
473  }
474 
475  tmp[j] = (*emissions)[j] * x;
476  dTmp[j] = (*dEmissions)[j] * x + (*emissions)[j] * VectorTools::sum(trans.getCol(j) * dLikelihood_[i - 1]);
477 
478  dScales_[i] += dTmp[j];
479  }
480  }
481  else // Reset markov chain:
482  {
483  for (size_t j = 0; j < nbStates_; j++)
484  {
485  dTmp[j] = (*dEmissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
486  tmp[j] = (*emissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
487 
488  dScales_[i] += dTmp[j];
489  }
490 
491  bpIt++;
492  if (bpIt != breakPoints_.end())
493  nextBrkPt = *bpIt;
494  else
495  nextBrkPt = nbSites_;
496  }
497 
498  dLScales[i] = dScales_[i] / scales_[i];
499 
500  for (size_t j = 0; j < nbStates_; j++)
501  {
502  dLikelihood_[i][j] = (dTmp[j] * scales_[i] - tmp[j] * dScales_[i]) / pow(scales_[i], 2);
503  }
504  }
505 
506  greater<double> cmp;
507  sort(dLScales.begin(), dLScales.end(), cmp);
508  dLogLik_ = 0;
509  for (size_t i = 0; i < nbSites_; ++i)
510  {
511  dLogLik_ += dLScales[i];
512  }
513 }
514 
516 {
517  return dScales_[site] / scales_[site];
518 }
519 
520 /***************************************************************************************************************************/
521 
522 
524 {
525  // Init arrays:
526  if (d2Likelihood_.size() == 0)
527  {
528  d2Likelihood_.resize(nbSites_);
529  for (size_t i = 0; i < nbSites_; i++)
530  {
531  d2Likelihood_[i].resize(nbStates_);
532  }
533  }
534  if (d2Scales_.size() == 0)
535  d2Scales_.resize(nbSites_);
536 
537  double x;
538  vector<double> tmp(nbStates_), dTmp(nbStates_), d2Tmp(nbStates_);
539  vector<double> d2LScales(nbSites_);
540 
541  // Transition probabilities:
542  const ColMatrix<double> trans(transitionMatrix_->getPij());
543 
544  // Initialisation:
545  d2Scales_[0] = 0;
546  const vector<double>* emissions = &(*emissionProbabilities_)(0);
547  const vector<double>* dEmissions = &emissionProbabilities_->getDEmissionProbabilities(0);
548  const vector<double>* d2Emissions = &emissionProbabilities_->getD2EmissionProbabilities(0);
549 
550  for (size_t j = 0; j < nbStates_; j++)
551  {
552  tmp[j] = (*emissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
553  dTmp[j] = (*dEmissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
554  d2Tmp[j] = (*d2Emissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
555 
556  d2Scales_[0] += d2Tmp[j];
557  }
558 
559  d2LScales[0] = d2Scales_[0] / scales_[0] - pow(dScales_[0] / scales_[0], 2);
560 
561  for (size_t j = 0; j < nbStates_; j++)
562  {
563  d2Likelihood_[0][j] = d2Tmp[j] / scales_[0] - (d2Scales_[0] * tmp[j] + 2 * dScales_[0] * dTmp[j]) / pow(scales_[0], 2)
564  + 2 * pow(dScales_[0], 2) * tmp[j] / pow(scales_[0], 3);
565  }
566 
567  // Recursion:
568 
569  size_t nextBrkPt = nbSites_; // next break point
570  vector<size_t>::const_iterator bpIt = breakPoints_.begin();
571  if (bpIt != breakPoints_.end())
572  nextBrkPt = *bpIt;
573 
574  for (size_t i = 1; i < nbSites_; i++)
575  {
576  dScales_[i] = 0;
577 
578  emissions = &(*emissionProbabilities_)(i);
579  dEmissions = &emissionProbabilities_->getDEmissionProbabilities(i);
580  d2Emissions = &emissionProbabilities_->getD2EmissionProbabilities(i);
581 
582  if (i < nextBrkPt)
583  {
584  size_t iip = (i - 1) * nbStates_;
585 
586  for (size_t j = 0; j < nbStates_; j++)
587  {
588  x = 0;
589  for (size_t k = 0; k < nbStates_; k++)
590  {
591  x += trans(k, j) * likelihood_[iip + k];
592  }
593 
594  tmp[j] = (*emissions)[j] * x;
595  dTmp[j] = (*dEmissions)[j] * x + (*emissions)[j] * VectorTools::sum(trans.getCol(j) * dLikelihood_[i - 1]);
596  d2Tmp[j] = (*d2Emissions)[j] * x + 2 * (*dEmissions)[j] * VectorTools::sum(trans.getCol(j) * dLikelihood_[i - 1])
597  + (*emissions)[j] * VectorTools::sum(trans.getCol(j) * d2Likelihood_[i - 1]);
598 
599  d2Scales_[i] += d2Tmp[j];
600  }
601  }
602  else // Reset markov chain:
603  {
604  for (size_t j = 0; j < nbStates_; j++)
605  {
606  tmp[j] = (*emissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
607  dTmp[j] = (*dEmissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
608  d2Tmp[j] = (*d2Emissions)[j] * transitionMatrix_->getEquilibriumFrequencies()[j];
609 
610  d2Scales_[i] += d2Tmp[j];
611  }
612 
613  bpIt++;
614  if (bpIt != breakPoints_.end())
615  nextBrkPt = *bpIt;
616  else
617  nextBrkPt = nbSites_;
618  }
619 
620  d2LScales[i] = d2Scales_[i] / scales_[i] - pow(dScales_[i] / scales_[i], 2);
621 
622  for (size_t j = 0; j < nbStates_; j++)
623  {
624  d2Likelihood_[i][j] = d2Tmp[j] / scales_[i] - (d2Scales_[i] * tmp[j] + 2 * dScales_[i] * dTmp[j]) / pow(scales_[i], 2)
625  + 2 * pow(dScales_[i], 2) * tmp[j] / pow(scales_[i], 3);
626  }
627  }
628 
629  greater<double> cmp;
630  sort(d2LScales.begin(), d2LScales.end(), cmp);
631  dLogLik_ = 0;
632  for (size_t i = 0; i < nbSites_; ++i)
633  {
634  d2LogLik_ += d2LScales[i];
635  }
636 }
637 
638 /***************************************************************************************************************************/
639 
641 {
642  return d2Scales_[site] / scales_[site] - pow(dScales_[site] / scales_[site], 2);
643 }
A partial implementation of the Parametrizable interface.
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
virtual void addParameters_(const ParameterList &parameters)
static std::shared_ptr< OutputStream > warning
The output stream where warnings have to be displayed.
Matrix storage by column.
Definition: Matrix.h:239
const std::vector< Scalar > & getCol(size_t i) const
Definition: Matrix.h:304
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
Interface for computing emission probabilities in a Hidden Markov Model.
virtual const HmmStateAlphabet * getHmmStateAlphabet() const =0
Hidden states alphabet.
Describe the transition probabilities between hidden states of a Hidden Markov Model.
virtual const HmmStateAlphabet * getHmmStateAlphabet() const =0
The parameter list object.
Definition: ParameterList.h:65
std::vector< double > dScales_
std::vector< double > likelihood_
The likelihood arrays.
std::vector< std::vector< double > > d2Likelihood_
std::vector< size_t > breakPoints_
std::vector< double > d2Scales_
double getDLogLikelihoodForASite(size_t site) const
std::vector< std::vector< double > > dLikelihood_
derivatec of forward likelihood
Vdouble getHiddenStatesPosteriorProbabilitiesForASite(size_t site) const
RescaledHmmLikelihood(HmmStateAlphabet *hiddenAlphabet, HmmTransitionMatrix *transitionMatrix, HmmEmissionProbabilities *emissionProbabilities, const std::string &prefix)
Build a new RescaledHmmLikelihood object.
std::unique_ptr< HmmTransitionMatrix > transitionMatrix_
void getHiddenStatesPosteriorProbabilities(std::vector< std::vector< double > > &probs, bool append=false) const
std::unique_ptr< HmmEmissionProbabilities > emissionProbabilities_
double getD2LogLikelihoodForASite(size_t site) const
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site, and its derivatives.
void fireParameterChanged(const ParameterList &pl)
Notify the class when one or several parameters have changed.
std::vector< double > scales_
scales for likelihood computing
void setNamespace(const std::string &nameSpace)
Set the namespace for the parameter names.
std::vector< std::vector< double > > backLikelihood_
backward likelihood
Vdouble getLikelihoodForEachSite() const
Get the likelihood for each site.
std::unique_ptr< HmmStateAlphabet > hiddenAlphabet_
The alphabet describing the hidden states.
static T sum(const std::vector< T > &v1)
Definition: VectorTools.h:624
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:153
std::vector< double > Vdouble
Definition: VectorTools.h:70