bpp-phyl  2.2.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 (const Tree &tree, const SiteContainer &data, bool verbose=true, bool includeGaps=false) throw (Exception)
 
 DRTreeParsimonyScore (const Tree &tree, const SiteContainer &data, const StateMap *statesMap, bool verbose=true) throw (Exception)
 
 DRTreeParsimonyScore (const DRTreeParsimonyScore &tp)
 
DRTreeParsimonyScoreoperator= (const DRTreeParsimonyScore &tp)
 
virtual ~DRTreeParsimonyScore ()
 
DRTreeParsimonyScoreclone () const
 
unsigned int getScore () const
 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
 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...
 
virtual const TreegetTree () const
 Get the tree for wich scores are computed. More...
 
virtual std::vector< unsigned int > getScoreForEachSite () const
 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...
 
virtual const StateMapgetStateMap () const
 
virtual void topologyChangePerformed (const TopologyChangeEvent &event)
 Notify a topology change event. More...
 
Thee NNISearchable interface.
double getTopologyValue () const throw (Exception)
 Get the current score of this NNISearchable object. More...
 
double testNNI (int nodeId) const throw (NodeException)
 Send the score of a NNI movement, without performing it. More...
 
void doNNI (int nodeId) throw (NodeException)
 Perform a NNI movement. More...
 
const TreegetTopology () const
 Get the tree associated to this NNISearchable object. More...
 
void topologyChangeTested (const TopologyChangeEvent &event)
 Notify a topology change event. More...
 
void topologyChangeSuccessful (const TopologyChangeEvent &event)
 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...
 
const TreeTemplate< Node > * getTreeP_ () const
 
TreeTemplate< Node > * getTreeP_ ()
 

Private Member Functions

void init_ (const SiteContainer &data, bool verbose)
 

Private Attributes

DRTreeParsimonyDataparsimonyData_
 
size_t nbDistinctSites_
 

Detailed Description

Double recursive implementation of interface TreeParsimonyScore.

Uses a DRTreeParsimonyData object for data storage.

Definition at line 55 of file DRTreeParsimonyScore.h.

Constructor & Destructor Documentation

◆ DRTreeParsimonyScore() [1/3]

DRTreeParsimonyScore::DRTreeParsimonyScore ( const Tree tree,
const SiteContainer &  data,
bool  verbose = true,
bool  includeGaps = false 
)
throw (Exception
)

Definition at line 52 of file DRTreeParsimonyScore.cpp.

Referenced by clone().

◆ DRTreeParsimonyScore() [2/3]

DRTreeParsimonyScore::DRTreeParsimonyScore ( const Tree tree,
const SiteContainer &  data,
const StateMap statesMap,
bool  verbose = true 
)
throw (Exception
)

Definition at line 65 of file DRTreeParsimonyScore.cpp.

◆ DRTreeParsimonyScore() [3/3]

DRTreeParsimonyScore::DRTreeParsimonyScore ( const DRTreeParsimonyScore tp)

◆ ~DRTreeParsimonyScore()

DRTreeParsimonyScore::~DRTreeParsimonyScore ( )
virtual

Definition at line 115 of file DRTreeParsimonyScore.cpp.

References parsimonyData_.

Member Function Documentation

◆ clone()

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

Implements bpp::NNISearchable.

Definition at line 89 of file DRTreeParsimonyScore.h.

References DRTreeParsimonyScore().

◆ computeScores()

void DRTreeParsimonyScore::computeScores ( )
protectedvirtual

◆ 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 239 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 scroes fo 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 275 of file DRTreeParsimonyScore.cpp.

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

◆ computeScoresPostorder()

◆ 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 161 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 218 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)
throw (NodeException
)
virtual

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 385 of file DRTreeParsimonyScore.cpp.

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

◆ getScore()

unsigned int DRTreeParsimonyScore::getScore ( ) const
virtual

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::TreeParsimonyScore.

Definition at line 258 of file DRTreeParsimonyScore.cpp.

References bpp::DRTreeParsimonyData::getRootScore(), bpp::AbstractTreeParsimonyData::getWeight(), nbDistinctSites_, and parsimonyData_.

Referenced by getTopologyValue().

◆ getScoreForEachSite()

std::vector< unsigned int > AbstractTreeParsimonyScore::getScoreForEachSite ( ) const
virtualinherited

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::TreeParsimonyScore.

Definition at line 99 of file AbstractTreeParsimonyScore.cpp.

◆ getScoreForSite()

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

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::TreeParsimonyScore.

Definition at line 269 of file DRTreeParsimonyScore.cpp.

References bpp::AbstractTreeParsimonyData::getRootArrayPosition(), bpp::DRTreeParsimonyData::getRootScore(), and parsimonyData_.

◆ getStateMap()

virtual const StateMap& bpp::AbstractTreeParsimonyScore::getStateMap ( ) const
inlinevirtualinherited

◆ getTopology()

const Tree& bpp::DRTreeParsimonyScore::getTopology ( ) const
inlinevirtual

Get the tree associated to this NNISearchable object.

Returns
The tree associated to this instance.

Implements bpp::NNISearchable.

Definition at line 181 of file DRTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::getTree().

◆ getTopologyValue()

double bpp::DRTreeParsimonyScore::getTopologyValue ( ) const
throw (Exception
)
inlinevirtual

Get the current score of this NNISearchable object.

Returns
The current score of this instance.

Implements bpp::NNISearchable.

Definition at line 174 of file DRTreeParsimonyScore.h.

References getScore().

◆ getTree()

virtual const Tree& bpp::AbstractTreeParsimonyScore::getTree ( ) const
inlinevirtualinherited

Get the tree for wich scores are computed.

Returns
The tree associated to this object.

Implements bpp::TreeParsimonyScore.

Definition at line 111 of file AbstractTreeParsimonyScore.h.

References bpp::AbstractTreeParsimonyScore::tree_.

Referenced by computeScores(), and getTopology().

◆ getTreeP_() [1/2]

const TreeTemplate<Node>* bpp::AbstractTreeParsimonyScore::getTreeP_ ( ) const
inlineprotectedinherited

◆ getTreeP_() [2/2]

TreeTemplate<Node>* bpp::AbstractTreeParsimonyScore::getTreeP_ ( )
inlineprotectedinherited

◆ init_()

void DRTreeParsimonyScore::init_ ( const SiteContainer &  data,
bool  verbose 
)
private

Definition at line 78 of file DRTreeParsimonyScore.cpp.

◆ operator=()

◆ testNNI()

double DRTreeParsimonyScore::testNNI ( int  nodeId) const
throw (NodeException
)
virtual

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 313 of file DRTreeParsimonyScore.cpp.

References bpp::DRTreeParsimonyNodeData::getBitsetsArrayForNeighbor(), bpp::Node::getFather(), bpp::Node::getId(), bpp::TreeTemplateTools::getRemainingNeighbors(), bpp::DRTreeParsimonyNodeData::getScoresArrayForNeighbor(), bpp::Node::getSon(), bpp::Node::getSonPosition(), and bpp::Node::hasFather().

◆ 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 105 of file TopologySearch.h.

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

◆ topologyChangeSuccessful()

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

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 189 of file DRTreeParsimonyScore.h.

◆ topologyChangeTested()

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

Notify a topology change event.

Parameters
eventThe topology change event.

Implements bpp::TopologyListener.

Definition at line 183 of file DRTreeParsimonyScore.h.

References computeScores(), parsimonyData_, and bpp::DRTreeParsimonyData::reInit().

Member Data Documentation

◆ nbDistinctSites_

size_t bpp::DRTreeParsimonyScore::nbDistinctSites_
private

Definition at line 61 of file DRTreeParsimonyScore.h.

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

◆ parsimonyData_


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