bpp-core  2.2.0
HmmLikelihood.h
Go to the documentation of this file.
1 //
2 // File: HmmLikelihood.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Oct 26 11:20 2007
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _HMMLIKELIHOOD_H_
41 #define _HMMLIKELIHOOD_H_
42 
43 
44 // From NumCalc:
45 #include "../Function/Functions.h"
46 #include "../VectorTools.h"
47 
48 #include "HmmStateAlphabet.h"
49 #include "HmmTransitionMatrix.h"
51 
52 namespace bpp
53 {
54 
78  public virtual DerivableSecondOrder
79  {
80  public:
81 
82 #ifndef NO_VIRTUAL_COV
83  virtual HmmLikelihood* clone() const = 0;
84 #endif
85 
86  virtual const HmmStateAlphabet& getHmmStateAlphabet() const = 0;
88 
89  virtual const HmmTransitionMatrix& getHmmTransitionMatrix() const = 0;
91 
92  virtual const HmmEmissionProbabilities& getHmmEmissionProbabilities() const = 0;
94 
95  virtual void getHiddenStatesPosteriorProbabilities(std::vector< std::vector<double> >& probs, bool append) const throw (Exception) = 0;
96 
97  virtual Vdouble getHiddenStatesPosteriorProbabilitiesForASite(size_t site) const = 0;
98 
99  virtual double getLogLikelihood() const = 0;
100 
101  virtual double getDLogLikelihood() const = 0;
102 
103  virtual double getD2LogLikelihood() const = 0;
104 
112  virtual double getLikelihoodForASite(size_t site) const = 0;
113 
119  virtual Vdouble getLikelihoodForEachSite() const = 0;
120 
121  virtual const std::vector<size_t>& getBreakPoints() const = 0;
122 
123  virtual void setBreakPoints(const std::vector<size_t>& breakPoints) = 0;
124 
125  protected:
126 
127  virtual void computeDLikelihood_() const = 0;
128 
129  virtual void computeD2Likelihood_() const = 0;
130 
131  };
132 
133 
134  /*
135  * @brief partial impmementation of Hmm Likelihoods.
136  *
137  */
138 
140  public virtual HmmLikelihood
141  {
142  protected:
143 
144  mutable double dLogLik_;
145  mutable std::string dVariable_;
146 
147  mutable double d2LogLik_;
148  mutable std::string d2Variable_;
149 
150  public:
152 
154 
156 
157  /* @{
158  *
159  * @brief From FirstOrder:
160  *
161  */
162 
163  void enableFirstOrderDerivatives(bool yn) {};
164 
165  bool enableFirstOrderDerivatives() const { return true;}
166 
167  double getFirstOrderDerivative(const std::string& variable) const throw (Exception);
168 
169  double getDLogLikelihood() const
170  {
171  return dLogLik_;
172  }
173 
174  /*
175  * @}
176  *
177  */
178 
179  /* @{
180  *
181  * @brief From SecondOrder:
182  *
183  */
184 
186 
187  bool enableSecondOrderDerivatives() const {return true;}
188 
189  double getSecondOrderDerivative(const std::string& variable) const throw (Exception);
190 
191  double getD2LogLikelihood() const
192  {
193  return d2LogLik_;
194  }
195 
196  double getSecondOrderDerivative(const std::string& variable1, const std::string& variable2) const throw (Exception) {
197  throw (NotImplementedException("AbstractHmmLikelihood::getSecondOrderDerivative is not defined for 2 variables."));
198  }
199 
200  /*
201  * @}
202  *
203  */
204 
205 
206  };
207 
208 
209 } //end of namespace bpp.
210 
211 #endif //_HMMLIKELIHOOD_H_
212 
Hidden states alphabet.
virtual const std::vector< size_t > & getBreakPoints() const =0
virtual double getLogLikelihood() const =0
double getDLogLikelihood() const
virtual void getHiddenStatesPosteriorProbabilities(std::vector< std::vector< double > > &probs, bool append) const =0
This class allows to perform a correspondence analysis.
virtual const HmmEmissionProbabilities & getHmmEmissionProbabilities() const =0
virtual double getDLogLikelihood() const =0
Interface for computing emission probabilities in a Hidden Markov Model.
void enableSecondOrderDerivatives(bool yn)
Tell if derivatives must be computed.
void enableFirstOrderDerivatives(bool yn)
Tell if derivatives must be computed.
virtual void computeDLikelihood_() const =0
virtual void setBreakPoints(const std::vector< size_t > &breakPoints)=0
double getD2LogLikelihood() const
This expeption is sent when a given method is not implemented.
Definition: Exceptions.h:400
bool enableFirstOrderDerivatives() const
Tell if derivatives must be computed.
double getSecondOrderDerivative(const std::string &variable) const
Get the second order derivative of the function at the current point.
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:67
virtual double getLikelihoodForASite(size_t site) const =0
Get the likelihood for a site.
Exception base class.
Definition: Exceptions.h:57
double getFirstOrderDerivative(const std::string &variable) const
Get the derivative of the function at the current point.
This is the abstract class for second order derivable functions.
Definition: Functions.h:189
AbstractHmmLikelihood & operator=(const AbstractHmmLikelihood &adhlik)
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 const HmmTransitionMatrix & getHmmTransitionMatrix() const =0
virtual Vdouble getLikelihoodForEachSite() const =0
Get the likelihood for each site.
virtual const HmmStateAlphabet & getHmmStateAlphabet() 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:77