bpp-phyl3  3.0.0
bpp::DRTreeParsimonyScore Class Reference

Double recursive implementation of interface TreeParsimonyScore. More...

#include <Bpp/Phyl/Parsimony/DRTreeParsimonyScore.h>

+ Inheritance diagram for bpp::DRTreeParsimonyScore:
+ Collaboration diagram for bpp::DRTreeParsimonyScore:

Public Member Functions

 DRTreeParsimonyScore (std::shared_ptr< TreeTemplate< Node >> tree, std::shared_ptr< const SiteContainerInterface > data, bool verbose=true, bool includeGaps=false)
 
 DRTreeParsimonyScore (std::shared_ptr< TreeTemplate< Node >> tree, std::shared_ptr< const SiteContainerInterface > data, std::shared_ptr< const StateMapInterface > statesMap, bool verbose=true)
 
 DRTreeParsimonyScore (const DRTreeParsimonyScore &tp)
 
DRTreeParsimonyScoreoperator= (const DRTreeParsimonyScore &tp)
 
virtual ~DRTreeParsimonyScore ()
 
DRTreeParsimonyScoreclone () const override
 
unsigned int getScore () const override
 Get the score for the current tree, i.e. the total minimum number of changes in the tree. More...
 
unsigned int getScoreForSite (size_t site) const override
 Get the score for a given site for the current tree, i.e. the total minimum number of changes in the tree for this site. More...
 
const Treetree () const override
 Get the tree for which scores are computed. More...
 
virtual const TreeTemplate< Node > & treeTemplate () const
 
virtual std::shared_ptr< const TreeTemplate< Node > > getTreeTemplate () const
 
std::vector< unsigned int > getScorePerSite () const override
 Get the score for each site for the current tree, i.e. the total minimum number of changes in the tree for each site. More...
 
const StateMapInterfacestateMap () const override
 Get the state map associated to this instance. More...
 
std::shared_ptr< const StateMapInterfacegetStateMap () const override
 Get the state map associated to this instance. More...
 
virtual void topologyChangePerformed (const TopologyChangeEvent &event)
 Notify a topology change event. More...
 
Thee NNISearchable interface.
double getTopologyValue () const override
 Get the current score of this NNISearchable object. More...
 
double testNNI (int nodeId) const override
 Send the score of a NNI movement, without performing it. More...
 
void doNNI (int nodeId) override
 Perform a NNI movement. More...
 
const Treetopology () const override
 Get the tree associated to this NNISearchable object. More...
 
void topologyChangeTested (const TopologyChangeEvent &event) override
 Notify a topology change event. More...
 
void topologyChangeSuccessful (const TopologyChangeEvent &event) override
 Tell that a topology change is definitive. More...
 

Static Public Member Functions

static void computeScoresPostorderForNode (const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
 Compute bitsets and scores for each site for a node, in postorder. More...
 
static void computeScoresPreorderForNode (const DRTreeParsimonyNodeData &pData, const Node *source, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
 Compute bitsets and scores for each site for a node, in preorder. More...
 
static void computeScoresForNode (const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
 Compute bitsets and scores for each site for a node, in all directions. More...
 
static void computeScoresFromArrays (const std::vector< const std::vector< Bitset > * > &iBitsets, const std::vector< const std::vector< unsigned int > * > &iScores, std::vector< Bitset > &oBitsets, std::vector< unsigned int > &oScores)
 Compute bitsets and scores from an array of arrays. More...
 

Protected Member Functions

virtual void computeScores ()
 Compute all scores. More...
 
virtual void computeScoresPreorder (const Node *)
 Compute scores (preorder algorithm). More...
 
virtual void computeScoresPostorder (const Node *)
 Compute scores (postorder algorithm). More...
 
virtual Treetree_ ()
 
virtual TreeTemplate< Node > & treeTemplate_ ()
 
virtual std::shared_ptr< TreeTemplate< Node > > getTreeTemplate_ ()
 

Private Member Functions

void init_ (std::shared_ptr< const SiteContainerInterface > data, bool verbose)
 

Private Attributes

std::unique_ptr< DRTreeParsimonyDataparsimonyData_
 
size_t nbDistinctSites_
 
std::shared_ptr< TreeTemplate< Node > > treePtr_
 
std::shared_ptr< const SiteContainerInterfacedata_
 
std::shared_ptr< const Alphabetalphabet_
 
std::shared_ptr< const StateMapInterfacestatesMap_
 
size_t nbStates_
 

Detailed Description

Double recursive implementation of interface TreeParsimonyScore.

Uses a DRTreeParsimonyData object for data storage.

Definition at line 21 of file DRTreeParsimonyScore.h.

Constructor & Destructor Documentation

◆ DRTreeParsimonyScore() [1/3]

DRTreeParsimonyScore::DRTreeParsimonyScore ( std::shared_ptr< TreeTemplate< Node >>  tree,
std::shared_ptr< const SiteContainerInterface data,
bool  verbose = true,
bool  includeGaps = false 
)

Definition at line 17 of file DRTreeParsimonyScore.cpp.

References init_().

Referenced by clone().

◆ DRTreeParsimonyScore() [2/3]

DRTreeParsimonyScore::DRTreeParsimonyScore ( std::shared_ptr< TreeTemplate< Node >>  tree,
std::shared_ptr< const SiteContainerInterface data,
std::shared_ptr< const StateMapInterface statesMap,
bool  verbose = true 
)

Definition at line 29 of file DRTreeParsimonyScore.cpp.

References init_().

◆ DRTreeParsimonyScore() [3/3]

DRTreeParsimonyScore::DRTreeParsimonyScore ( const DRTreeParsimonyScore tp)

◆ ~DRTreeParsimonyScore()

DRTreeParsimonyScore::~DRTreeParsimonyScore ( )
virtual

Definition at line 78 of file DRTreeParsimonyScore.cpp.

Member Function Documentation

◆ clone()

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

Implements bpp::NNISearchable.

Definition at line 48 of file DRTreeParsimonyScore.h.

References DRTreeParsimonyScore().

◆ computeScores()

void DRTreeParsimonyScore::computeScores ( )
protectedvirtual

Compute all scores.

Call the computeScoresPreorder and computeScoresPostorder methods, and then initialize rootBitsets_ and rootScores_.

Definition at line 82 of file DRTreeParsimonyScore.cpp.

References computeScoresForNode(), computeScoresPostorder(), computeScoresPreorder(), parsimonyData_, and bpp::AbstractTreeParsimonyScore::treeTemplate().

Referenced by init_(), and topologyChangeTested().

◆ computeScoresForNode()

void DRTreeParsimonyScore::computeScoresForNode ( const DRTreeParsimonyNodeData pData,
std::vector< Bitset > &  rBitsets,
std::vector< unsigned int > &  rScores 
)
static

Compute bitsets and scores for each site for a node, in all directions.

Parameters
pDataThe node data to use.
rBitsetsThe bitset array where to store the resulting bitsets.
rScoresThe score array where to write the resulting scores.

Definition at line 202 of file DRTreeParsimonyScore.cpp.

References computeScoresFromArrays(), bpp::Node::degree(), bpp::DRTreeParsimonyNodeData::getBitsetsArrayForNeighbor(), bpp::Node::getId(), bpp::Node::getNeighbors(), bpp::DRTreeParsimonyNodeData::getNode(), and bpp::DRTreeParsimonyNodeData::getScoresArrayForNeighbor().

Referenced by computeScores().

◆ computeScoresFromArrays()

void DRTreeParsimonyScore::computeScoresFromArrays ( const std::vector< const std::vector< Bitset > * > &  iBitsets,
const std::vector< const std::vector< unsigned int > * > &  iScores,
std::vector< Bitset > &  oBitsets,
std::vector< unsigned int > &  oScores 
)
static

Compute bitsets and scores from an array of arrays.

This method is the more general score computation. Depending on what is passed as input, it may computes scores of a subtree or the whole tree.

Parameters
iBitsetsThe vector of bitset arrays to use.
iScoresThe vector of score arrays to use.
oBitsetsThe bitset array where to store the resulting bitsets.
oScoresThe score array where to write the resulting scores.

Definition at line 238 of file DRTreeParsimonyScore.cpp.

Referenced by computeScoresForNode(), computeScoresPostorderForNode(), computeScoresPreorderForNode(), and testNNI().

◆ computeScoresPostorder()

void DRTreeParsimonyScore::computeScoresPostorder ( const Node node)
protectedvirtual

◆ computeScoresPostorderForNode()

void DRTreeParsimonyScore::computeScoresPostorderForNode ( const DRTreeParsimonyNodeData pData,
std::vector< Bitset > &  rBitsets,
std::vector< unsigned int > &  rScores 
)
static

Compute bitsets and scores for each site for a node, in postorder.

Parameters
pDataThe node data to use.
rBitsetsThe bitset array where to store the resulting bitsets.
rScoresThe score array where to write the resulting scores.

Definition at line 123 of file DRTreeParsimonyScore.cpp.

References computeScoresFromArrays(), bpp::Node::degree(), bpp::DRTreeParsimonyNodeData::getBitsetsArrayForNeighbor(), bpp::Node::getFather(), bpp::Node::getId(), bpp::Node::getNeighbors(), bpp::DRTreeParsimonyNodeData::getNode(), and bpp::DRTreeParsimonyNodeData::getScoresArrayForNeighbor().

Referenced by computeScoresPostorder().

◆ computeScoresPreorder()

◆ computeScoresPreorderForNode()

void DRTreeParsimonyScore::computeScoresPreorderForNode ( const DRTreeParsimonyNodeData pData,
const Node source,
std::vector< Bitset > &  rBitsets,
std::vector< unsigned int > &  rScores 
)
static

Compute bitsets and scores for each site for a node, in preorder.

Parameters
pDataThe node data to use.
sourceThe node where we are coming from.
rBitsetsThe bitset array where to store the resulting bitsets.
rScoresThe score array where to write the resulting scores.

Definition at line 181 of file DRTreeParsimonyScore.cpp.

References computeScoresFromArrays(), bpp::Node::degree(), bpp::DRTreeParsimonyNodeData::getBitsetsArrayForNeighbor(), bpp::Node::getId(), bpp::Node::getNeighbors(), bpp::DRTreeParsimonyNodeData::getNode(), and bpp::DRTreeParsimonyNodeData::getScoresArrayForNeighbor().

Referenced by computeScoresPreorder().

◆ doNNI()

void DRTreeParsimonyScore::doNNI ( int  nodeId)
overridevirtual

Perform a NNI movement.

Parameters
nodeIdThe id of the node defining the NNI movement.
Exceptions
NodeExceptionIf the node does not define a valid NNI.

Implements bpp::NNISearchable.

Definition at line 351 of file DRTreeParsimonyScore.cpp.

References bpp::Node::addSon(), bpp::Node::getFather(), bpp::Node::getSon(), bpp::Node::getSonPosition(), bpp::Node::hasFather(), bpp::Node::removeSon(), and bpp::AbstractTreeParsimonyScore::treeTemplate_().

◆ getScore()

unsigned int DRTreeParsimonyScore::getScore ( ) const
overridevirtual

Get the score for the current tree, i.e. the total minimum number of changes in the tree.

Returns
The minimum total number of changes in the tree.

Implements bpp::TreeParsimonyScoreInterface.

Definition at line 221 of file DRTreeParsimonyScore.cpp.

References nbDistinctSites_, and parsimonyData_.

Referenced by getTopologyValue(), and testNNI().

◆ getScoreForSite()

unsigned int DRTreeParsimonyScore::getScoreForSite ( size_t  site) const
overridevirtual

Get the score for a given site for the current tree, i.e. the total minimum number of changes in the tree for this site.

Parameters
siteThe corresponding site.
Returns
The minimum total number of changes in the tree for site 'site'.

Implements bpp::TreeParsimonyScoreInterface.

Definition at line 232 of file DRTreeParsimonyScore.cpp.

References parsimonyData_.

◆ getScorePerSite()

std::vector< unsigned int > AbstractTreeParsimonyScore::getScorePerSite ( ) const
overridevirtualinherited

Get the score for each site for the current tree, i.e. the total minimum number of changes in the tree for each site.

Returns
The minimum total number of changes in the tree for each site.

Implements bpp::TreeParsimonyScoreInterface.

Definition at line 69 of file AbstractTreeParsimonyScore.cpp.

References bpp::AbstractTreeParsimonyScore::data_, and bpp::TreeParsimonyScoreInterface::getScoreForSite().

◆ getStateMap()

std::shared_ptr<const StateMapInterface> bpp::AbstractTreeParsimonyScore::getStateMap ( ) const
inlineoverridevirtualinherited

Get the state map associated to this instance.

Returns
A shared pointer toward the underlying state map.

Implements bpp::TreeParsimonyScoreInterface.

Definition at line 54 of file AbstractTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::statesMap_.

Referenced by init_().

◆ getTopologyValue()

double bpp::DRTreeParsimonyScore::getTopologyValue ( ) const
inlineoverridevirtual

Get the current score of this NNISearchable object.

Returns
The current score of this instance.

Implements bpp::NNISearchable.

Definition at line 133 of file DRTreeParsimonyScore.h.

References getScore().

◆ getTreeTemplate()

virtual std::shared_ptr<const TreeTemplate<Node> > bpp::AbstractTreeParsimonyScore::getTreeTemplate ( ) const
inlinevirtualinherited

◆ getTreeTemplate_()

virtual std::shared_ptr<TreeTemplate<Node> > bpp::AbstractTreeParsimonyScore::getTreeTemplate_ ( )
inlineprotectedvirtualinherited

◆ init_()

◆ operator=()

DRTreeParsimonyScore & DRTreeParsimonyScore::operator= ( const DRTreeParsimonyScore tp)

◆ stateMap()

const StateMapInterface& bpp::AbstractTreeParsimonyScore::stateMap ( ) const
inlineoverridevirtualinherited

Get the state map associated to this instance.

Returns
The underlying state map.

Implements bpp::TreeParsimonyScoreInterface.

Definition at line 53 of file AbstractTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::statesMap_.

◆ testNNI()

double DRTreeParsimonyScore::testNNI ( int  nodeId) const
overridevirtual

Send the score of a NNI movement, without performing it.

This methods sends the score variation. This variation must be negative if the new point is better, i.e. the object is to be used with a minimizing optimization (for consistence with Optimizer objects).

Parameters
nodeIdThe id of the node defining the NNI movement.
Returns
The score variation of the NNI.
Exceptions
NodeExceptionIf the node does not define a valid NNI.

Implements bpp::NNISearchable.

Definition at line 276 of file DRTreeParsimonyScore.cpp.

References computeScoresFromArrays(), bpp::DRTreeParsimonyNodeData::getBitsetsArrayForNeighbor(), bpp::Node::getFather(), bpp::Node::getId(), bpp::TreeTemplateTools::getRemainingNeighbors(), getScore(), bpp::DRTreeParsimonyNodeData::getScoresArrayForNeighbor(), bpp::Node::getSon(), bpp::Node::getSonPosition(), bpp::Node::hasFather(), nbDistinctSites_, parsimonyData_, and bpp::AbstractTreeParsimonyScore::treeTemplate().

◆ topology()

const Tree& bpp::DRTreeParsimonyScore::topology ( ) const
inlineoverridevirtual

Get the tree associated to this NNISearchable object.

Returns
The tree associated to this instance.

Implements bpp::NNISearchable.

Definition at line 139 of file DRTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::tree().

◆ topologyChangePerformed()

virtual void bpp::TopologyListener::topologyChangePerformed ( const TopologyChangeEvent event)
inlinevirtualinherited

Notify a topology change event.

This method is to be invoked after one or several NNI are performed. It allows appropriate recomputations.

In most case, this is the same as topologyChangeTested() + topologyChangeSuccessful().

Parameters
eventThe topology change event.

Definition at line 67 of file TopologySearch.h.

References bpp::TopologyListener::topologyChangeSuccessful(), and bpp::TopologyListener::topologyChangeTested().

◆ topologyChangeSuccessful()

void bpp::DRTreeParsimonyScore::topologyChangeSuccessful ( const TopologyChangeEvent event)
inlineoverridevirtual

Tell that a topology change is definitive.

This method is called after the topologyChangeTested() method.

Parameters
eventThe topology change event.

Implements bpp::TopologyListener.

Definition at line 147 of file DRTreeParsimonyScore.h.

◆ topologyChangeTested()

void bpp::DRTreeParsimonyScore::topologyChangeTested ( const TopologyChangeEvent event)
inlineoverridevirtual

Notify a topology change event.

Parameters
eventThe topology change event.

Implements bpp::TopologyListener.

Definition at line 141 of file DRTreeParsimonyScore.h.

References computeScores(), and parsimonyData_.

◆ tree()

const Tree& bpp::AbstractTreeParsimonyScore::tree ( ) const
inlineoverridevirtualinherited

Get the tree for which scores are computed.

Returns
The tree associated to this object.

Implements bpp::TreeParsimonyScoreInterface.

Definition at line 49 of file AbstractTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::treePtr_.

Referenced by topology().

◆ tree_()

virtual Tree& bpp::AbstractTreeParsimonyScore::tree_ ( )
inlineprotectedvirtualinherited

◆ treeTemplate()

virtual const TreeTemplate<Node>& bpp::AbstractTreeParsimonyScore::treeTemplate ( ) const
inlinevirtualinherited

Definition at line 50 of file AbstractTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::treePtr_.

Referenced by computeScores(), and testNNI().

◆ treeTemplate_()

virtual TreeTemplate<Node>& bpp::AbstractTreeParsimonyScore::treeTemplate_ ( )
inlineprotectedvirtualinherited

Definition at line 58 of file AbstractTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::treePtr_.

Referenced by doNNI().

Member Data Documentation

◆ alphabet_

std::shared_ptr<const Alphabet> bpp::AbstractTreeParsimonyScore::alphabet_
privateinherited

◆ data_

std::shared_ptr<const SiteContainerInterface> bpp::AbstractTreeParsimonyScore::data_
privateinherited

◆ nbDistinctSites_

size_t bpp::DRTreeParsimonyScore::nbDistinctSites_
private

Definition at line 27 of file DRTreeParsimonyScore.h.

Referenced by getScore(), init_(), operator=(), and testNNI().

◆ nbStates_

size_t bpp::AbstractTreeParsimonyScore::nbStates_
privateinherited

◆ parsimonyData_

std::unique_ptr<DRTreeParsimonyData> bpp::DRTreeParsimonyScore::parsimonyData_
private

◆ statesMap_

std::shared_ptr<const StateMapInterface> bpp::AbstractTreeParsimonyScore::statesMap_
privateinherited

◆ treePtr_


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