bpp-phyl3  3.0.0
DiscreteDistribution.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_LIKELIHOOD_DATAFLOW_DISCRETEDISTRIBUTION_H
6 #define BPP_PHYL_LIKELIHOOD_DATAFLOW_DISCRETEDISTRIBUTION_H
7 
8 #include <Bpp/Exceptions.h>
13 #include <functional>
14 #include <unordered_map>
15 
16 #include "Definitions.h"
17 
18 namespace bpp
19 {
20 /* Likelihood discrete distribution.
21  */
22 
36 class ConfiguredDistribution : public Value<const DiscreteDistributionInterface*>,
38 {
39  // private:
40  // Context& context_;
41 
42 public:
45 
46  ConfiguredDistribution (Context& context, NodeRefVec&& deps, std::unique_ptr<DiscreteDistributionInterface>&& distrib);
48 
50  {
51  throw bpp::Exception("ConfiguredDistribution clone should not happen.");
52  }
53 
54  std::string description () const final;
55  std::string debugInfo () const final;
56  std::string color() const final
57  {
58  return "blue";
59  }
60 
61  bool compareAdditionalArguments (const Node_DF& other) const;
62 
63  std::size_t hashAdditionalArguments () const;
64 
67 
68  NodeRef recreate (Context& c, NodeRefVec&& deps) final;
69 
70  const ConfiguredParameter& getConfiguredParameter(const std::string& name)
71  {
72  return static_cast<const ConfiguredParameter&>(parameter(name));
73  }
74 
75 private:
76  void compute ()
77  {
78  distrib_->matchParametersValues(getParameters());
79  }
80 
81  std::unique_ptr<DiscreteDistributionInterface> distrib_;
82 };
83 
91 class ProbabilitiesFromDiscreteDistribution : public Value<Eigen::RowVectorXd>
92 {
93 public:
96  using T = Eigen::RowVectorXd;
97 
99 
100  std::string debugInfo () const final;
101 
102  std::string color() const final
103  {
104  return "blue";
105  }
106 
107  bool compareAdditionalArguments (const Node_DF& other) const final;
108 
109  NodeRef derive (Context& c, const Node_DF& node) final;
110  NodeRef recreate (Context& c, NodeRefVec&& deps) final;
111 
112 private:
113  void compute () final;
114 
116 
117 public:
118  static std::shared_ptr<Self> create (Context& c, NodeRefVec&& deps);
119 };
120 
130 {
131 private:
132  uint nCat_;
133 
134 public:
137  using T = double;
138 
139  ProbabilityFromDiscreteDistribution (NodeRefVec&& deps, uint nCat_);
140 
141  std::string debugInfo () const final;
142 
143  bool compareAdditionalArguments (const Node_DF& other) const final;
144 
145  NodeRef derive (Context& c, const Node_DF& node) final;
146  NodeRef recreate (Context& c, NodeRefVec&& deps) final;
147 
148  std::string color() const final
149  {
150  return "blue";
151  }
152 
153 private:
154  void compute () final;
155 
156 public:
157  static std::shared_ptr<Self> create (Context& c, NodeRefVec&& deps, uint nCat);
158 };
159 
169 {
170 private:
171  uint nCat_;
172 
173 public:
176  using T = double;
177 
178  CategoryFromDiscreteDistribution (NodeRefVec&& deps, uint nCat_);
179 
180  std::string debugInfo () const final;
181 
182  bool compareAdditionalArguments (const Node_DF& other) const final;
183 
184  NodeRef derive (Context& c, const Node_DF& node) final;
185  NodeRef recreate (Context& c, NodeRefVec&& deps) final;
186 
187  std::string color() const final
188  {
189  return "blue";
190  }
191 
192 private:
193  void compute () final;
194 
195 public:
196  static std::shared_ptr<Self> create (Context& c, NodeRefVec&& deps, uint nCat);
197 };
198 } // namespace bpp
199 #endif // BPP_PHYL_LIKELIHOOD_DATAFLOW_DISCRETEDISTRIBUTION_H
const Parameter & parameter(const std::string &name) const override
const ParameterList & getParameters() const override
Data flow node representing a DiscreteDistribution configured with parameter values.
const ConfiguredParameter & getConfiguredParameter(const std::string &name)
NumericalDerivativeConfiguration config
Configuration for numerical derivation of computation nodes using this Model.
std::unique_ptr< DiscreteDistributionInterface > distrib_
bool compareAdditionalArguments(const Node_DF &other) const
Compare node-specific configuration to another.
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
ConfiguredDistribution(Context &context, NodeRefVec &&deps, std::unique_ptr< DiscreteDistributionInterface > &&distrib)
std::string color() const final
ConfiguredDistribution * clone() const
std::string description() const final
Node pretty name (default = type name).
void compute()
Computation implementation.
std::size_t hashAdditionalArguments() const
Return the hash of node-specific configuration.
Data flow node representing a parameter.
Definition: Parameter.h:27
Context for dataflow node construction.
Definition: DataFlow.h:527
Base dataflow Node class.
Definition: DataFlow.h:152
ProbabilitiesFromDiscreteDistribution Self
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps)
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
ProbabilitiesFromDiscreteDistribution(NodeRefVec &&deps, const Dimension< T > &dim)
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
void compute() final
Computation implementation.
Abstract Node storing a value of type T.
Definition: DataFlow.h:352
Defines the basic types of data flow nodes.
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
Definition: DataFlow.h:81
std::shared_ptr< Node_DF > NodeRef
Definition: DataFlow.h:78
Store a dimension for type T.
Configuration for a numerical derivation: what delta to use, and type of derivation.