bpp-core3  3.0.0
HmmLikelihood.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_HMM_HMMLIKELIHOOD_H
6 #define BPP_NUMERIC_HMM_HMMLIKELIHOOD_H
7 
8 
9 // From NumCalc:
10 #include "../Function/Functions.h"
11 #include "../VectorTools.h"
12 
13 #include "HmmStateAlphabet.h"
14 #include "HmmTransitionMatrix.h"
16 
17 namespace bpp
18 {
42  public virtual SecondOrderDerivable
43 {
44 public:
45  virtual HmmLikelihood* clone() const = 0;
46 
47  virtual const HmmStateAlphabet& hmmStateAlphabet() const = 0;
48  virtual HmmStateAlphabet& hmmStateAlphabet() = 0;
49 
50  virtual std::shared_ptr<const HmmStateAlphabet> getHmmStateAlphabet() const = 0;
51  virtual std::shared_ptr<HmmStateAlphabet> getHmmStateAlphabet() = 0;
52 
53  virtual const HmmTransitionMatrix& hmmTransitionMatrix() const = 0;
55 
56  virtual std::shared_ptr<const HmmTransitionMatrix> getHmmTransitionMatrix() const = 0;
57  virtual std::shared_ptr<HmmTransitionMatrix> getHmmTransitionMatrix() = 0;
58 
59  virtual const HmmEmissionProbabilities& hmmEmissionProbabilities() const = 0;
61 
62  virtual std::shared_ptr<const HmmEmissionProbabilities> getHmmEmissionProbabilities() const = 0;
63  virtual std::shared_ptr<HmmEmissionProbabilities> getHmmEmissionProbabilities() = 0;
64 
65  virtual void getHiddenStatesPosteriorProbabilities(std::vector< std::vector<double>>& probs, bool append) const = 0;
66 
67  virtual Vdouble getHiddenStatesPosteriorProbabilitiesForASite(size_t site) const = 0;
68 
69  virtual double getLogLikelihood() const = 0;
70 
71  virtual double getDLogLikelihood() const = 0;
72 
73  virtual double getD2LogLikelihood() const = 0;
74 
81  virtual double getLikelihoodForASite(size_t site) const = 0;
82 
83  virtual double getDLogLikelihoodForASite(size_t site) const = 0;
84 
85  virtual double getD2LogLikelihoodForASite(size_t site) const = 0;
86 
92  virtual Vdouble getLikelihoodForEachSite() const = 0;
93 
94  virtual const std::vector<size_t>& getBreakPoints() const = 0;
95 
96  virtual void setBreakPoints(const std::vector<size_t>& breakPoints) = 0;
97 
98 protected:
99  virtual void computeDLikelihood_() const = 0;
100 
101  virtual void computeD2Likelihood_() const = 0;
102 };
103 
104 
110  public virtual HmmLikelihood
111 {
112 protected:
113  mutable double dLogLik_;
114  mutable std::string dVariable_;
115 
116  mutable double d2LogLik_;
117  mutable std::string d2Variable_;
118 
119 public:
121 
123 
124  AbstractHmmLikelihood& operator=(const AbstractHmmLikelihood& adhlik);
125 
133 
134  bool enableFirstOrderDerivatives() const { return true;}
135 
136  double getFirstOrderDerivative(const std::string& variable) const;
137 
138  double getDLogLikelihood() const
139  {
140  return dLogLik_;
141  }
142 
153 
154  bool enableSecondOrderDerivatives() const {return true;}
155 
156  double getSecondOrderDerivative(const std::string& variable) const;
157 
158  double getD2LogLikelihood() const
159  {
160  return d2LogLik_;
161  }
162 
163  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const
164  {
165  throw (NotImplementedException("AbstractHmmLikelihood::getSecondOrderDerivative is not defined for 2 variables."));
166  }
167 
171 };
172 } // end of namespace bpp.
173 #endif // BPP_NUMERIC_HMM_HMMLIKELIHOOD_H
virtual double getD2LogLikelihoodForASite(size_t site) const =0
Hidden states alphabet.
virtual const std::vector< size_t > & getBreakPoints() const =0
virtual double getLogLikelihood() const =0
double getDLogLikelihood() const
virtual const HmmStateAlphabet & hmmStateAlphabet() const =0
virtual double getDLogLikelihoodForASite(size_t site) const =0
virtual double getDLogLikelihood() const =0
Interface for computing emission probabilities in a Hidden Markov Model.
virtual const HmmTransitionMatrix & hmmTransitionMatrix() const =0
void enableSecondOrderDerivatives(bool yn)
From SecondOrder:
void enableFirstOrderDerivatives(bool yn)
From FirstOrder:
virtual std::shared_ptr< const HmmTransitionMatrix > getHmmTransitionMatrix() const =0
virtual void computeDLikelihood_() const =0
virtual void setBreakPoints(const std::vector< size_t > &breakPoints)=0
virtual double getFirstOrderDerivative(const std::string &variable) const =0
Get the derivative of the function at the current point.
double getD2LogLikelihood() const
This exception is sent when a given method is not implemented.
Definition: Exceptions.h:191
virtual double getSecondOrderDerivative(const std::string &variable) const =0
Get the second order derivative of the function at the current point.
bool enableFirstOrderDerivatives() const
Tell if derivatives must be computed.
virtual std::shared_ptr< const HmmStateAlphabet > getHmmStateAlphabet() const =0
virtual HmmLikelihood * clone() const =0
Create a copy of this object and send a pointer to it.
virtual double getD2LogLikelihood() const =0
std::vector< double > Vdouble
Definition: VectorTools.h:34
virtual double getLikelihoodForASite(size_t site) const =0
Get the likelihood for a site, and its derivatives.
virtual std::shared_ptr< const HmmEmissionProbabilities > getHmmEmissionProbabilities() const =0
partial impmementation of Hmm Likelihoods.
double getSecondOrderDerivative(const std::string &variable1, const std::string &variable2) const
Get the value of the cross derivative of the function according to a given set of parameters...
virtual Vdouble getLikelihoodForEachSite() const =0
Get the likelihood for each site.
virtual void getHiddenStatesPosteriorProbabilities(std::vector< std::vector< double >> &probs, bool append) const =0
virtual Vdouble getHiddenStatesPosteriorProbabilitiesForASite(size_t site) const =0
virtual void computeD2Likelihood_() const =0
bool enableSecondOrderDerivatives() const
Tell if derivatives must be computed.
Describe the transition probabilities between hidden states of a Hidden Markov Model.
Basal interface for Hidden Markov Models likelihood computation.
Definition: HmmLikelihood.h:41
This is the abstract class for second order derivable functions.
Definition: Functions.h:151
virtual const HmmEmissionProbabilities & hmmEmissionProbabilities() const =0