bpp-phyl3  3.0.0
bpp::DecompositionReward Class Reference

Analytical reward using the eigen decomposition method. More...

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

+ Inheritance diagram for bpp::DecompositionReward:
+ Collaboration diagram for bpp::DecompositionReward:

Public Member Functions

 DecompositionReward (std::shared_ptr< const SubstitutionModelInterface > model, std::shared_ptr< const AlphabetIndex1 > alphIndex)
 
 DecompositionReward (const StateMapInterface &stateMap, std::shared_ptr< const AlphabetIndex1 > alphIndex)
 
 DecompositionReward (const DecompositionReward &dr)
 
DecompositionRewardoperator= (const DecompositionReward &dr)
 
virtual ~DecompositionReward ()
 
DecompositionRewardclone () const override
 
double getReward (size_t initialState, size_t finalState, double length) const override
 Get the reward of susbstitutions on a branch, given the initial and final states, and the branch length. More...
 
Matrix< double > * getAllRewards (double length) const override
 Get the rewards on a branch, for each initial and final states, and given the branch length. More...
 
void storeAllRewards (double length, Eigen::MatrixXd &mat) const override
 Store the rewards on a branch, for each initial and final states, and given the branch length. More...
 
void setSubstitutionModel (std::shared_ptr< const SubstitutionModelInterface > model) override
 Set the substitution model. More...
 
bool hasAlphabetIndex () const
 
void setAlphabetIndex (std::shared_ptr< const AlphabetIndex1 > alphIndex)
 attribution of an AlphabetIndex1 More...
 
std::shared_ptr< const AlphabetIndex1getAlphabetIndex () const
 
const AlphabetIndex1alphabetIndex () const
 
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...
 

Protected Member Functions

void initRewards_ ()
 
void computeRewards_ (double length) const
 
void alphabetIndexHasChanged () 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 AlphabetIndex1alphIndex_
 
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 fillBMatrice_ ()
 

Private Attributes

RowMatrix< double > rewards_
 
double currentLength_
 

Detailed Description

Analytical reward using the eigen decomposition method.

The codes is adapted from the original R code by Paula Tataru and Asger Hobolth to the formula in the article of Minin & Suchard.

Minin, V.N. and Suchard, M.A., Fast, accurate and simulation-free stochastic mapping Philosophical Transactions of the Royal Society B 2008 363:3985-95.

Only reversible models are supported for now.

Author
Laurent Guéguen

Definition at line 28 of file DecompositionReward.h.

Constructor & Destructor Documentation

◆ DecompositionReward() [1/3]

DecompositionReward::DecompositionReward ( std::shared_ptr< const SubstitutionModelInterface model,
std::shared_ptr< const AlphabetIndex1 alphIndex 
)

◆ DecompositionReward() [2/3]

DecompositionReward::DecompositionReward ( const StateMapInterface stateMap,
std::shared_ptr< const AlphabetIndex1 alphIndex 
)

Definition at line 38 of file DecompositionReward.cpp.

◆ DecompositionReward() [3/3]

bpp::DecompositionReward::DecompositionReward ( const DecompositionReward dr)
inline

Definition at line 45 of file DecompositionReward.h.

◆ ~DecompositionReward()

virtual bpp::DecompositionReward::~DecompositionReward ( )
inlinevirtual

Definition at line 62 of file DecompositionReward.h.

Member Function Documentation

◆ alphabetIndex()

const AlphabetIndex1& bpp::AbstractReward::alphabetIndex ( ) const
inlineinherited

Definition at line 161 of file Reward.h.

References bpp::AbstractReward::alphIndex_.

◆ alphabetIndexHasChanged()

void DecompositionReward::alphabetIndexHasChanged ( )
overrideprotectedvirtual

◆ clone()

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

Implements bpp::Reward.

Definition at line 64 of file DecompositionReward.h.

References DecompositionReward().

◆ computeExpectations() [1/2]

◆ computeExpectations() [2/2]

◆ computeProducts_()

◆ computeRewards_()

◆ fillBMatrice_()

◆ getAllRewards()

Matrix< double > * DecompositionReward::getAllRewards ( double  length) const
overridevirtual

Get the rewards on a branch, for each initial and final states, and given the branch length.

Parameters
lengthThe length of the branch.
Returns
A matrix with all rewards for each initial and final states.

Implements bpp::Reward.

Definition at line 86 of file DecompositionReward.cpp.

References computeRewards_(), currentLength_, bpp::DecompositionMethods::model_, rewards_, and bpp::TextTools::toString().

◆ getAlphabet()

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

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

Returns
The alphabet associated to this substitution count.

Definition at line 65 of file Reward.h.

References bpp::Reward::getAlphabetIndex().

Referenced by bpp::Reward::getNumberOfStates().

◆ getAlphabetIndex()

std::shared_ptr<const AlphabetIndex1> bpp::AbstractReward::getAlphabetIndex ( ) const
inlinevirtualinherited
Returns
The AlphabetIndex1 object associated to this instance. The alphabet index contains the value associated to each state.

Implements bpp::Reward.

Definition at line 159 of file Reward.h.

References bpp::AbstractReward::alphIndex_.

Referenced by fillBMatrice_().

◆ getNumberOfStates()

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

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

Returns
The number of states in the model/alphabet.

Definition at line 75 of file Reward.h.

References bpp::Reward::getAlphabet().

◆ getReward()

double DecompositionReward::getReward ( size_t  initialState,
size_t  finalState,
double  length 
) const
overridevirtual

Get the reward 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.
Returns
The reward of the function on a branch of specified length and according to initial and final states.

Implements bpp::Reward.

Definition at line 130 of file DecompositionReward.cpp.

References computeRewards_(), currentLength_, rewards_, and bpp::TextTools::toString().

◆ hasAlphabetIndex()

bool bpp::AbstractReward::hasAlphabetIndex ( ) const
inlinevirtualinherited
Returns
Tell if an alphabet index has been attached to this class.

Implements bpp::Reward.

Definition at line 146 of file Reward.h.

References bpp::AbstractReward::alphIndex_.

◆ initBMatrices_()

◆ initRewards_()

void DecompositionReward::initRewards_ ( )
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=()

DecompositionReward& bpp::DecompositionReward::operator= ( const DecompositionReward dr)
inline

◆ setAlphabetIndex()

void bpp::AbstractReward::setAlphabetIndex ( std::shared_ptr< const AlphabetIndex1 alphIndex)
inlinevirtualinherited

attribution of an AlphabetIndex1

Parameters
alphIndexpointer to a AlphabetIndex1

Implements bpp::Reward.

Definition at line 153 of file Reward.h.

References bpp::AbstractReward::alphabetIndexHasChanged(), and bpp::AbstractReward::alphIndex_.

◆ setSubstitutionModel()

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

Set the substitution model.

Parameters
modelA pointer toward the substitution model to use. Only reversible models are currently supported. Setting a non-reversible model will throw an exception.

Implements bpp::Reward.

Definition at line 144 of file DecompositionReward.cpp.

References bpp::AbstractReward::alphIndex_, bpp::DecompositionMethods::computeProducts_(), computeRewards_(), currentLength_, fillBMatrice_(), initRewards_(), and bpp::DecompositionMethods::setSubstitutionModel().

◆ storeAllRewards()

void DecompositionReward::storeAllRewards ( double  length,
Eigen::MatrixXd &  mat 
) const
overridevirtual

Store the rewards on a branch, for each initial and final states, and given the branch length.

Parameters
lengthThe length of the branch.
matA matrix to store all rewards for each initial and final states.

Implements bpp::Reward.

Definition at line 103 of file DecompositionReward.cpp.

References computeRewards_(), currentLength_, bpp::DecompositionMethods::model_, bpp::DecompositionMethods::nbStates_, rewards_, and bpp::TextTools::toString().

Member Data Documentation

◆ alphIndex_

◆ bMatrices_

◆ currentLength_

double bpp::DecompositionReward::currentLength_
mutableprivate

◆ 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_

◆ rewards_

RowMatrix<double> bpp::DecompositionReward::rewards_
mutableprivate

◆ rightEigenVectors_

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

◆ rightIEigenVectors_


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