bpp-phyl3  3.0.0
bpp::DecompositionSubstitutionCount Class Reference

Analytical substitution count using the eigen decomposition method. More...

#include <Bpp/Phyl/Mapping/DecompositionSubstitutionCount.h>

+ Inheritance diagram for bpp::DecompositionSubstitutionCount:
+ Collaboration diagram for bpp::DecompositionSubstitutionCount:

Public Member Functions

 DecompositionSubstitutionCount (std::shared_ptr< const SubstitutionModelInterface > model, std::shared_ptr< const SubstitutionRegisterInterface > reg, std::shared_ptr< const AlphabetIndex2 > weights=nullptr, std::shared_ptr< const AlphabetIndex2 > distances=nullptr)
 
 DecompositionSubstitutionCount (std::shared_ptr< const SubstitutionRegisterInterface > reg, std::shared_ptr< const AlphabetIndex2 > weights=nullptr, std::shared_ptr< const AlphabetIndex2 > distances=nullptr)
 
 DecompositionSubstitutionCount (const DecompositionSubstitutionCount &dsc)
 
DecompositionSubstitutionCountoperator= (const DecompositionSubstitutionCount &dsc)
 
virtual ~DecompositionSubstitutionCount ()
 
DecompositionSubstitutionCountclone () const override
 
double getNumberOfSubstitutions (size_t initialState, size_t finalState, double length, size_t type=1) const override
 Get the number of susbstitutions on a branch, given the initial and final states, and the branch length. More...
 
std::unique_ptr< Matrix< double > > getAllNumbersOfSubstitutions (double length, size_t type=1) const override
 Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branch length. More...
 
void storeAllNumbersOfSubstitutions (double length, size_t type, Eigen::MatrixXd &mat) const override
 Stores the numbers of susbstitutions on a branch, for each initial and final states, and given the branch length. More...
 
std::vector< double > getNumberOfSubstitutionsPerType (size_t initialState, size_t finalState, double length) const override
 Get the numbers of susbstitutions on a branch for all types, for an initial and final states, given the branch length. More...
 
void setSubstitutionModel (std::shared_ptr< const SubstitutionModelInterface > model) override
 Set the substitution model. More...
 
bool hasSubstitutionRegister () const
 
void setSubstitutionRegister (std::shared_ptr< const SubstitutionRegisterInterface > reg)
 attribution of a SubstitutionRegister More...
 
std::shared_ptr< const SubstitutionRegisterInterfacegetSubstitutionRegister () const
 
virtual size_t getNumberOfSubstitutionTypes () const
 Short cut function, equivalent to getSubstitutionRegister().getNumberOfSubstitutionTypes(). More...
 
virtual std::shared_ptr< const AlphabetgetAlphabet () const
 Short cut function, equivalent to getSubstitutionRegister()->getAlphabet(). More...
 
virtual size_t getNumberOfStates () const
 Short cut function, equivalent to getSubstitutionRegister()->getAlphabet()->getSize(). More...
 
void setWeights (std::shared_ptr< const AlphabetIndex2 > weights)
 
bool hasWeights () const
 
std::shared_ptr< const AlphabetIndex2getWeights () const
 
void setDistances (std::shared_ptr< const AlphabetIndex2 > distances)
 
bool hasDistances () const
 
std::shared_ptr< const AlphabetIndex2getDistances () const
 

Protected Member Functions

void initCounts_ ()
 
void computeCounts_ (double length) const
 
void substitutionRegisterHasChanged () override
 
void weightsHaveChanged () override
 
void distancesHaveChanged () override
 
void initStates_ ()
 
void initBMatrices_ ()
 
void computeProducts_ ()
 
void computeExpectations (RowMatrix< double > &mapping, double length) const
 
void computeExpectations (std::vector< RowMatrix< double >> &mappings, double length) const
 
void jFunction_ (const std::vector< double > &lambda, double t, RowMatrix< double > &result) const
 Compute the integral part of the computation. More...
 
void jFunction_ (const std::vector< double > &lambda, const std::vector< double > &ilambda, double t, RowMatrix< double > &result, RowMatrix< double > &iresult) const
 Compute the integral part of the computation, in complex numbers. More...
 

Protected Attributes

std::shared_ptr< const SubstitutionRegisterInterfaceregister_
 
std::shared_ptr< const AlphabetIndex2weights_
 
std::shared_ptr< const AlphabetIndex2distances_
 
std::shared_ptr< const SubstitutionModelInterfacemodel_
 
size_t nbStates_
 
size_t nbTypes_
 
RowMatrix< double > jMat_
 
RowMatrix< double > jIMat_
 
ColMatrix< double > rightEigenVectors_
 Real and imaginary eigenvectors, for non-reversible computation. More...
 
ColMatrix< double > rightIEigenVectors_
 
RowMatrix< double > leftEigenVectors_
 
RowMatrix< double > leftIEigenVectors_
 
std::vector< RowMatrix< double > > bMatrices_
 computation matrices More...
 
std::vector< RowMatrix< double > > insideProducts_
 
std::vector< RowMatrix< double > > insideIProducts_
 

Private Member Functions

void fillBMatrices_ ()
 
void setDistanceBMatrices_ ()
 

Private Attributes

std::vector< RowMatrix< double > > counts_
 
double currentLength_
 

Detailed Description

Analytical substitution count using the eigen decomposition method.

The codes is adapted from the original R code by Paula Tataru and Asger Hobolth.

Author
Julien Dutheil

Definition at line 24 of file DecompositionSubstitutionCount.h.

Constructor & Destructor Documentation

◆ DecompositionSubstitutionCount() [1/3]

DecompositionSubstitutionCount::DecompositionSubstitutionCount ( std::shared_ptr< const SubstitutionModelInterface model,
std::shared_ptr< const SubstitutionRegisterInterface reg,
std::shared_ptr< const AlphabetIndex2 weights = nullptr,
std::shared_ptr< const AlphabetIndex2 distances = nullptr 
)

◆ DecompositionSubstitutionCount() [2/3]

DecompositionSubstitutionCount::DecompositionSubstitutionCount ( std::shared_ptr< const SubstitutionRegisterInterface reg,
std::shared_ptr< const AlphabetIndex2 weights = nullptr,
std::shared_ptr< const AlphabetIndex2 distances = nullptr 
)

Definition at line 39 of file DecompositionSubstitutionCount.cpp.

References initCounts_().

◆ DecompositionSubstitutionCount() [3/3]

bpp::DecompositionSubstitutionCount::DecompositionSubstitutionCount ( const DecompositionSubstitutionCount dsc)
inline

Definition at line 46 of file DecompositionSubstitutionCount.h.

◆ ~DecompositionSubstitutionCount()

virtual bpp::DecompositionSubstitutionCount::~DecompositionSubstitutionCount ( )
inlinevirtual

Definition at line 66 of file DecompositionSubstitutionCount.h.

Member Function Documentation

◆ clone()

DecompositionSubstitutionCount* bpp::DecompositionSubstitutionCount::clone ( ) const
inlineoverridevirtual

◆ computeCounts_()

◆ computeExpectations() [1/2]

◆ computeExpectations() [2/2]

◆ computeProducts_()

◆ distancesHaveChanged()

◆ fillBMatrices_()

◆ getAllNumbersOfSubstitutions()

unique_ptr< Matrix< double > > DecompositionSubstitutionCount::getAllNumbersOfSubstitutions ( double  length,
size_t  type = 1 
) const
overridevirtual

Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branch length.

Parameters
lengthThe length of the branch.
typeThe type of susbstitution to count.
Returns
A matrix with all numbers of substitutions for each initial and final states.

Implements bpp::SubstitutionCountInterface.

Definition at line 134 of file DecompositionSubstitutionCount.cpp.

References computeCounts_(), counts_, currentLength_, bpp::DecompositionMethods::model_, and bpp::TextTools::toString().

◆ getAlphabet()

virtual std::shared_ptr<const Alphabet> bpp::SubstitutionCountInterface::getAlphabet ( ) const
inlinevirtualinherited

Short cut function, equivalent to getSubstitutionRegister()->getAlphabet().

Returns
The alphabet associated to this substitution count.

Definition at line 78 of file SubstitutionCount.h.

References bpp::SubstitutionCountInterface::getSubstitutionRegister().

◆ getDistances()

std::shared_ptr<const AlphabetIndex2> bpp::AbstractSubstitutionDistance::getDistances ( ) const
inlinevirtualinherited

◆ getNumberOfStates()

virtual size_t bpp::SubstitutionCountInterface::getNumberOfStates ( ) const
inlinevirtualinherited

Short cut function, equivalent to getSubstitutionRegister()->getAlphabet()->getSize().

Returns
The number of states in the model/alphabet.

Definition at line 85 of file SubstitutionCount.h.

References bpp::SubstitutionCountInterface::getSubstitutionRegister().

◆ getNumberOfSubstitutions()

double DecompositionSubstitutionCount::getNumberOfSubstitutions ( size_t  initialState,
size_t  finalState,
double  length,
size_t  type = 1 
) const
overridevirtual

Get the number of susbstitutions on a branch, given the initial and final states, and the branch length.

Parameters
initialStateThe initial state.
finalStateThe final state.
lengthThe length of the branch.
typeThe type of substitution to count.
Returns
The number of substitutions on a branch of specified length and according to initial and final states.

Implements bpp::SubstitutionCountInterface.

Definition at line 179 of file DecompositionSubstitutionCount.cpp.

References computeCounts_(), counts_, currentLength_, bpp::DecompositionMethods::model_, and bpp::TextTools::toString().

◆ getNumberOfSubstitutionsPerType()

std::vector< double > DecompositionSubstitutionCount::getNumberOfSubstitutionsPerType ( size_t  initialState,
size_t  finalState,
double  length 
) const
overridevirtual

Get the numbers of susbstitutions on a branch for all types, for an initial and final states, given the branch length.

Parameters
initialStateThe initial state.
finalStateThe final state.
lengthThe length of the branch.
Returns
A matrix with all numbers of substitutions for each initial and final states.

Implements bpp::SubstitutionCountInterface.

Definition at line 196 of file DecompositionSubstitutionCount.cpp.

References computeCounts_(), counts_, currentLength_, bpp::SubstitutionCountInterface::getNumberOfSubstitutionTypes(), bpp::DecompositionMethods::model_, and bpp::TextTools::toString().

◆ getNumberOfSubstitutionTypes()

virtual size_t bpp::SubstitutionCountInterface::getNumberOfSubstitutionTypes ( ) const
inlinevirtualinherited

◆ getSubstitutionRegister()

std::shared_ptr<const SubstitutionRegisterInterface> bpp::AbstractSubstitutionCount::getSubstitutionRegister ( ) const
inlinevirtualinherited
Returns
The SubstitutionRegister object associated to this instance. The register contains the description of the various substitutions types that are mapped.

Implements bpp::SubstitutionCountInterface.

Definition at line 170 of file SubstitutionCount.h.

References bpp::AbstractSubstitutionCount::register_.

◆ getWeights()

std::shared_ptr<const AlphabetIndex2> bpp::AbstractWeightedSubstitutionCount::getWeights ( ) const
inlinevirtualinherited

◆ hasDistances()

bool bpp::AbstractSubstitutionDistance::hasDistances ( ) const
inlinevirtualinherited

◆ hasSubstitutionRegister()

bool bpp::AbstractSubstitutionCount::hasSubstitutionRegister ( ) const
inlinevirtualinherited
Returns
Tell if a substitution register has been attached to this class.

Implements bpp::SubstitutionCountInterface.

Definition at line 156 of file SubstitutionCount.h.

References bpp::AbstractSubstitutionCount::register_.

◆ hasWeights()

bool bpp::AbstractWeightedSubstitutionCount::hasWeights ( ) const
inlinevirtualinherited

◆ initBMatrices_()

◆ initCounts_()

void DecompositionSubstitutionCount::initCounts_ ( )
protected

◆ initStates_()

◆ jFunction_() [1/2]

void DecompositionMethods::jFunction_ ( const std::vector< double > &  lambda,
const std::vector< double > &  ilambda,
double  t,
RowMatrix< double > &  result,
RowMatrix< double > &  iresult 
) const
protectedinherited

Compute the integral part of the computation, in complex numbers.

Definition at line 135 of file DecompositionMethods.cpp.

References bpp::abs(), bpp::VectorTools::cos(), bpp::VectorTools::exp(), bpp::DecompositionMethods::nbStates_, bpp::VectorTools::sin(), and bpp::NumConstants::TINY().

◆ jFunction_() [2/2]

void DecompositionMethods::jFunction_ ( const std::vector< double > &  lambda,
double  t,
RowMatrix< double > &  result 
) const
protectedinherited

Compute the integral part of the computation.

Definition at line 117 of file DecompositionMethods.cpp.

References bpp::abs(), bpp::VectorTools::exp(), bpp::DecompositionMethods::nbStates_, and bpp::NumConstants::TINY().

Referenced by bpp::DecompositionMethods::computeExpectations().

◆ operator=()

◆ setDistanceBMatrices_()

◆ setDistances()

void AbstractSubstitutionDistance::setDistances ( std::shared_ptr< const AlphabetIndex2 distances)
virtualinherited

◆ setSubstitutionModel()

void DecompositionSubstitutionCount::setSubstitutionModel ( std::shared_ptr< const SubstitutionModelInterface model)
overridevirtual

◆ setSubstitutionRegister()

void bpp::AbstractSubstitutionCount::setSubstitutionRegister ( std::shared_ptr< const SubstitutionRegisterInterface reg)
inlinevirtualinherited

attribution of a SubstitutionRegister

Parameters
regpointer to a SubstitutionRegister

Implements bpp::SubstitutionCountInterface.

Definition at line 164 of file SubstitutionCount.h.

References bpp::AbstractSubstitutionCount::register_, and bpp::AbstractSubstitutionCount::substitutionRegisterHasChanged().

◆ setWeights()

void AbstractWeightedSubstitutionCount::setWeights ( std::shared_ptr< const AlphabetIndex2 weights)
virtualinherited

◆ storeAllNumbersOfSubstitutions()

void DecompositionSubstitutionCount::storeAllNumbersOfSubstitutions ( double  length,
size_t  type,
Eigen::MatrixXd &  mat 
) const
overridevirtual

Stores the numbers of susbstitutions on a branch, for each initial and final states, and given the branch length.

Parameters
lengthThe length of the branch.
typeThe type of susbstitution to count.
matThe matrix filled with all numbers of substitutions for each initial and final states.

Implements bpp::SubstitutionCountInterface.

Definition at line 152 of file DecompositionSubstitutionCount.cpp.

References computeCounts_(), counts_, currentLength_, bpp::DecompositionMethods::model_, bpp::DecompositionMethods::nbStates_, and bpp::TextTools::toString().

◆ substitutionRegisterHasChanged()

◆ weightsHaveChanged()

void DecompositionSubstitutionCount::weightsHaveChanged ( )
overrideprotectedvirtual

Member Data Documentation

◆ bMatrices_

std::vector< RowMatrix<double> > bpp::DecompositionMethods::bMatrices_
protectedinherited

◆ counts_

std::vector< RowMatrix<double> > bpp::DecompositionSubstitutionCount::counts_
mutableprivate

◆ currentLength_

◆ distances_

◆ insideIProducts_

std::vector< RowMatrix<double> > bpp::DecompositionMethods::insideIProducts_
protectedinherited

◆ insideProducts_

std::vector< RowMatrix<double> > bpp::DecompositionMethods::insideProducts_
protectedinherited

◆ jIMat_

RowMatrix<double> bpp::DecompositionMethods::jIMat_
protectedinherited

◆ jMat_

◆ leftEigenVectors_

◆ leftIEigenVectors_

◆ model_

◆ nbStates_

◆ nbTypes_

◆ register_

◆ rightEigenVectors_

ColMatrix<double> bpp::DecompositionMethods::rightEigenVectors_
protectedinherited

◆ rightIEigenVectors_

◆ weights_


The documentation for this class was generated from the following files: