17 std::shared_ptr<const SubstitutionModelInterface> model,
18 std::shared_ptr<const SubstitutionRegisterInterface> reg,
19 std::shared_ptr<const AlphabetIndex2> weights,
20 std::shared_ptr<const AlphabetIndex2> distances) :
25 nbStates_(model->getNumberOfStates()),
26 bMatrices_(reg->getNumberOfSubstitutionTypes()),
28 s_(reg->getNumberOfSubstitutionTypes()),
30 counts_(reg->getNumberOfSubstitutionTypes()),
34 if (model->getAlphabet()->getAlphabetType() != reg->getAlphabet()->getAlphabetType())
35 throw Exception(
"UniformizationSubstitutionCount (constructor): alphabets do not match between register and model.");
42 for (
unsigned int i = 0; i <
nbStates_; ++i)
50 throw Exception(
"UniformizationSubstitutionCount::UniformizationSubstitutionCount The maximum diagonal values of generator is above 10000. Abort, chose another mapping method");
55 std::shared_ptr<const SubstitutionRegisterInterface> reg,
56 std::shared_ptr<const AlphabetIndex2> weights,
57 std::shared_ptr<const AlphabetIndex2> distances) :
62 nbStates_(stateMap.getNumberOfModelStates()),
63 bMatrices_(reg->getNumberOfSubstitutionTypes()),
65 s_(reg->getNumberOfSubstitutionTypes()),
67 counts_(reg->getNumberOfSubstitutionTypes()),
75 size_t nbTypes =
register_->getNumberOfSubstitutionTypes();
85 for (
size_t i = 0; i <
register_->getNumberOfSubstitutionTypes(); ++i)
94 vector<int> supportedStates =
model_->getAlphabetStates();
113 vector<int> supportedStates =
model_->getAlphabetStates();
132 double lam =
miu_ * length;
142 size_t nMax =
static_cast<size_t>(ceil(4 + 6 * sqrt(lam) + lam));
147 for (
size_t i = 1; i < nMax + 1; ++i)
152 for (
size_t i = 0; i <
register_->getNumberOfSubstitutionTypes(); ++i)
154 s_[i].resize(nMax + 1);
157 for (
size_t l = 1; l < nMax + 1; ++l)
164 for (
size_t l = 0; l < nMax + 1; ++l)
175 vector<int> supportedStates =
model_->getAlphabetStates();
177 for (
size_t i = 0; i <
register_->getNumberOfSubstitutionTypes(); i++)
187 counts_[i](j, k) *=
weights_->getIndex(supportedStates[j], supportedStates[k]);
198 throw Exception(
"UniformizationSubstitutionCount::getAllNumbersOfSubstitutions: model not defined.");
201 throw Exception(
"UniformizationSubstitutionCount::getAllNumbersOfSubstitutions. Negative branch length: " +
TextTools::toString(length) +
".");
207 return make_unique<RowMatrix<double>>(
counts_[type - 1]);
215 throw Exception(
"UniformizationSubstitutionCount::storeAllNumbersOfSubstitutions: model not defined.");
218 throw Exception(
"UniformizationSubstitutionCount::storeAllNumbersOfSubstitutions. Negative branch length: " +
TextTools::toString(length) +
".");
227 const auto& ct =
counts_[type - 1];
232 mat(Eigen::Index(i), Eigen::Index(j)) = isnan(ct(i, j)) ? 0 : ct(i, j);
242 throw Exception(
"UniformizationSubstitutionCount::getNumberOfSubstitutions: model not defined.");
245 throw Exception(
"UniformizationSubstitutionCount::getNumbersOfSubstitutions. Negative branch length: " +
TextTools::toString(length) +
".");
251 return counts_[type - 1](initialState, finalState);
259 throw Exception(
"UniformizationSubstitutionCount::getNumberOfSubstitutionsPerTye: model not defined.");
262 throw Exception(
"UniformizationSubstitutionCount::getNumbersOfSubstitutions. Negative branch length: " +
TextTools::toString(length) +
".");
271 v[t] =
counts_[t](initialState, finalState);
279 std::shared_ptr<const SubstitutionModelInterface> model)
287 if (model->alphabet().getAlphabetType() !=
register_->alphabet().getAlphabetType())
288 throw Exception(
"UniformizationSubstitutionCount::setSubstitutionModel: alphabets do not match between register and model.");
290 size_t n = model->getNumberOfStates();
308 throw Exception(
"UniformizationSubstitutionCount::setSubstitutionModel(). The maximum diagonal values of generator is above 10000. Abort, chose another mapping method.");
323 if (
model_->getAlphabet()->getAlphabetType() !=
register_->getAlphabet()->getAlphabetType())
324 throw Exception(
"UniformizationSubstitutionCount::substitutionRegisterHasChanged: alphabets do not match between register and model.");
342 if (
weights_->getAlphabet()->getAlphabetType() !=
register_->getAlphabet()->getAlphabetType())
343 throw Exception(
"UniformizationSubstitutionCount::weightsHaveChanged. Incorrect alphabet type.");
355 if (
distances_->getAlphabet()->getAlphabetType() !=
register_->getAlphabet()->getAlphabetType())
356 throw Exception(
"UniformizationSubstitutionCount::distancesHaveChanged. Incorrect alphabet type.");
Partial implementation of the SubstitutionCount interface.
std::shared_ptr< const SubstitutionRegisterInterface > register_
Partial implementation of the SubstitutionDistance interface.
std::shared_ptr< const AlphabetIndex2 > distances_
Partial implementation of the WeightedSubstitutionCount interface.
std::shared_ptr< const AlphabetIndex2 > weights_
Map the states of a given alphabet which have a model state.
virtual size_t getNumberOfSubstitutionTypes() const
Short cut function, equivalent to getSubstitutionRegister().getNumberOfSubstitutionTypes().
std::string toString(T t)
bool isinf(const double &d)
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)
ExtendedFloat exp(const ExtendedFloat &ef)
ExtendedFloat abs(const ExtendedFloat &ef)