bpp-phyl  2.2.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 (const SubstitutionModel *model, AlphabetIndex1 *alphIndex)
 
 DecompositionReward (const DecompositionReward &dr)
 
DecompositionRewardoperator= (const DecompositionReward &dr)
 
virtual ~DecompositionReward ()
 
DecompositionRewardclone () const
 
double getReward (size_t initialState, size_t finalState, double length) const
 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
 Get the rewards on a branch, for each initial and final states, and given the branch length. More...
 
void setSubstitutionModel (const SubstitutionModel *model)
 Set the substitution model. More...
 
bool hasAlphabetIndex () const
 
void setAlphabetIndex (AlphabetIndex1 *alphIndex)
 
const AlphabetIndex1 * getAlphabetIndex () const
 
AlphabetIndex1 * getAlphabetIndex ()
 
virtual const Alphabet * getAlphabet () 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 computeRewards_ (double length) const
 
void jFunction_ (const std::vector< double > &lambda, double t, RowMatrix< double > &result) const
 
void alphabetIndexHasChanged () throw (Exception)
 

Protected Attributes

AlphabetIndex1 * alphIndex_
 

Private Member Functions

void resetStates_ ()
 
void computeBMatrice_ ()
 
void computeEigen_ ()
 
void computeProducts_ ()
 

Private Attributes

const ReversibleSubstitutionModelmodel_
 
size_t nbStates_
 
RowMatrix< double > jMat_
 
RowMatrix< double > v_
 
RowMatrix< double > vInv_
 
std::vector< double > lambda_
 
RowMatrix< double > bMatrice_
 
RowMatrix< double > insideProduct_
 
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 65 of file DecompositionReward.h.

Constructor & Destructor Documentation

◆ DecompositionReward() [1/2]

DecompositionReward::DecompositionReward ( const SubstitutionModel model,
AlphabetIndex1 *  alphIndex 
)

◆ DecompositionReward() [2/2]

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

Definition at line 80 of file DecompositionReward.h.

◆ ~DecompositionReward()

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

Definition at line 110 of file DecompositionReward.h.

Member Function Documentation

◆ alphabetIndexHasChanged()

void DecompositionReward::alphabetIndexHasChanged ( )
throw (Exception
)
protectedvirtual

◆ clone()

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

Implements bpp::Reward.

Definition at line 112 of file DecompositionReward.h.

References DecompositionReward().

◆ computeBMatrice_()

void DecompositionReward::computeBMatrice_ ( )
private

◆ computeEigen_()

◆ computeProducts_()

void DecompositionReward::computeProducts_ ( )
private

◆ computeRewards_()

void DecompositionReward::computeRewards_ ( double  length) const
protected

◆ getAllRewards()

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

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 148 of file DecompositionReward.cpp.

References computeRewards_(), currentLength_, and rewards_.

◆ getAlphabet()

virtual 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 108 of file Reward.h.

References bpp::Reward::getAlphabetIndex().

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

◆ getAlphabetIndex() [1/2]

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 194 of file Reward.h.

References bpp::AbstractReward::alphIndex_.

Referenced by computeBMatrice_().

◆ getAlphabetIndex() [2/2]

AlphabetIndex1* bpp::AbstractReward::getAlphabetIndex ( )
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 196 of file Reward.h.

References bpp::AbstractReward::alphIndex_.

◆ 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 115 of file Reward.h.

References bpp::Reward::getAlphabet().

◆ getReward()

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

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 162 of file DecompositionReward.cpp.

References computeRewards_(), currentLength_, and rewards_.

◆ 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 179 of file Reward.h.

References bpp::AbstractReward::alphIndex_.

◆ jFunction_()

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

Definition at line 110 of file DecompositionReward.cpp.

References nbStates_.

Referenced by computeRewards_().

◆ operator=()

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

◆ resetStates_()

void DecompositionReward::resetStates_ ( )
private

Definition at line 99 of file DecompositionReward.cpp.

References bMatrice_, insideProduct_, jMat_, lambda_, nbStates_, rewards_, v_, and vInv_.

Referenced by setSubstitutionModel().

◆ setAlphabetIndex()

void bpp::AbstractReward::setAlphabetIndex ( AlphabetIndex1 *  alphind)
inlinevirtualinherited
Parameters
alphindThe new AlphabetIndex1 object to be associated to this instance.

Implements bpp::Reward.

Definition at line 188 of file Reward.h.

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

◆ setSubstitutionModel()

void DecompositionReward::setSubstitutionModel ( const SubstitutionModel model)
virtual

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 176 of file DecompositionReward.cpp.

References bpp::AbstractReward::alphIndex_, computeEigen_(), computeProducts_(), computeRewards_(), currentLength_, bpp::SubstitutionModel::getAlphabet(), model_, nbStates_, and resetStates_().

Member Data Documentation

◆ alphIndex_

◆ bMatrice_

RowMatrix<double> bpp::DecompositionReward::bMatrice_
private

Definition at line 73 of file DecompositionReward.h.

Referenced by computeBMatrice_(), computeProducts_(), operator=(), and resetStates_().

◆ currentLength_

double bpp::DecompositionReward::currentLength_
mutableprivate

◆ insideProduct_

RowMatrix<double> bpp::DecompositionReward::insideProduct_
private

Definition at line 73 of file DecompositionReward.h.

Referenced by computeProducts_(), computeRewards_(), operator=(), and resetStates_().

◆ jMat_

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

Definition at line 71 of file DecompositionReward.h.

Referenced by computeRewards_(), operator=(), and resetStates_().

◆ lambda_

std::vector<double> bpp::DecompositionReward::lambda_
mutableprivate

Definition at line 72 of file DecompositionReward.h.

Referenced by computeEigen_(), computeRewards_(), operator=(), and resetStates_().

◆ model_

const ReversibleSubstitutionModel* bpp::DecompositionReward::model_
private

◆ nbStates_

size_t bpp::DecompositionReward::nbStates_
private

◆ rewards_

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

◆ v_

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

◆ vInv_

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

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