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 _LEGACY_PROBABILISTIC_REWARD_MAPPING_H_
6 #define _LEGACY_PROBABILISTIC_REWARD_MAPPING_H_
7 
8 #include "RewardMapping.h"
9 #include "../../Mapping/Reward.h" // We use the new implementation here
10 #include "../../Tree/TreeExceptions.h"
11 
12 #include <Bpp/Text/TextTools.h>
13 
14 // From the STL:
15 #include <vector>
16 
17 namespace bpp
18 {
30 {
31 private:
32  std::shared_ptr<const Reward> reward_;
33 
39  std::vector<std::vector<double>> mapping_;
40 
41 public:
49  LegacyProbabilisticRewardMapping(const Tree& tree, std::shared_ptr<const Reward> reward, size_t numberOfSites) :
51  reward_(reward),
52  mapping_(0)
53  {
54  setNumberOfSites(numberOfSites);
55  }
56 
64  reward_(nullptr),
65  mapping_(0)
66  {}
67 
68 
70  {
71  return new LegacyProbabilisticRewardMapping(*this);
72  }
73 
75 
77 
79 
80 public:
81  virtual double getReward(int nodeId, size_t siteIndex) const
82  {
83  return mapping_[siteIndex][getNodeIndex(nodeId)];
84  }
85 
91  virtual void setTree(const Tree& tree);
92 
93  virtual void setNumberOfSites(size_t numberOfSites) override;
94 
100  virtual double& operator()(size_t nodeIndex, size_t siteIndex) override
101  {
102  return mapping_[siteIndex][nodeIndex];
103  }
104 
110  virtual const double& operator()(size_t nodeIndex, size_t siteIndex) const override
111  {
112  return mapping_[siteIndex][nodeIndex];
113  }
114 
120  std::vector<double>& operator[](size_t siteIndex)
121  {
122  return mapping_[siteIndex];
123  }
124 
130  const std::vector<double>& operator[](size_t siteIndex) const
131  {
132  return mapping_[siteIndex];
133  }
134 };
135 } // end of namespace bpp.
136 
137 #endif // _LEGACY_PROBABILISTIC_REWARD_MAPPING_H_
const TreeTemplate< Node > & tree() const override
Definition: Mapping.h:132
virtual size_t getNodeIndex(int nodeId) const override
Definition: Mapping.h:184
Partial implementation of the reward mapping interface.
Definition: RewardMapping.h:49
Legacy data storage class for probabilistic rewards mappings.
const std::vector< double > & operator[](size_t siteIndex) const
Direct access to rewards.
virtual const double & operator()(size_t nodeIndex, size_t siteIndex) const override
Direct access to rewards.
LegacyProbabilisticRewardMapping & operator=(const LegacyProbabilisticRewardMapping &prm)=default
std::vector< double > & operator[](size_t siteIndex)
Direct access to rewards.
LegacyProbabilisticRewardMapping(const LegacyProbabilisticRewardMapping &prm)=default
LegacyProbabilisticRewardMapping * clone() const override
virtual double & operator()(size_t nodeIndex, size_t siteIndex) override
Direct access to rewards.
virtual double getReward(int nodeId, size_t siteIndex) const
LegacyProbabilisticRewardMapping(const Tree &tree)
Build a new ProbabilisticRewardMapping object.
virtual void setNumberOfSites(size_t numberOfSites) override
std::vector< std::vector< double > > mapping_
Rewards storage.
virtual void setTree(const Tree &tree)
(Re)-set the phylogenetic tree associated to this mapping.
LegacyProbabilisticRewardMapping(const Tree &tree, std::shared_ptr< const Reward > reward, size_t numberOfSites)
Build a new LegacyProbabilisticRewardMapping object.
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.