bpp-phyl3  3.0.0
Model.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>
9 
10 
11 using namespace std;
12 using namespace bpp;
13 
14 // Model node
15 
16 ConfiguredModel::ConfiguredModel(
17  Context& context,
18  NodeRefVec&& deps,
19  shared_ptr<BranchModelInterface>&& model) :
20  Value<std::shared_ptr<BranchModelInterface>>(
21  std::move(deps),
22  model),
23  AbstractParametrizable(model->getNamespace()), // , context_(context)
24  model_(model)
25 {
26  for (const auto& dep : dependencies())
27  {
28  shareParameter_(std::dynamic_pointer_cast<ConfiguredParameter>(dep));
29  }
30 }
31 
33 
34 std::string ConfiguredModel::description () const { return "Model(" + model_->getName () + ")"; }
35 
36 std::string ConfiguredModel::debugInfo () const
37 {
38  return "nbState=" + std::to_string (model_->getAlphabet ()->getSize ());
39 }
40 
41 // Model node additional arguments = (type of BranchModel).
42 // Everything else is determined by the node dependencies.
44 {
45  const auto* derived = dynamic_cast<const Self*>(&other);
46  if (derived == nullptr)
47  {
48  return false;
49  }
50  else
51  {
52  const auto& thisModel = *model_;
53  const auto& otherModel = *derived->model_;
54  return typeid (thisModel) == typeid (otherModel);
55  }
56 }
57 
59 {
60  const auto& bppModel = *model_;
61  return typeid (bppModel).hash_code ();
62 }
63 
65 {
66  auto m = ConfiguredParametrizable::createConfigured<Target, Self>(c, std::move (deps), std::unique_ptr<Target>{dynamic_cast<Target*>(model_->clone ())});
67  m->config = this->config; // Duplicate derivation config
68  return m;
69 }
70 
71 // EquilibriumFrequenciesFromModel
72 
74  NodeRefVec&& deps, const Dimension<Eigen::RowVectorXd>& dim)
75  : Value<Eigen::RowVectorXd>(std::move (deps)), targetDimension_ (dim)
76 {}
77 
79 {
80  using namespace numeric;
81  return debug (this->accessValueConst ()) + " targetDim=" + to_string (targetDimension_);
82 }
83 
84 // EquilibriumFrequenciesFromModel additional arguments = ().
86 {
87  return dynamic_cast<const Self*>(&other) != nullptr;
88 }
89 
91 {
92  // d(equFreqs)/dn = sum_i d(equFreqs)/dx_i * dx_i/dn (x_i = model parameters)
93  auto modelDep = this->dependency (0);
94  auto& model = static_cast<Dep&>(*modelDep);
95  NodeRef subNode = this->nbDependencies() == 1 ? 0 : this->dependency (1);
96  auto buildFWithNewModel = [this, &c, &subNode](NodeRef&& newModel) {
97  return ConfiguredParametrizable::createRowVector<Dep, Self>(c, {std::move (newModel), subNode}, targetDimension_);
98  };
99 
100  NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<Dep, T>(
101  c, model, node, targetDimension_, buildFWithNewModel);
102  return CWiseAdd<T, ReductionOf<T>>::create (c, std::move (derivativeSumDeps), targetDimension_);
103 }
104 
106 {
107  return ConfiguredParametrizable::createRowVector<Dep, Self>(c, std::move (deps), targetDimension_);
108 }
109 
111 {
112  const Vdouble* freqsFromModel;
113  const auto* mixmodel = dynamic_cast<const MixedTransitionModelInterface*>(accessValueConstCast<const BranchModelInterface*>(*this->dependency (0)));
114  if (mixmodel && nbDependencies() > 1 && dependency(1))
115  {
116  auto nMod = accessValueConstCast<size_t>(*this->dependency(1));
117  freqsFromModel = &mixmodel->nModel(nMod).getFrequencies();
118  }
119  else
120  {
121  const auto pmodel = dynamic_cast<const TransitionModelInterface*>(accessValueConstCast<const BranchModelInterface*>(*this->dependency (0)));
122  if (pmodel)
123  freqsFromModel = &pmodel->getFrequencies();
124  else
125  throw Exception("EquilibriumFrequenciesFromModel::compute only possible for Transition Models.");
126  }
127 
128  auto& r = this->accessValueMutable ();
129  r = Eigen::Map<const T>(freqsFromModel->data (), static_cast<Eigen::Index>(freqsFromModel->size ()));
130 }
131 
132 // TransitionMatrixFromModel
133 
135  const Dimension<Eigen::MatrixXd>& dim)
136  : Value<Eigen::MatrixXd>(std::move (deps)), targetDimension_ (dim)
137 {}
138 
140 {
141  using namespace numeric;
142  const auto nDeriv = accessValueConstCast<size_t>(*this->dependency (2));
143  auto ret = debug (this->accessValueConst ()) + " targetDim=" + to_string (targetDimension_) + ":nDeriv=" + TextTools::toString(nDeriv);
144  return ret;
145 }
146 
147 // TransitionMatrixFromModel additional arguments = ().
149 {
150  return dynamic_cast<const Self*>(&other) != nullptr;
151 }
152 
154 {
155  // dtm/dn = sum_i dtm/dx_i * dx_i/dn + dtm/dbrlen * dbrlen/dn (x_i = model parameters).
156  auto modelDep = this->dependency (0);
157  auto brlenDep = this->dependency (1);
158  NodeRef derivNode = this->dependency (2);
159  NodeRef subNode = nbDependencies() < 4 ? 0 : this->dependency (3);
160 
161  const auto nDeriv = accessValueConstCast<size_t>(*derivNode);
162 
163  // Model part
164  auto& model = static_cast<Dep&>(*modelDep);
165  auto buildFWithNewModel = [this, &c, &brlenDep, &derivNode, &subNode](NodeRef&& newModel) {
166  return ConfiguredParametrizable::createMatrix<Dep, Self>(c, {std::move (newModel), brlenDep, derivNode, subNode}, targetDimension_);
167  };
168  NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<Dep, T>(
169  c, model, node, targetDimension_, buildFWithNewModel);
170  // Brlen part, use specific node
171  auto dbrlen_dn = brlenDep->derive (c, node);
172  if (!dbrlen_dn->hasNumericalProperty (NumericalProperty::ConstantZero))
173  {
174  auto nDerivp = NumericConstant<size_t>::create(c, nDeriv + 1);
175 
176  auto df_dbrlen =
177  ConfiguredParametrizable::createMatrix<Dep, TransitionMatrixFromModel>(c, {modelDep, brlenDep, nDerivp, subNode}, targetDimension_);
178  derivativeSumDeps.emplace_back (CWiseMul<T, std::tuple<double, T>>::create (
179  c, {std::move (dbrlen_dn), std::move (df_dbrlen)}, targetDimension_));
180  }
181  return CWiseAdd<T, ReductionOf<T>>::create (c, std::move (derivativeSumDeps), targetDimension_);
182 }
183 
185 {
186  return ConfiguredParametrizable::createMatrix<Dep, Self>(c, std::move (deps), targetDimension_);
187 }
188 
190 {
191  const auto brlen = accessValueConstCast<double>(*this->dependency (1)->dependency(0));
192  const auto nDeriv = accessValueConstCast<size_t>(*this->dependency (2));
193 
194  auto& r = this->accessValueMutable ();
195 
196  const auto* model1 = accessValueConstCast<const BranchModelInterface*>(*this->dependency (0));
197 
198  const auto* mixmodel = dynamic_cast<const MixedTransitionModelInterface*>(accessValueConstCast<const BranchModelInterface*>(*this->dependency (0)));
199 
200 #ifdef DEBUG
201  std::cerr << "=== TransitionMatrixFromModel::compute === " << this << std::endl;
202  std::cerr << "brlen= " << brlen << std::endl;
203  std::cerr << "nDeriv=" << nDeriv << std::endl;
204  std::cerr << "model= " << model1 << " : " << model1->getName() << std::endl;
205  model1->getParameters().printParameters(std::cerr);
206  std::cerr << "=== end TransitionMatrixFromModel::compute === " << this << std::endl << std::endl;
207 #endif
208 
209  if (mixmodel && nbDependencies() >= 4 && this->dependency(3)) // in case there is a submodel
210  {
211  auto nMod = accessValueConstCast<size_t>(*this->dependency (3));
212 
213  switch (nDeriv)
214  {
215  case 0:
216  copyBppToEigen (mixmodel->nModel(nMod).getPij_t (brlen), r);
217  break;
218  case 1:
219  copyBppToEigen (mixmodel->nModel(nMod).getdPij_dt (brlen), r);
220  break;
221  case 2:
222  copyBppToEigen (mixmodel->nModel(nMod).getd2Pij_dt2 (brlen), r);
223  break;
224  default:
225  throw Exception("TransitionMatrixFromModel likelihood derivate " + TextTools::toString(nDeriv) + " not defined.");
226  }
227  }
228  else
229  {
230  const auto model = dynamic_cast<const TransitionModelInterface*>(model1);
231 
232  if (!model)
233  throw Exception("TransitionMatrixFromModel::compute only possible for Transition Models.");
234 
235  switch (nDeriv)
236  {
237  case 0:
238  copyBppToEigen (model->getPij_t (brlen), r);
239  break;
240  case 1:
241  copyBppToEigen (model->getdPij_dt (brlen), r);
242  break;
243  case 2:
244  copyBppToEigen (model->getd2Pij_dt2 (brlen), r);
245  break;
246  default:
247  throw Exception("TransitionMatrixFromModel likelihood derivate " + TextTools::toString(nDeriv) + " not defined.");
248  }
249  }
250 }
251 
253 // TransitionFunctionFromModel
254 
256  const Dimension<T>& dim)
257  : Value<TransitionFunction>(std::move (deps)), targetDimension_ (dim) {}
258 
260 {
261  using namespace numeric;
262  const auto nDeriv = accessValueConstCast<size_t>(*this->dependency (2));
263  auto ret = debug (this->accessValueConst ()) + " targetDim=" + to_string (targetDimension_) + ":nDeriv=" + TextTools::toString(nDeriv);
264  return ret;
265 }
266 
267 // TransitionFunctionFromModel additional arguments = ().
269 {
270  return dynamic_cast<const Self*>(&other) != nullptr;
271 }
272 
273 std::shared_ptr<TransitionFunctionFromModel> TransitionFunctionFromModel::create (Context& c, NodeRefVec&& deps, const Dimension<T>& dim)
274 {
275  checkDependenciesNotNull (typeid (Self), deps);
276  checkDependencyVectorSize (typeid (Self), deps, 3);
277  checkNthDependencyIs<ConfiguredModel>(typeid (Self), deps, 0);
278  checkNthDependencyIs<ConfiguredParameter>(typeid (Self), deps, 1);
279 // checkNthDependencyIs<size_t> (typeid (Self), deps, 2);
280 
281  return cachedAs<TransitionFunctionFromModel>(c, std::make_shared<TransitionFunctionFromModel>(std::move (deps), dim));
282 }
283 
285 {
286  // df(v)/dn = sum_i df(v)/dx_i * dx_i/dn + df(v)/dbrlen * dbrlen/dn + df(v)/dv * dv/dn (x_i = model parameters, v = variable of f).
287  if (&node == &NodeX)
288  throw Exception("TransitionFunctionFromModel::derive : Jacobian not implemented. Ask developers.");
289 
290  auto modelDep = this->dependency (0);
291  auto brlenDep = this->dependency (1);
292  NodeRef derivNode = this->dependency (2);
293  const auto nDeriv = accessValueConstCast<size_t>(*this->dependency (2));
294 
295  // Model part
296  auto& model = static_cast<Dep&>(*modelDep);
297  auto buildFWithNewModel = [this, &c, &brlenDep, &derivNode](NodeRef&& newModel) {
298  return TransitionFunctionFromModel::create(c, {std::move (newModel), brlenDep, derivNode}, targetDimension_);
299  };
300 
301  NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<Dep, T>(c, model, node, targetDimension_, buildFWithNewModel);
302 
303  // Brlen part, use specific node
304  auto dbrlen_dn = brlenDep->derive (c, node);
305  if (!dbrlen_dn->hasNumericalProperty (NumericalProperty::ConstantZero))
306  {
307  auto nDerivp = NumericConstant<size_t>::create(c, nDeriv + 1);
308  auto df_dbrlen = TransitionFunctionFromModel::create(c, {modelDep, brlenDep, nDerivp}, targetDimension_);
309  derivativeSumDeps.emplace_back (CWiseMul<T, std::tuple<double, T>>::create (
310  c, {std::move (dbrlen_dn), std::move (df_dbrlen)}, targetDimension_));
311  }
312 
313  // Vector part, use specific node
314 
315 
316  return CWiseAdd<T, ReductionOf<T>>::create (c, std::move (derivativeSumDeps), targetDimension_);
317 }
318 
320 {
321  return Self::create(c, std::move (deps), targetDimension_);
322 }
323 
325 {
326  const auto brlen = accessValueConstCast<double>(*this->dependency (1)->dependency(0));
327  const auto* model = accessValueConstCast<const BranchModelInterface*>(*this->dependency(0));
328  const auto nDeriv = accessValueConstCast<size_t>(*this->dependency (2));
329 
330  auto& r = this->accessValueMutable ();
331 
332  auto dimin = VectorDimension(Eigen::Dynamic); // ttargetDimension_;
333  auto dimout = Dimension<VectorLik>(Eigen::Dynamic, 1); // ttargetDimension_;
334 
335  r = [model, brlen, nDeriv, dimin, dimout](const VectorLik& values)
336  {
337  switch (nDeriv)
338  {
339  case 0:
340  return numeric::convert(model->Lik_t(numeric::convert<Eigen::Dynamic, 1>(values, dimin), brlen), dimout);
341  case 1:
342  return numeric::convert(model->dLik_dt(numeric::convert<Eigen::Dynamic, 1>(values, dimin), brlen), dimout);
343  case 2:
344  return numeric::convert(model->d2Lik_dt2(numeric::convert<Eigen::Dynamic, 1>(values, dimin), brlen), dimout);
345 // return numeric::convert<VectorLik, Eigen::VectorXd>(model->d2Lik_dt2(numeric::convert<Eigen::VectorXd, VectorLik>(values, dim), brlen), dim);
346  default:
347  throw Exception("TransitionFunctionFromModel likelihood derivate " + TextTools::toString(nDeriv) + " not defined.");
348  }
349  };
350 }
351 
352 
354 // ProbabilitiesFromMixedModel
355 
357  NodeRefVec&& deps, const Dimension<Eigen::RowVectorXd>& dim)
358  : Value<Eigen::RowVectorXd>(std::move (deps)), nbClass_ (dim) {}
359 
360 
362 {
363  using namespace numeric;
364  return debug (this->accessValueConst ()) + " nbClass=" + to_string (nbClass_);
365 }
366 
367 // ProbabilitiesFromMixedModel additional arguments = ().
369 {
370  return dynamic_cast<const Self*>(&other) != nullptr;
371 }
372 
374 {
375  // d(Prob)/dn = sum_i d(Prob)/dx_i * dx_i/dn (x_i = distrib parameters)
376  auto modelDep = this->dependency (0);
377  auto& model = static_cast<ConfiguredModel&>(*modelDep);
378  auto buildPWithNewModel = [this, &c](NodeRef&& newModel) {
379  return ConfiguredParametrizable::createRowVector<Dep, Self>(c, {std::move (newModel)}, nbClass_);
380  };
381 
382  NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<Dep, T >(
383  c, model, node, nbClass_, buildPWithNewModel);
384  return CWiseAdd<T, ReductionOf<T>>::create (c, std::move (derivativeSumDeps), nbClass_);
385 }
386 
388 {
389  return ConfiguredParametrizable::createRowVector<Dep, Self>(c, std::move (deps), nbClass_);
390 }
391 
393 {
394  const auto* mixmodel = dynamic_cast<const MixedTransitionModelInterface*>(accessValueConstCast<const BranchModelInterface*>(*this->dependency (0)));
395  const auto& probasFromModel = mixmodel->getProbabilities ();
396  auto& r = this->accessValueMutable ();
397  r = Eigen::Map<const T>(probasFromModel.data(), static_cast<Eigen::Index>(probasFromModel.size ()));
398 }
399 
400 std::shared_ptr<ProbabilitiesFromMixedModel> ProbabilitiesFromMixedModel::create(Context& c, NodeRefVec&& deps)
401 {
402  checkDependenciesNotNull (typeid (Self), deps);
403  checkDependencyVectorSize (typeid (Self), deps, 1);
404  checkNthDependencyIs<ConfiguredModel>(typeid (Self), deps, 0);
405  auto& model = static_cast<ConfiguredModel&>(*deps[0]);
406  auto& deps0 = *deps[0];
407  const auto mixmodel = dynamic_pointer_cast<const MixedTransitionModelInterface>(model.targetValue());
408  if (!mixmodel)
409  failureDependencyTypeMismatch(typeid(Self), 0, typeid(MixedTransitionModelInterface), typeid(deps0));
410 
411  size_t nbCat = mixmodel->getNumberOfModels();
412  return cachedAs<ProbabilitiesFromMixedModel>(c, make_shared<ProbabilitiesFromMixedModel>(std::move(deps), RowVectorDimension(Eigen::Index(nbCat))));
413 }
414 
415 
417 // ProbabilityFromMixedModel
418 
420  NodeRefVec&& deps, size_t nCat)
421  : Value<double>(std::move (deps)), nCat_ (nCat) {}
422 
423 
425 {
426  using namespace numeric;
427  return "proba=" + TextTools::toString(accessValueConst()) + ":nCat=" + TextTools::toString(nCat_);
428 }
429 
430 // ProbabilityFromMixedModel additional arguments = ().
432 {
433  const auto* derived = dynamic_cast<const Self*>(&other);
434  return derived != nullptr && nCat_ == derived->nCat_;
435 }
436 
437 std::shared_ptr<ProbabilityFromMixedModel> ProbabilityFromMixedModel::create(Context& c, NodeRefVec&& deps, size_t nCat)
438 {
439  checkDependenciesNotNull (typeid (Self), deps);
440  checkDependencyVectorSize (typeid (Self), deps, 1);
441  checkNthDependencyIs<ConfiguredModel>(typeid (Self), deps, 0);
442  auto& model = static_cast<ConfiguredModel&>(*deps[0]);
443  const auto& deps0 = *deps[0];
444  const auto mixmodel = dynamic_pointer_cast<const MixedTransitionModelInterface>(model.targetValue());
445  if (!mixmodel)
446  failureDependencyTypeMismatch (typeid(Self), 0, typeid(MixedTransitionModelInterface), typeid(deps0));
447 
448  return cachedAs<ProbabilityFromMixedModel>(c, std::make_shared<ProbabilityFromMixedModel>(std::move (deps), nCat));
449 }
450 
452 {
453  // d(Prob)/dn = sum_i d(Prob)/dx_i * dx_i/dn (x_i = distrib parameters)
454  auto modelDep = this->dependency (0);
455  auto& model = static_cast<Dep&>(*modelDep);
456  auto buildPWithNewModel = [this, &c](NodeRef&& newModel) {
457  return this->create (c, {std::move (newModel)}, nCat_);
458  };
459 
460  NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<Dep, T >(
461  c, model, node, 1, buildPWithNewModel);
462  return CWiseAdd<T, ReductionOf<T>>::create (c, std::move (derivativeSumDeps), 1);
463 }
464 
466 {
467  return ProbabilityFromMixedModel::create (c, {std::move (deps)}, nCat_);
468 }
469 
471 {
472  const auto* mixmodel = dynamic_cast<const MixedTransitionModelInterface*>(accessValueConstCast<const BranchModelInterface*>(*this->dependency (0)));
473  this->accessValueMutable () = mixmodel->getNProbability(nCat_);
474 }
virtual void shareParameter_(const std::shared_ptr< Parameter > &parameter)
Interface for all Branch models.
virtual std::string getName() const =0
Get the name of the model.
Likelihood transition model.
Definition: Model.h:48
virtual ~ConfiguredModel()
bool compareAdditionalArguments(const Node_DF &other) const override
Compare node-specific configuration to another.
Definition: Model.cpp:43
std::shared_ptr< BranchModelInterface > model_
Definition: Model.h:92
NumericalDerivativeConfiguration config
Configuration for numerical derivation of computation nodes using this Model.
Definition: Model.h:77
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Model.cpp:36
std::size_t hashAdditionalArguments() const override
Return the hash of node-specific configuration.
Definition: Model.cpp:58
std::string description() const final
Node pretty name (default = type name).
Definition: Model.cpp:34
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Model.cpp:64
Context for dataflow node construction.
Definition: DataFlow.h:527
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Model.cpp:105
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Definition: Model.cpp:90
EquilibriumFrequenciesFromModel(NodeRefVec &&deps, const Dimension< T > &dim)
Definition: Model.cpp:73
bool compareAdditionalArguments(const Node_DF &other) const
Compare node-specific configuration to another.
Definition: Model.cpp:85
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Model.cpp:78
void compute() final
Computation implementation.
Definition: Model.cpp:110
Interface for Transition models, defined as a mixture of "simple" transition models.
virtual const std::vector< double > & getProbabilities() const =0
Base dataflow Node class.
Definition: DataFlow.h:152
const NodeRef & dependency(std::size_t i) const noexcept
Definition: DataFlow.h:185
std::size_t nbDependencies() const noexcept
Number of dependencies (ie nodes we depend on)
Definition: DataFlow.h:181
const NodeRefVec & dependencies() const noexcept
Definition: DataFlow.h:183
static std::shared_ptr< Self > create(Context &c, Args &&... args)
Build a new NumericConstant node with T(args...) value.
ProbabilitiesFromMixedModel(NodeRefVec &&deps, const Dimension< T > &dim)
Definition: Model.cpp:356
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Model.cpp:361
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps)
Definition: Model.cpp:400
void compute() final
Computation implementation.
Definition: Model.cpp:392
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
Definition: Model.cpp:368
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Model.cpp:387
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Definition: Model.cpp:373
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Model.cpp:424
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Model.cpp:465
void compute() final
Computation implementation.
Definition: Model.cpp:470
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
Definition: Model.cpp:431
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Definition: Model.cpp:451
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps, size_t nCat)
Definition: Model.cpp:437
ProbabilityFromMixedModel(NodeRefVec &&deps, size_t nCat)
Definition: Model.cpp:419
TransitionFunctionFromModel(NodeRefVec &&deps, const Dimension< T > &dim)
Build a new TransitionMatrixFromModel node with the given output dimensions.
Definition: Model.cpp:255
Dimension< T > targetDimension_
Definition: Model.h:199
void compute() final
Computation implementation.
Definition: Model.cpp:324
bool compareAdditionalArguments(const Node_DF &other) const
Compare node-specific configuration to another.
Definition: Model.cpp:268
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Model.cpp:259
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps, const Dimension< T > &dim)
Definition: Model.cpp:273
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Definition: Model.cpp:284
bpp::TransitionFunction T
Definition: Model.h:196
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Model.cpp:319
TransitionMatrixFromModel(NodeRefVec &&deps, const Dimension< T > &dim)
Build a new TransitionMatrixFromModel node with the given output dimensions.
Definition: Model.cpp:134
Dimension< T > targetDimension_
Definition: Model.h:149
bool compareAdditionalArguments(const Node_DF &other) const
Compare node-specific configuration to another.
Definition: Model.cpp:148
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Definition: Model.cpp:139
void compute() final
Computation implementation.
Definition: Model.cpp:189
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Definition: Model.cpp:153
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Definition: Model.cpp:184
Interface for all transition models.
virtual const Vdouble & getFrequencies() const =0
Abstract Node storing a value of type T.
Definition: DataFlow.h:352
const Eigen::RowVectorXd & accessValueConst() const noexcept
Raw value access (const).
Definition: DataFlow.h:385
Eigen::RowVectorXd & accessValueMutable() noexcept
Definition: DataFlow.h:416
std::string toString(T t)
std::string debug(const T &t, typename std::enable_if< std::is_arithmetic< T >::value >::type *=0)
R convert(const F &from, const Dimension< R > &)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
NumericConstant< char > NodeX('X')
void checkDependenciesNotNull(const std::type_info &contextNodeType, const NodeRefVec &deps)
Checks that all dependencies are not null, throws if not.
Definition: DataFlow.cpp:103
std::string to_string(const NoDimension &)
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
Definition: DataFlow.h:81
template void copyBppToEigen(const std::vector< ExtendedFloat > &bppVector, Eigen::RowVectorXd &eigenVector)
void checkDependencyVectorSize(const std::type_info &contextNodeType, const NodeRefVec &deps, std::size_t expectedSize)
Definition: DataFlow.cpp:83
void failureDependencyTypeMismatch(const std::type_info &contextNodeType, std::size_t depIndex, const std::type_info &expectedType, const std::type_info &givenNodeType)
Definition: DataFlow.cpp:74
std::shared_ptr< Node_DF > NodeRef
Definition: DataFlow.h:78
std::function< VectorLik(const VectorLik &)> TransitionFunction
Store a dimension for type T.