17 DecompositionMethods::DecompositionMethods(
18 std::shared_ptr<const SubstitutionModelInterface> model,
19 std::shared_ptr<const SubstitutionRegisterInterface> reg) :
21 nbStates_(model->getNumberOfStates()),
22 nbTypes_(reg->getNumberOfSubstitutionTypes()),
23 jMat_(nbStates_, nbStates_),
25 rightEigenVectors_(0, 0),
26 rightIEigenVectors_(0, 0),
27 leftEigenVectors_(0, 0),
28 leftIEigenVectors_(0, 0),
29 bMatrices_(reg->getNumberOfSubstitutionTypes()),
30 insideProducts_(reg->getNumberOfSubstitutionTypes()),
38 std::shared_ptr<const SubstitutionRegisterInterface> reg) :
40 nbStates_(reg->stateMap().getNumberOfModelStates()),
41 nbTypes_(reg->getNumberOfSubstitutionTypes()),
42 jMat_(nbStates_, nbStates_),
44 rightEigenVectors_(0, 0),
45 rightIEigenVectors_(0, 0),
46 leftEigenVectors_(0, 0),
47 leftIEigenVectors_(0, 0),
48 bMatrices_(reg->getNumberOfSubstitutionTypes()),
49 insideProducts_(reg->getNumberOfSubstitutionTypes()),
57 nbStates_(stateMap.getNumberOfModelStates()),
59 jMat_(nbStates_, nbStates_),
61 rightEigenVectors_(0, 0),
62 rightIEigenVectors_(0, 0),
63 leftEigenVectors_(0, 0),
64 leftIEigenVectors_(0, 0),
74 std::shared_ptr<const SubstitutionModelInterface> model) :
76 nbStates_(model->getNumberOfStates()),
78 jMat_(nbStates_, nbStates_),
80 rightEigenVectors_(0, 0),
81 rightIEigenVectors_(0, 0),
82 leftEigenVectors_(0, 0),
83 leftIEigenVectors_(0, 0),
94 if (
model_->isDiagonalizable())
96 for (
size_t i = 0; i <
nbTypes_; ++i)
105 for (
size_t i = 0; i <
nbTypes_; ++i)
120 for (
unsigned int i = 0; i <
nbStates_; ++i)
122 for (
unsigned int j = 0; j <
nbStates_; ++j)
124 double dd = lambda[i] - lambda[j];
126 result(i, j) = t * expLam[i];
129 result(i, j) = (expLam[i] - expLam[j]) / dd;
141 for (
unsigned int i = 0; i <
nbStates_; ++i)
143 for (
unsigned int j = 0; j <
nbStates_; ++j)
145 double dd = lambda[i] - lambda[j];
146 double idd = ilambda[i] - ilambda[j];
149 result(i, j) = t * cosLam[i];
150 iresult(i, j) = t * sinLam[i];
154 double es = sinLam[i] - sinLam[j];
155 double ec = cosLam[i] - cosLam[j];
156 double num = dd * dd + idd * idd;
158 result(i, j) = (dd * ec + idd * es) / num;
159 iresult(i, j) = (dd * es - idd * ec) / num;
169 throw Exception(
"DecompositionMethods::computeExpectations: model not defined.");
172 if (
model_->isDiagonalizable())
180 else if (
model_->isNonSingular())
192 throw Exception(
"void DecompositionMethods::computeMappings : substitution mapping is not implemented for singular generators.");
199 throw Exception(
"DecompositionMethods::computeExpectations: model not defined.");
203 if (
model_->isDiagonalizable())
207 for (
size_t i = 0; i <
nbTypes_; ++i)
214 else if (
model_->isNonSingular())
221 for (
size_t i = 0; i <
nbTypes_; ++i)
229 throw Exception(
"void DecompositionMethods::computeMappings : substitution mapping is not implemented for singular generators.");
242 std::shared_ptr<const SubstitutionModelInterface> model)
248 size_t n = model->getNumberOfStates();
257 if (!
model_->isDiagonalizable())
261 for (
size_t i = 0; i <
nbTypes_; ++i)
277 const vector<double>& vi =
model_->getIEigenValues();
311 for (
size_t i = 0; i <
nbTypes_; ++i)
std::vector< Scalar > col(size_t j) const
const std::vector< Scalar > & getCol(size_t i) const
void resize(size_t nRows, size_t nCols)
size_t getNumberOfRows() const
ColMatrix< double > rightEigenVectors_
Real and imaginary eigenvectors, for non-reversible computation.
RowMatrix< double > leftIEigenVectors_
void computeExpectations(RowMatrix< double > &mapping, double length) const
RowMatrix< double > leftEigenVectors_
std::vector< RowMatrix< double > > insideIProducts_
void jFunction_(const std::vector< double > &lambda, double t, RowMatrix< double > &result) const
Compute the integral part of the computation.
ColMatrix< double > rightIEigenVectors_
RowMatrix< double > jIMat_
RowMatrix< double > jMat_
std::vector< RowMatrix< double > > insideProducts_
DecompositionMethods(std::shared_ptr< const SubstitutionModelInterface > model, std::shared_ptr< const SubstitutionRegisterInterface > reg)
void setSubstitutionModel(std::shared_ptr< const SubstitutionModelInterface > model)
Set the substitution model.
std::shared_ptr< const SubstitutionModelInterface > model_
std::vector< RowMatrix< double > > bMatrices_
computation matrices
const std::vector< double > & getRow(size_t i) const
std::vector< double > row(size_t i) const
void resize(size_t nRows, size_t nCols)
Map the states of a given alphabet which have a model state.
Defines the basic types of data flow nodes.
ExtendedFloat abs(const ExtendedFloat &ef)