5 #ifndef BPP_PHYL_LIKELIHOOD_PHYLOLIKELIHOODS_HMMLIKELIHOODCOMPUTATION_H
6 #define BPP_PHYL_LIKELIHOOD_PHYLOLIKELIHOODS_HMMLIKELIHOODCOMPUTATION_H
12 #include "../DataFlow/TransitionMatrix.h"
39 checkNthDependencyIsValue<std::string>(
typeid(
CondLikelihood), deps, 1);
41 return cachedAs<Value<Eigen::MatrixXd>>(c, std::make_shared<CondLikelihood>(std::move (deps), dim));
52 using namespace numeric;
53 const auto name = accessValueConstCast<std::string>(*this->
dependency (1));
68 throw Exception(
"CondLikelihood::derive is done in dependency class.");
156 checkNthDependencyIsValue<Eigen::VectorXd>(
typeid (
Self), deps, 0);
157 checkNthDependencyIsValue<Eigen::MatrixXd>(
typeid (
Self), deps, 1);
158 checkNthDependencyIsValue<MatrixLik>(
typeid (
Self), deps, 2);
160 auto sself = std::make_shared<Self>(std::move (deps), dim);
163 return cachedAs<Value<RowLik>>(c, sself);
169 for (
auto& v:parCondLik_)
183 const auto& hmmEq = dynamic_pointer_cast<Value<Eigen::VectorXd>>(this->
dependency(0))->
targetValue();
188 const auto& hmmTrans = dynamic_pointer_cast<Value<Eigen::MatrixXd>>(this->
dependency(1))->
targetValue();
190 if (hmmTrans.cols() != hmmTrans.rows())
191 throw BadSizeException(
"ForwardHmmLikelihood_DF: Transition matrix should be square",
size_t(hmmTrans.cols()),
size_t(hmmTrans.rows()));
205 using namespace numeric;
212 return dynamic_cast<const Self*
>(&other) !=
nullptr;
300 checkNthDependencyIsValue<Eigen::VectorXd>(
typeid (
Self), deps, 0);
301 checkNthDependencyIsValue<Eigen::MatrixXd>(
typeid (
Self), deps, 1);
302 checkNthDependencyIsValue<MatrixLik>(
typeid (
Self), deps, 2);
304 checkNthDependencyIs<ForwardHmmLikelihood_DF>(
typeid (
Self), deps, 3);
306 checkNthDependencyIsValue<Eigen::VectorXd>(
typeid (
Self), deps, 4);
307 checkNthDependencyIsValue<Eigen::MatrixXd>(
typeid (
Self), deps, 5);
308 checkNthDependencyIsValue<MatrixLik>(
typeid (
Self), deps, 6);
310 auto sself = std::make_shared<Self>(std::move (deps), dim);
313 return cachedAs<Value<RowLik>>(c, sself);
319 for (
auto& v:dParCondLik_)
335 using namespace numeric;
342 return dynamic_cast<const Self*
>(&other) !=
nullptr;
427 checkNthDependencyIsValue<Eigen::VectorXd>(
typeid (
Self), deps, 0);
428 checkNthDependencyIsValue<Eigen::MatrixXd>(
typeid (
Self), deps, 1);
429 checkNthDependencyIsValue<MatrixLik>(
typeid (
Self), deps, 2);
431 checkNthDependencyIs<ForwardHmmLikelihood_DF>(
typeid (
Self), deps, 3);
433 checkNthDependencyIsValue<Eigen::VectorXd>(
typeid (
Self), deps, 4);
434 checkNthDependencyIsValue<Eigen::MatrixXd>(
typeid (
Self), deps, 5);
435 checkNthDependencyIsValue<MatrixLik>(
typeid (
Self), deps, 6);
437 checkNthDependencyIs<ForwardHmmDLikelihood_DF>(
typeid (
Self), deps, 7);
439 checkNthDependencyIsValue<Eigen::VectorXd>(
typeid (
Self), deps, 8);
440 checkNthDependencyIsValue<Eigen::MatrixXd>(
typeid (
Self), deps, 9);
441 checkNthDependencyIsValue<MatrixLik>(
typeid (
Self), deps, 10);
443 auto sself = std::make_shared<Self>(std::move (deps), dim);
446 return cachedAs<Value<RowLik>>(c, sself);
464 using namespace numeric;
471 return dynamic_cast<const Self*
>(&other) !=
nullptr;
476 throw Exception(
"ForwardHmmD2Likelihood_DF::derive not implemented.");
535 checkNthDependencyIsValue<RowLik>(
typeid (
Self), deps, 0);
536 checkNthDependencyIsValue<Eigen::MatrixXd>(
typeid (
Self), deps, 1);
537 checkNthDependencyIsValue<MatrixLik>(
typeid (
Self), deps, 2);
539 return cachedAs<Value<Eigen::MatrixXd>>(c, std::make_shared<Self>(std::move (deps), dim));
547 const auto& hmmScale = accessValueConstCast<RowLik>(*this->
dependency(0));
548 if (hmmScale.cols() != dim.cols)
549 throw BadSizeException(
"BackwardHmmLikelihood_DF: bad dimension for forward likelihoods vector",
size_t(hmmScale.cols()),
size_t(dim.cols));
552 const auto& hmmTrans = accessValueConstCast<Eigen::MatrixXd>(*this->
dependency(1));
553 if (hmmTrans.cols() != dim.rows)
554 throw BadSizeException(
"BackwardHmmLikelihood_DF: bad size for transition matrix",
size_t(hmmTrans.cols()),
size_t(dim.rows));
556 const auto& hmmEmis = accessValueConstCast<MatrixLik>(*this->
dependency(2));
557 if (hmmEmis.rows() != dim.rows)
558 throw BadSizeException(
"BackwardHmmLikelihood_DF: bad number of states for emission matrix",
size_t(hmmEmis.rows()),
size_t(dim.rows));
559 if (hmmEmis.cols() != dim.cols)
560 throw BadSizeException(
"BackwardHmmLikelihood_DF: bad number of sites for emission matrix",
size_t(hmmEmis.cols()),
size_t(dim.cols));
565 using namespace numeric;
572 return dynamic_cast<const Self*
>(&other) !=
nullptr;
580 throw Exception(
"BackwardHmmLikelihood_DF::derive To be finished.");
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Dimension< Eigen::MatrixXd > targetDimension_
backward likelihood
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
static ValueRef< Eigen::MatrixXd > create(Context &c, NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
BackwardHmmLikelihood_DF(NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Dimension< Eigen::MatrixXd > targetDimension_
Dimension of the data : states X sites.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
friend class ForwardHmmDLikelihood_DF
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
static ValueRef< Eigen::MatrixXd > create(Context &c, NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
CondLikelihood(NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
Eigen::MatrixXd & getCondLikelihood()
void compute() override
Computation implementation.
friend class ForwardHmmLikelihood_DF
friend class ForwardHmmD2Likelihood_DF
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
const Eigen::MatrixXd & getCondLikelihood() const
Context for dataflow node construction.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
Dimension< Eigen::MatrixXd > targetDimension_
Dimension of the data : states X sites.
ValueRef< Eigen::MatrixXd > d2CondLik_
derivatives of the conditional forward likelihoods : Will be used by backward likelihoods computation...
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
static ValueRef< RowLik > create(Context &c, NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
ForwardHmmD2Likelihood_DF(NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
Dimension< Eigen::MatrixXd > targetDimension_
Dimension of the data : states X sites.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
const std::vector< Eigen::VectorXd > & getParDCondLik() const
std::vector< Eigen::VectorXd > dParCondLik_
ForwardHmmDLikelihood_DF(NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
std::string debugInfo() const override
Node debug info (default = ""): user defined detailed info for DF graph debug.
ValueRef< Eigen::MatrixXd > getForwardDCondLikelihood() const
static ValueRef< RowLik > create(Context &c, NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
ValueRef< Eigen::MatrixXd > dCondLik_
derivatives of the conditional forward likelihoods : Will be used by likelihoods computation of 2nd o...
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
ValueRef< Eigen::MatrixXd > getForwardCondLikelihood() const
Dimension< Eigen::MatrixXd > targetDimension_
const std::vector< Eigen::VectorXd > & getParCondLik() const
std::string debugInfo() const override
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.
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
std::vector< Eigen::VectorXd > parCondLik_
ValueRef< Eigen::MatrixXd > condLik_
static ValueRef< RowLik > create(Context &c, NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
ForwardHmmLikelihood_DF(NodeRefVec &&deps, const Dimension< Eigen::MatrixXd > &dim)
Base dataflow Node class.
const NodeRef & dependency(std::size_t i) const noexcept
static std::shared_ptr< Self > create(Context &c, Args &&... args)
Build a new NumericConstant node with T(args...) value.
Abstract Node storing a value of type T.
const Eigen::MatrixXd & accessValueConst() const noexcept
Raw value access (const).
const Eigen::MatrixXd & targetValue()
Access value, recompute if needed.
Eigen::MatrixXd & accessValueMutable() noexcept
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::shared_ptr< Value< T > > ValueRef
Shared pointer alias for Value<T>.
void checkDependenciesNotNull(const std::type_info &contextNodeType, const NodeRefVec &deps)
Checks that all dependencies are not null, throws if not.
std::string to_string(const NoDimension &)
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
void checkDependencyVectorSize(const std::type_info &contextNodeType, const NodeRefVec &deps, std::size_t expectedSize)
std::shared_ptr< Node_DF > NodeRef