bpp-phyl3 3.0.0
Simplex_DF.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#include <Bpp/Exceptions.h>
8
9
10using namespace std;
11
12namespace bpp
13{
14// Simplex node
15
16ConfiguredSimplex::ConfiguredSimplex (const Context& context, NodeRefVec&& deps, std::unique_ptr<Simplex>&& simplex)
17 : Value<const Simplex*>(std::move (deps), simplex.get ()), AbstractParametrizable(simplex->getNamespace()) // , context_(context)
18 , simplex_(std::move(simplex))
19{
20 for (const auto& dep:dependencies())
21 {
22 const auto& param = std::dynamic_pointer_cast<ConfiguredParameter>(dep);
23 shareParameter_(param);
24 }
25}
26
28
29std::string ConfiguredSimplex::description () const { return "Simplex"; }
30
31std::string ConfiguredSimplex::debugInfo () const
32{
33 return "nbState=" + std::to_string (simplex_->dimension ());
34}
35
36// Simplex node additional arguments = (type of bpp::Simplex).
37// Everything else is determined by the node dependencies.
38
40{
41 const auto* derived = dynamic_cast<const Self*>(&other);
42 if (derived == nullptr)
43 {
44 return false;
45 }
46 else
47 {
48 const auto& thisFS = *simplex_;
49 const auto& otherFS = *derived->simplex_;
50 return typeid (thisFS) == typeid (otherFS);
51 }
52}
53
55{
56 const auto& bppFS = *simplex_;
57 return typeid (bppFS).hash_code ();
58}
59
61{
62 auto m = ConfiguredParametrizable::createConfigured<Target, Self>(c, std::move (deps), std::unique_ptr<Target>(dynamic_cast<Target*>(simplex_->clone ())));
63 m->config = this->config; // Duplicate derivation config
64 return m;
65}
66
67/***********************************************************/
68
69// FrequenciesFromSimplex
70
73 : Value<Eigen::RowVectorXd>(std::move (deps)), targetDimension_ (dim) {}
74
76{
77 using namespace numeric;
78 return debug (this->accessValueConst ()) + " targetDim=" + to_string (targetDimension_);
79}
80
81// FrequenciesFromSimplex additional arguments = ().
83{
84 return dynamic_cast<const Self*>(&other) != nullptr;
85}
86
88{
89 // d(equFreqs)/dn = sum_i d(equFreqs)/dx_i * dx_i/dn (x_i = simplex parameters)
90 auto simplexDep = this->dependency (0);
91 auto& simplex = static_cast<ConfiguredSimplex&>(*simplexDep);
92 auto buildFWithNewSimplex = [this, &c](NodeRef&& newSimplex) {
93 return ConfiguredParametrizable::createRowVector<ConfiguredSimplex, Self>(c, {std::move (newSimplex)}, targetDimension_);
94 };
95
96 NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<ConfiguredSimplex, T >(
97 c, simplex, node, targetDimension_, buildFWithNewSimplex);
98
99 return CWiseAdd<T, ReductionOf<T>>::create (c, std::move (derivativeSumDeps), targetDimension_);
100}
101
103{
104 return ConfiguredParametrizable::createRowVector<ConfiguredSimplex, Self>(c, std::move (deps), targetDimension_);
105}
106
108{
109 const auto* simplex = accessValueConstCast<const Simplex*>(*this->dependency (0));
110 const auto& freqsFromFS = simplex->getFrequencies ();
111 auto& r = this->accessValueMutable ();
112 r = Eigen::Map<const T>(freqsFromFS.data(), static_cast<Eigen::Index>(freqsFromFS.size ()));
113}
114} // namespace bpp
virtual void shareParameter_(const std::shared_ptr< Parameter > &parameter)
Data flow node representing a Frequencies Set configured with parameter values.
Definition: Simplex_DF.h:37
std::string description() const final
Node pretty name (default = type name).
Definition: Simplex_DF.cpp:29
std::unique_ptr< Simplex > simplex_
Definition: Simplex_DF.h:82
bool compareAdditionalArguments(const Node_DF &other) const
Compare node-specific configuration to another.
Definition: Simplex_DF.cpp:39
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Simplex_DF.cpp:31
NumericalDerivativeConfiguration config
Configuration for numerical derivation of computation nodes using this Simplex.
Definition: Simplex_DF.h:66
std::size_t hashAdditionalArguments() const
Return the hash of node-specific configuration.
Definition: Simplex_DF.cpp:54
ConfiguredSimplex(const Context &context, NodeRefVec &&deps, std::unique_ptr< Simplex > &&simplex)
Definition: Simplex_DF.cpp:16
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Simplex_DF.cpp:60
Context for dataflow node construction.
Definition: DataFlow.h:527
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Definition: Simplex_DF.cpp:87
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps)
void compute() final
Computation implementation.
Definition: Simplex_DF.cpp:107
FrequenciesFromSimplex(NodeRefVec &&deps, const Dimension< T > &dim)
Definition: Simplex_DF.cpp:71
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
Definition: Simplex_DF.cpp:82
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Simplex_DF.cpp:102
Dimension< T > targetDimension_
Definition: Simplex_DF.h:116
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Simplex_DF.cpp:75
Base dataflow Node class.
Definition: DataFlow.h:152
const NodeRefVec & dependencies() const noexcept
Definition: DataFlow.h:183
const NodeRef & dependency(std::size_t i) const noexcept
Definition: DataFlow.h:185
Abstract Node storing a value of type T.
Definition: DataFlow.h:352
Eigen::RowVectorXd & accessValueMutable() noexcept
Definition: DataFlow.h:416
const Eigen::RowVectorXd & accessValueConst() const noexcept
Raw value access (const).
Definition: DataFlow.h:385
std::string debug(const T &t, typename std::enable_if< std::is_arithmetic< T >::value >::type *=0)
Defines the basic types of data flow nodes.
std::string to_string(const NoDimension &)
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.