bpp-phyl3 3.0.0
ProbabilisticRewardMapping.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_MAPPING_PROBABILISTICREWARDMAPPING_H
6#define BPP_PHYL_MAPPING_PROBABILISTICREWARDMAPPING_H
7
9
10#include "../Likelihood/DataFlow/DataFlowCWise.h"
11#include "../Tree/PhyloTreeExceptions.h"
12#include "PhyloBranchReward.h"
13#include "Reward.h"
14#include "RewardMapping.h"
15
16// From the STL:
17#include <vector>
18
19namespace bpp
20{
32 public AssociationTreeGlobalGraphObserver<PhyloNode, PhyloBranchReward>
33{
34public:
36
37private:
50
52
54
55public:
58
59public:
66 ProbabilisticRewardMapping(const PhyloTree& tree, size_t numberOfSites) :
68 {
69 std::unique_ptr<mapTree::EdgeIterator> nIT = allEdgesIterator();
70 for ( ; !nIT->end(); nIT->next())
71 {
72 (**nIT)->setNumberOfSites(numberOfDistinctSites_);
73 }
74 }
75
79 ProbabilisticRewardMapping(const PhyloTree& tree, const PatternType& rootpatterns, size_t nbDistinctSites) :
80 AbstractRewardMapping(), mapTree(tree), rootPatternLinks_(rootpatterns), usePatterns_(true), numberOfDistinctSites_(nbDistinctSites)
81 {
82 std::unique_ptr<mapTree::EdgeIterator> nIT = allEdgesIterator();
83 for ( ; !nIT->end(); nIT->next())
84 {
85 (**nIT)->setNumberOfSites(numberOfDistinctSites_);
86 }
87 }
88
96 {}
97
98
99 ProbabilisticRewardMapping* clone() const override { return new ProbabilisticRewardMapping(*this); }
100
103 {}
104
106 {
109
113 return *this;
114 }
115
117
118public:
119 /*
120 * @brief From Mapping interface
121 *
122 * @{
123 */
124 const PhyloBranch& getBranch(unsigned int branchIndex) const override
125 {
126 return *getEdge(branchIndex);
127 }
128
129 PhyloBranch& getBranch(unsigned int branchIndex) override
130 {
131 return *getEdge(branchIndex);
132 }
133
134 size_t getNumberOfBranches() const override
135 {
136 return getNumberOfEdges();
137 }
138
140 {
142 }
143
144 /*
145 * @}
146 */
147
152 virtual double getReward(int branchId, size_t site) const
153 {
154 return getEdge((uint)branchId)->getSiteReward(getSiteIndex(site));
155 }
156
157 virtual void setNumberOfSites(size_t numberOfSites) override;
158
165 virtual double operator()(uint branchId, size_t siteIndex) const override
166 {
167 return (*getEdge(branchId))(siteIndex);
168 }
169
176 virtual double& operator()(uint branchId, size_t siteIndex) override
177 {
178 return (*getEdge(branchId))(siteIndex);
179 }
180
184 bool usePatterns() const
185 {
186 return usePatterns_;
187 }
188
193 {
194 return rootPatternLinks_;
195 }
196
197 const size_t getSiteIndex(size_t site) const
198 {
199 return rootPatternLinks_[Eigen::Index(site)];
200 }
201};
202} // end of namespace bpp.
203#endif // BPP_PHYL_MAPPING_PROBABILISTICREWARDMAPPING_H
AbstractMapping & operator=(const AbstractMapping &absm)=default
Partial implementation of the substitution mapping interface.
Definition: RewardMapping.h:49
virtual std::unique_ptr< EdgeIterator > allEdgesIterator()=0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const=0
AssociationTreeGraphImplObserver< N, E, TreeGraphImpl > & operator=(bpp::AssociationTreeGraphImplObserver< N, E, TreeGraphImpl > const &treeGraphObserver)
Data storage class for probabilistic rewards mappings.
ProbabilisticRewardMapping & operator=(const ProbabilisticRewardMapping &prm)
const PhyloBranch & getBranch(unsigned int branchIndex) const override
virtual double getReward(int branchId, size_t site) const
Retrieve the rewards, with compressed site positions.
ProbabilisticRewardMapping(const PhyloTree &tree, size_t numberOfSites)
Build a new ProbabilisticRewardMapping object.
virtual void setNumberOfSites(size_t numberOfSites) override
ProbabilisticRewardMapping * clone() const override
PhyloBranch & getBranch(unsigned int branchIndex) override
ProbabilisticRewardMapping(const PhyloTree &tree, const PatternType &rootpatterns, size_t nbDistinctSites)
the same with rootPatternLinks
ProbabilisticRewardMapping(const ProbabilisticRewardMapping &prm)
ProbabilisticRewardMapping(const PhyloTree &tree)
Build a new ProbabilisticRewardMapping object.
virtual double & operator()(uint branchId, size_t siteIndex) override
Direct access to rewards, with COMPRESSED site positions (ie site indexes).
const PatternType & getPatterns() const
returns the vector of site patterns
bool usePatterns() const
Does it use site patterns?
virtual double operator()(uint branchId, size_t siteIndex) const override
Direct access to rewards, with COMPRESSED site positions (ie site indexes)
const size_t getSiteIndex(size_t site) const
AssociationTreeGlobalGraphObserver< PhyloNode, PhyloBranchReward > mapTree
PatternType rootPatternLinks_
Links between sites and patterns.
Defines the basic types of data flow nodes.
Eigen::Matrix< size_t, -1, 1 > PatternType