30 const std::string& prefix) :
33 modelList.getWordAlphabet(),
39 Vrate_ (modelList.size())
42 size_t n = modelList.
size();
49 while (!flag && i < (n - 1))
66 for (i = 0; i < n; i++)
77 for (i = 0; i < n; i++)
87 for (i = 0; i < n; i++)
89 Vrate_[i] = 1.0 /
static_cast<double>(n);
94 std::shared_ptr<const Alphabet> alph,
95 std::shared_ptr<const StateMapInterface> stateMap,
96 const string& prefix) :
106 unique_ptr<SubstitutionModelInterface> pmodel,
108 const std::string& prefix) :
114 Vrate_ (num, 1.0 / num)
121 shared_ptr<SubstitutionModelInterface> pmodel2 = std::move(pmodel);
122 for (i = 0; i < num; i++)
137 newAlphabet_(wrsm.newAlphabet_),
139 VnestedPrefix_(wrsm.VnestedPrefix_),
148 shared_ptr<SubstitutionModelInterface> pSM =
nullptr;
150 pSM.reset(wrsm.
VSubMod_[0]->clone());
152 for (i = 0; i < num; ++i)
154 VSubMod_.push_back(pSM ? pSM : shared_ptr<SubstitutionModelInterface>(wrsm.
VSubMod_[i]->clone()));
173 shared_ptr<SubstitutionModelInterface> pSM =
nullptr;
175 pSM.reset(model.
VSubMod_[0]->clone());
177 for (i = 0; i < num; ++i)
179 VSubMod_[i] = (pSM ? pSM : shared_ptr<SubstitutionModelInterface>(model.
VSubMod_[i]->clone()));
192 for (
size_t i = 0; i <
VSubMod_.size(); i++)
200 for (
size_t i = 0; i <
VSubMod_.size(); i++)
217 for (
size_t i = 0; i <
VSubMod_.size(); i++)
227 size_t i, j, n, l, k, m;
229 vector<size_t> vsize;
231 for (k = 0; k < nbmod; k++)
264 for (
auto& fr :
freq_)
270 for (k = nbmod; k > 0; k--)
273 for (j = 0; j < vsize[k - 1]; ++j)
278 for (l = 0; l < m; ++l)
280 freq_[n + j * m + l] *= pSM->freq(j);
282 n += m * vsize[k - 1];
293 for (i = 0; i <
size_; i++)
295 for (j = 0; j <
size_; j++)
312 vector<size_t> vsize;
314 for (
size_t k = 0; k < nbmod; k++)
321 for (
size_t k = nbmod; k > 0; k--)
324 for (
size_t i = 0; i < vsize[k - 1]; i++)
326 const vector<double>& row_gi = gk.
getRow(i);
328 for (
size_t j = 0; j < vsize[k - 1]; j++)
335 for (
size_t l = 0; l < m; l++)
339 n += m * vsize[k - 1];
351 map<int, double> tmpFreq;
354 size_t i, j, s, k, d, size;
359 s =
VSubMod_[0]->getAlphabet()->getSize();
360 for (j = 0; j < s; j++)
362 tmpFreq[
static_cast<int>(j)] = 0;
365 for (i = 0; i < nbmod; i++)
368 for (k = 0; k < size; k++)
370 tmpFreq[
static_cast<int>((k / d) % s)] += freqs[
static_cast<int>(k)];
374 for (k = 0; k < s; k++)
376 tmpFreq[
static_cast<int>(k)] /=
static_cast<double>(nbmod);
383 for (i = 0; i < nbmod; i++)
386 s =
VSubMod_[i]->getAlphabet()->getSize();
388 for (j = 0; j < s; j++)
390 tmpFreq[
static_cast<int>(j)] = 0;
392 for (k = 0; k < size; k++)
394 tmpFreq[
static_cast<int>((k / d) % s)] += freqs[
static_cast<int>(k)];
void addParameters_(const ParameterList ¶meters)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
void setNamespace(const std::string &prefix)
bool matchParametersValues(const ParameterList ¶meters) override
const ParameterList & getParameters() const override
RowMatrix< double > generator_
The generator matrix of the model.
AbstractSubstitutionModel & operator=(const AbstractSubstitutionModel &model)
void normalize()
normalize the generator
void setDiagonal()
set the diagonal of the generator such that sum on each line equals 0.
bool computeFrequencies() const
RowMatrix< double > exchangeability_
The exchangeability matrix of the model, defined as . When the model is reversible,...
virtual void updateMatrices_()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
bool enableEigenDecomposition()
Tell if eigenValues and Vectors must be computed.
std::shared_ptr< const StateMapInterface > stateMap_
The map of model states with alphabet states.
std::shared_ptr< const Alphabet > getAlphabet() const override
size_t size_
The number of states.
Vdouble freq_
The vector of equilibrium frequencies.
const Alphabet & alphabet() const override
std::shared_ptr< const Alphabet > alphabet_
The alphabet relevant to this model.
size_t getNumberOfStates() const override
Get the number of states.
Abstract Basal class for words of substitution models.
virtual void completeMatrices_()=0
Called by updateMatrices to handle specific modifications for inheriting classes.
virtual void setFreq(std::map< int, double > &freqs)
Estimation of the parameters of the models so that the equilibrium frequencies match the given ones.
virtual void fillBasicGenerator_()
First fill of the generator, from the position model.
void updateMatrices_()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
std::vector< double > Vrate_
bool newAlphabet_
boolean flag to check if a specific WordAlphabet has been built
void setNamespace(const std::string &prefix)
AbstractWordSubstitutionModel(ModelList &modelList, const std::string &prefix)
Build a new AbstractWordSubstitutionModel object from a vector of pointers to SubstitutionModels.
std::vector< std::shared_ptr< SubstitutionModelInterface > > VSubMod_
std::vector< std::string > VnestedPrefix_
AbstractWordSubstitutionModel & operator=(const AbstractWordSubstitutionModel &)
This class implements a state map where all resolved states are modeled.
A list of models, for building a WordSubstitutionModel.
std::shared_ptr< SubstitutionModelInterface > getModel(size_t i)
const std::vector< double > & getRow(size_t i) const
Map the states of a given alphabet which have a model state.
std::string toString(T t)
Defines the basic types of data flow nodes.