14 std::shared_ptr<HmmStateAlphabet> hiddenAlphabet,
15 std::shared_ptr<HmmTransitionMatrix> transitionMatrix,
16 std::shared_ptr<HmmEmissionProbabilities> emissionProbabilities,
17 const std::string& prefix,
21 hiddenAlphabet_(hiddenAlphabet),
22 transitionMatrix_(transitionMatrix),
23 emissionProbabilities_(emissionProbabilities),
33 throw Exception(
"LowMemoryRescaledHmmLikelihood: null pointer passed for HmmStateAlphabet.");
34 if (!transitionMatrix)
35 throw Exception(
"LowMemoryRescaledHmmLikelihood: null pointer passed for HmmTransitionMatrix.");
36 if (!emissionProbabilities)
37 throw Exception(
"LowMemoryRescaledHmmLikelihood: null pointer passed for HmmEmissionProbabilities.");
39 throw Exception(
"LowMemoryRescaledHmmLikelihood: HmmTransitionMatrix and HmmEmissionProbabilities should point toward the same HmmStateAlphabet object.");
40 if (!
hiddenAlphabet_->worksWith(emissionProbabilities->hmmStateAlphabet()))
41 throw Exception(
"LowMemoryRescaledHmmLikelihood: HmmTransitionMatrix and HmmEmissionProbabilities should point toward the same HmmStateAlphabet object.");
75 if (alphabetChanged && !transitionsChanged)
77 if (alphabetChanged && !emissionChanged)
104 const vector<double>* emissions = &(*emissionProbabilities_)(0);
113 tmp[j] = (*emissions)[j] * x;
120 lScales[0] = log(scale);
126 vector<size_t>::const_iterator bpIt =
breakPoints_.begin();
134 for (
size_t i = 1; i <
nbSites_; i++)
137 tmpLikelihood = previousLikelihood;
138 previousLikelihood = currentLikelihood;
139 currentLikelihood = tmpLikelihood;
142 emissions = &(*emissionProbabilities_)(i);
151 a = trans[jj + k] * (*previousLikelihood)[k];
159 tmp[j] = (*emissions)[j] * x;
184 tmp[j] = (*emissions)[j] * x;
202 (*currentLikelihood)[j] = tmp[j] / scale;
204 (*currentLikelihood)[j] = 0;
206 lScales[i - offset] = log(scale);
211 double partialLogLik = 0;
212 sort(lScales.begin(), lScales.end(), cmp);
213 for (
size_t j = 0; j <
maxSize_; ++j)
215 partialLogLik += lScales[j];
221 sort(lScales.begin(), lScales.begin() +
static_cast<ptrdiff_t
>(nbSites_ - offset), cmp);
222 double partialLogLik = 0;
223 for (
size_t i = 0; i < nbSites_ - offset; ++i)
225 partialLogLik += lScales[i];
std::shared_ptr< HmmTransitionMatrix > transitionMatrix_
std::shared_ptr< HmmEmissionProbabilities > emissionProbabilities_
void setNamespace(const std::string &nameSpace) override
Set the namespace for the parameter names.
A partial implementation of the Parametrizable interface.
void setNamespace(const std::string &prefix) override
Set the namespace for the parameter names.
The parameter list object.
std::shared_ptr< HmmStateAlphabet > hiddenAlphabet_
The alphabet describing the hidden states.
void fireParameterChanged(const ParameterList &pl) override
Notify the class when one or several parameters have changed.
partial impmementation of Hmm Likelihoods.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
std::vector< double > likelihood2_
std::vector< double > likelihood1_
The likelihood array.
LowMemoryRescaledHmmLikelihood(std::shared_ptr< HmmStateAlphabet > hiddenAlphabet, std::shared_ptr< HmmTransitionMatrix > transitionMatrix, std::shared_ptr< HmmEmissionProbabilities > emissionProbabilities, const std::string &prefix, size_t maxSize=1000000)
Build a new LowMemoryRescaledHmmLikelihood object.
std::vector< size_t > breakPoints_
virtual void addParameters_(const ParameterList ¶meters)