bpp-phyl3  3.0.0
bpp::ConfiguredModel Class Reference

Likelihood transition model. More...

#include <Bpp/Phyl/Likelihood/DataFlow/Model.h>

+ Inheritance diagram for bpp::ConfiguredModel:
+ Collaboration diagram for bpp::ConfiguredModel:

Public Types

using Self = ConfiguredModel
 
using Target = BranchModelInterface
 

Public Member Functions

 ConfiguredModel (Context &context, NodeRefVec &&deps, std::shared_ptr< BranchModelInterface > &&model)
 
virtual ~ConfiguredModel ()
 
ConfiguredModelclone () const override
 
std::string description () const final
 Node pretty name (default = type name). More...
 
std::string debugInfo () const final
 Node debug info (default = ""): user defined detailed info for DF graph debug. More...
 
std::string color () const final
 
bool compareAdditionalArguments (const Node_DF &other) const override
 Compare node-specific configuration to another. More...
 
std::size_t hashAdditionalArguments () const override
 Return the hash of node-specific configuration. More...
 
NodeRef recreate (Context &c, NodeRefVec &&deps) final
 Recreate the node with different dependencies. More...
 
const ConfiguredParametergetConfiguredParameter (const std::string &name) const
 
const std::shared_ptr< BranchModelInterface > & targetValue ()
 Access value, recompute if needed. More...
 
const std::shared_ptr< BranchModelInterface > & accessValueConst () const noexcept
 Raw value access (const). More...
 
ValueRef< std::shared_ptr< BranchModelInterface > > deriveAsValue (Context &c, const Node_DF &node)
 
void modify (Callable &&modifier, bool makeValid)
 General case for modification of the T object. More...
 
bool isValid () const noexcept
 
std::size_t nbDependentNodes () const noexcept
 Number of dependent nodes (ie nodes that depend on this) More...
 
const std::vector< Node_DF * > & dependentNodes () const noexcept
 
std::size_t nbDependencies () const noexcept
 Number of dependencies (ie nodes we depend on) More...
 
const NodeRefVecdependencies () const noexcept
 
const NodeRefdependency (std::size_t i) const noexcept
 
virtual std::string shape () const
 
virtual bool hasNumericalProperty (NumericalProperty prop) const
 Test if the node has the given numerical property. More...
 
virtual NodeRef derive (Context &c, const Node_DF &node)
 Returns a node computing d(this_node_expression)/d(node_expression). More...
 
void computeRecursively ()
 Compute this node value, recomputing dependencies (transitively) as needed. More...
 
bool hasParameter (const std::string &name) const override
 
const ParameterListgetParameters () const override
 
const Parameterparameter (const std::string &name) const override
 
const std::shared_ptr< Parameter > & getParameter (const std::string &name) const
 
double getParameterValue (const std::string &name) const override
 
void setAllParametersValues (const ParameterList &parameters) override
 
void setParameterValue (const std::string &name, double value) override
 
void setParametersValues (const ParameterList &parameters) override
 
bool matchParametersValues (const ParameterList &parameters) override
 
void removeConstraint (const std::string &name) override
 
void setConstraint (const std::string &name, std::shared_ptr< ConstraintInterface > constraint) override
 
size_t getNumberOfParameters () const override
 
void setNamespace (const std::string &prefix) override
 
std::string getNamespace () const override
 
std::string getParameterNameWithoutNamespace (const std::string &name) const override
 
virtual void fireParameterChanged (const ParameterList &parameters)
 

Public Attributes

NumericalDerivativeConfiguration config
 Configuration for numerical derivation of computation nodes using this Model. More...
 

Protected Member Functions

std::shared_ptr< BranchModelInterface > & accessValueMutable () noexcept
 
void invalidateRecursively () noexcept
 Invalidate (transitively) dependent nodes from this one. More...
 
void makeInvalid () noexcept
 
void makeValid () noexcept
 
void resetDependencies_ (NodeRefVec &&dependenciesArg)
 
const std::shared_ptr< Parameter > & getParameter (size_t i) const
 
std::shared_ptr< Parameter > & getParameter (size_t i)
 
virtual void addParameter_ (Parameter *parameter)
 
virtual void addParameters_ (const ParameterList &parameters)
 
virtual void shareParameter_ (const std::shared_ptr< Parameter > &parameter)
 
virtual void shareParameters_ (const ParameterList &parameters)
 
virtual void includeParameters_ (const ParameterList &parameters)
 
virtual void deleteParameter_ (size_t index)
 
virtual void deleteParameter_ (std::string &name)
 
virtual void deleteParameters_ (const std::vector< std::string > &names)
 
void resetParameters_ ()
 
ParametergetParameter_ (const std::string &name)
 
ParametergetParameter_ (size_t index)
 
const ParametergetParameter_ (size_t index) const
 
ParametergetParameterWithNamespace_ (const std::string &name)
 
const ParametergetParameterWithNamespace_ (const std::string &name) const
 
ParameterListgetParameters_ () override
 

Private Member Functions

void compute () override
 Computation implementation. More...
 
void registerNode (Node_DF *n)
 
void unregisterNode (const Node_DF *n)
 

Private Attributes

std::shared_ptr< BranchModelInterfacemodel_
 
std::shared_ptr< BranchModelInterfacevalue_
 
NodeRefVec dependencyNodes_ {}
 
std::vector< Node_DF * > dependentNodes_ {}
 
bool isValid_ {false}
 
ParameterList parameters_
 
std::string prefix_
 

Detailed Description

Likelihood transition model.

Data flow node representing a Model configured with parameter values.

This class wraps a bpp::TransitionModel as a data flow node. It depends on Value<double> nodes (one for each parameter declared in the model). It provides a dummy value representing the "model configured by its parameters". This dummy value is then used by other node types to compute equilibrium frequencies, transition matrices and their derivatives.

The dummy value is implemented as a pointer to the internal model for simplicity.

Definition at line 45 of file Model.h.

Member Typedef Documentation

◆ Self

Definition at line 53 of file Model.h.

◆ Target

Definition at line 54 of file Model.h.

Constructor & Destructor Documentation

◆ ConfiguredModel()

ConfiguredModel::ConfiguredModel ( Context context,
NodeRefVec &&  deps,
std::shared_ptr< BranchModelInterface > &&  model 
)

◆ ~ConfiguredModel()

ConfiguredModel::~ConfiguredModel ( )
virtualdefault

Member Function Documentation

◆ accessValueConst()

const std::shared_ptr< BranchModelInterface > & bpp::Value< std::shared_ptr< BranchModelInterface > >::accessValueConst ( ) const
inlinenoexceptinherited

Raw value access (const).

Value is not guaranteed to be valid (no recomputation).

Definition at line 385 of file DataFlow.h.

◆ accessValueMutable()

std::shared_ptr< BranchModelInterface > & bpp::Value< std::shared_ptr< BranchModelInterface > >::accessValueMutable ( )
inlineprotectednoexceptinherited

Raw value access (mutable). Should only be used by subclasses to implement compute().

Definition at line 416 of file DataFlow.h.

◆ clone()

ConfiguredModel* bpp::ConfiguredModel::clone ( ) const
inlineoverridevirtual

Implements bpp::AbstractParametrizable.

Definition at line 59 of file Model.h.

◆ color()

std::string bpp::ConfiguredModel::color ( ) const
inlinefinalvirtual

Reimplemented from bpp::Node_DF.

Definition at line 67 of file Model.h.

◆ compareAdditionalArguments()

bool ConfiguredModel::compareAdditionalArguments ( const Node_DF other) const
overridevirtual

Compare node-specific configuration to another.

Required by Context for merging. It must compare everything in the node configuration except its type and dependencies. See DataFlowNumeric for examples. The default returns false, so nodes are considered different and not merged.

Reimplemented from bpp::Node_DF.

Definition at line 43 of file Model.cpp.

References model_.

◆ compute()

void bpp::ConfiguredModel::compute ( )
inlineoverrideprivatevirtual

Computation implementation.

This functions is defined by derived classes. It should compute the new node value from dependency node values. When called, dependency node are guaranteed to have valid values.

This function is private to prevent use for invalid dependencies. Higher level functions like computeRecursively call it while ensuring dependency validity.

Compute has access to dependencies as a NodeRefVec (base Node_DF classes only). The recommended usage is to check dependency types at Node construction. Then use static_cast to access derived classes efficiently from the NodeRefVec. See DataFlowNumeric.h for examples.

Implements bpp::Node_DF.

Definition at line 87 of file Model.h.

References bpp::AbstractParametrizable::getParameters(), and model_.

◆ computeRecursively()

void bpp::Node_DF::computeRecursively ( )
inherited

Compute this node value, recomputing dependencies (transitively) as needed.

Not thread safe !

Definition at line 183 of file DataFlow.cpp.

References bpp::Node_DF::isValid().

Referenced by bpp::Value< T >::targetValue().

◆ debugInfo()

std::string ConfiguredModel::debugInfo ( ) const
finalvirtual

Node debug info (default = ""): user defined detailed info for DF graph debug.

Reimplemented from bpp::Node_DF.

Definition at line 36 of file Model.cpp.

References model_, and bpp::to_string().

◆ dependencies()

◆ dependency()

const NodeRef& bpp::Node_DF::dependency ( std::size_t  i) const
inlinenoexceptinherited

Definition at line 185 of file DataFlow.h.

References bpp::Node_DF::dependencyNodes_.

Referenced by bpp::BackwardHmmLikelihood_DF::BackwardHmmLikelihood_DF(), bpp::ForwardHmmLikelihood_DF::build(), bpp::ValueFromConfiguredParameter::color(), bpp::CWiseFill< R, T >::compute(), bpp::CWiseApply< R, T, F >::compute(), bpp::CWiseAdd< R, std::tuple< T0, T1 > >::compute(), bpp::CWiseAdd< R, T >::compute(), bpp::CWiseMul< R, std::tuple< T0, T1 > >::compute(), bpp::CWiseDiv< R, std::tuple< T0, T1 > >::compute(), bpp::SumOfLogarithms< F >::compute(), bpp::CombineDeltaShifted< T >::compute(), bpp::CWiseSub< R, std::tuple< T0, T1 > >::compute(), bpp::CWiseMean< R, ReductionOf< T >, ReductionOf< P > >::compute(), bpp::CWiseMean< R, ReductionOf< T >, P >::compute(), bpp::CWiseNegate< T >::compute(), bpp::CWiseInverse< T >::compute(), bpp::CWiseLog< T >::compute(), bpp::CWiseExp< T >::compute(), bpp::CWiseConstantPow< T >::compute(), bpp::ScalarProduct< R, T0, T1 >::compute(), bpp::LogSumExp< R, T0, T1 >::compute(), bpp::MatrixProduct< R, T0, T1 >::compute(), bpp::ShiftDelta< T >::compute(), bpp::Convert< R, F >::compute(), bpp::Identity< R >::compute(), bpp::ProbabilitiesFromDiscreteDistribution::compute(), bpp::ProbabilityFromDiscreteDistribution::compute(), bpp::CategoryFromDiscreteDistribution::compute(), bpp::FrequenciesFromFrequencySet::compute(), bpp::EquilibriumFrequenciesFromModel::compute(), bpp::TransitionMatrixFromModel::compute(), bpp::TransitionFunctionFromModel::compute(), bpp::ProbabilitiesFromMixedModel::compute(), bpp::ProbabilityFromMixedModel::compute(), bpp::ShiftParameter::compute(), bpp::ValueFromConfiguredParameter::compute(), bpp::FrequenciesFromSimplex::compute(), bpp::EquilibriumFrequenciesFromTransitionMatrix::compute(), bpp::TransitionMatrixFromTransitionMatrix::compute(), bpp::CWisePattern< R >::compute(), bpp::CWiseMatching< R, ReductionOf< T > >::compute(), bpp::CWiseCompound< R, ReductionOf< T > >::compute(), bpp::ConfiguredParameter::compute(), bpp::CombineDeltaShifted< T >::create(), bpp::TransitionMatrixFromModel::debugInfo(), bpp::TransitionFunctionFromModel::debugInfo(), bpp::ValueFromConfiguredParameter::debugInfo(), bpp::CondLikelihood::debugInfo(), bpp::CWiseFill< R, T >::derive(), bpp::CWisePattern< R >::derive(), bpp::CWiseMatching< R, ReductionOf< T > >::derive(), bpp::CWiseCompound< R, ReductionOf< T > >::derive(), bpp::CWiseApply< R, T, F >::derive(), bpp::CWiseAdd< R, std::tuple< T0, T1 > >::derive(), bpp::CWiseSub< R, std::tuple< T0, T1 > >::derive(), bpp::CWiseAdd< R, ReductionOf< T > >::derive(), bpp::CWiseAdd< R, T >::derive(), bpp::CWiseMean< R, ReductionOf< T >, ReductionOf< P > >::derive(), bpp::CWiseMean< R, ReductionOf< T >, P >::derive(), bpp::CWiseMul< R, std::tuple< T0, T1 > >::derive(), bpp::CWiseMul< R, ReductionOf< T > >::derive(), bpp::CWiseDiv< R, std::tuple< T0, T1 > >::derive(), bpp::CWiseNegate< T >::derive(), bpp::CWiseInverse< T >::derive(), bpp::CWiseLog< T >::derive(), bpp::CWiseExp< T >::derive(), bpp::CWiseConstantPow< T >::derive(), bpp::ScalarProduct< R, T0, T1 >::derive(), bpp::SumOfLogarithms< F >::derive(), bpp::LogSumExp< R, T0, T1 >::derive(), bpp::MatrixProduct< R, T0, T1 >::derive(), bpp::ShiftDelta< T >::derive(), bpp::CombineDeltaShifted< T >::derive(), bpp::Convert< R, F >::derive(), bpp::Identity< R >::derive(), bpp::ProbabilitiesFromDiscreteDistribution::derive(), bpp::ProbabilityFromDiscreteDistribution::derive(), bpp::CategoryFromDiscreteDistribution::derive(), bpp::FrequenciesFromFrequencySet::derive(), bpp::EquilibriumFrequenciesFromModel::derive(), bpp::TransitionMatrixFromModel::derive(), bpp::TransitionFunctionFromModel::derive(), bpp::ProbabilitiesFromMixedModel::derive(), bpp::ProbabilityFromMixedModel::derive(), bpp::ShiftParameter::derive(), bpp::ValueFromConfiguredParameter::derive(), bpp::FrequenciesFromSimplex::derive(), bpp::EquilibriumFrequenciesFromTransitionMatrix::derive(), bpp::TransitionMatrixFromTransitionMatrix::derive(), bpp::BackwardHmmLikelihood_DF::derive(), bpp::ConfiguredParameter::derive(), bpp::ValueFromConfiguredParameter::description(), bpp::ConfiguredParameter::getValue(), bpp::ConfiguredParameter::recreate(), bpp::ConfiguredParameter::setValue(), and bpp::writeDotEdge().

◆ dependentNodes()

const std::vector<Node_DF*>& bpp::Node_DF::dependentNodes ( ) const
inlinenoexceptinherited

Definition at line 175 of file DataFlow.h.

References bpp::Node_DF::dependentNodes_.

◆ derive()

NodeRef bpp::Node_DF::derive ( Context c,
const Node_DF node 
)
virtualinherited

Returns a node computing d(this_node_expression)/d(node_expression).

The expression represented by 'node' is considered as a variable. Event if 'node' is a constant value node, d(node)/d(node) == 1. The derivative of a matrix is the matrix of the derivatives. Derivation is undefined by default, and this function will throw an exception. Implementations will usually recursively derive sub-expressions and combine them.

Reimplemented in bpp::ConfiguredParameter, bpp::BackwardHmmLikelihood_DF, bpp::ForwardHmmD2Likelihood_DF, bpp::ForwardHmmDLikelihood_DF, bpp::ForwardHmmLikelihood_DF, bpp::CondLikelihood, bpp::TransitionMatrixFromTransitionMatrix, bpp::EquilibriumFrequenciesFromTransitionMatrix, bpp::FrequenciesFromSimplex, bpp::Sequence_DF, bpp::ValueFromConfiguredParameter, bpp::ShiftParameter, bpp::ProbabilityFromMixedModel, bpp::ProbabilitiesFromMixedModel, bpp::TransitionFunctionFromModel, bpp::TransitionMatrixFromModel, bpp::EquilibriumFrequenciesFromModel, bpp::FrequenciesFromFrequencySet, bpp::CategoryFromDiscreteDistribution, bpp::ProbabilityFromDiscreteDistribution, bpp::ProbabilitiesFromDiscreteDistribution, bpp::Identity< R >, bpp::Convert< R, F >, bpp::NumericMutable< T >, bpp::NumericConstant< T >, bpp::ConstantOne< T >, bpp::ConstantZero< T >, bpp::CombineDeltaShifted< T >, bpp::ShiftDelta< T >, bpp::MatrixProduct< R, T0, T1 >, bpp::LogSumExp< R, T0, T1 >, bpp::SumOfLogarithms< F >, bpp::ScalarProduct< R, T0, T1 >, bpp::CWiseConstantPow< T >, bpp::CWiseExp< T >, bpp::CWiseLog< T >, bpp::CWiseInverse< T >, bpp::CWiseNegate< T >, bpp::CWiseDiv< R, std::tuple< T0, T1 > >, bpp::CWiseMul< R, ReductionOf< T > >, bpp::CWiseMul< R, std::tuple< T0, T1 > >, bpp::CWiseMean< R, ReductionOf< T >, P >, bpp::CWiseMean< R, ReductionOf< T >, ReductionOf< P > >, bpp::CWiseAdd< R, T >, bpp::CWiseAdd< R, ReductionOf< T > >, bpp::CWiseSub< R, std::tuple< T0, T1 > >, bpp::CWiseAdd< R, std::tuple< T0, T1 > >, bpp::CWiseApply< R, T, F >, bpp::CWiseCompound< R, ReductionOf< T > >, bpp::CWiseMatching< R, ReductionOf< T > >, bpp::CWisePattern< R >, and bpp::CWiseFill< R, T >.

Definition at line 173 of file DataFlow.cpp.

References bpp::Node_DF::description().

Referenced by bpp::Value< T >::deriveAsValue().

◆ deriveAsValue()

ValueRef<std::shared_ptr< BranchModelInterface > > bpp::Value< std::shared_ptr< BranchModelInterface > >::deriveAsValue ( Context c,
const Node_DF node 
)
inlineinherited

Derive and cast result as Value<T> (most nodes derive to the same value type).

Definition at line 389 of file DataFlow.h.

◆ description()

std::string ConfiguredModel::description ( ) const
finalvirtual

Node pretty name (default = type name).

Reimplemented from bpp::Node_DF.

Definition at line 34 of file Model.cpp.

References model_.

◆ getConfiguredParameter()

const ConfiguredParameter& bpp::ConfiguredModel::getConfiguredParameter ( const std::string &  name) const
inline

Definition at line 81 of file Model.h.

References bpp::AbstractParametrizable::parameter().

◆ hashAdditionalArguments()

std::size_t ConfiguredModel::hashAdditionalArguments ( ) const
overridevirtual

Return the hash of node-specific configuration.

Compute a hash from additional arguments of the node. The hashed values must the same as the ones compared by compareAdditionalArguments. The default returns 0, which is ok if there are no additional arguments.

Reimplemented from bpp::Node_DF.

Definition at line 58 of file Model.cpp.

References model_.

◆ hasNumericalProperty()

bool bpp::Node_DF::hasNumericalProperty ( NumericalProperty  prop) const
virtualinherited

Test if the node has the given numerical property.

This is an optional indication only, used for optimisations. If unsure, leave it to always false (the default implementation). This should be non recursive, to ensure a constant time check.

Reimplemented in bpp::NumericConstant< T >, bpp::ConstantOne< T >, and bpp::ConstantZero< T >.

Definition at line 168 of file DataFlow.cpp.

Referenced by bpp::ScalarProduct< R, T0, T1 >::create(), bpp::CWisePattern< R >::create(), bpp::CWiseAdd< R, T >::create(), bpp::CWiseMean< R, ReductionOf< T >, ReductionOf< P > >::create(), bpp::CWiseDiv< R, std::tuple< T0, T1 > >::create(), bpp::CWiseNegate< T >::create(), bpp::CWiseInverse< T >::create(), bpp::CWiseLog< T >::create(), bpp::CWiseExp< T >::create(), bpp::CWiseConstantPow< T >::create(), and bpp::CombineDeltaShifted< T >::create().

◆ invalidateRecursively()

void bpp::Node_DF::invalidateRecursively ( )
protectednoexceptinherited

Invalidate (transitively) dependent nodes from this one.

Not thread safe !

Definition at line 219 of file DataFlow.cpp.

References bpp::Node_DF::isValid().

Referenced by bpp::Value< T >::modify(), and bpp::Node_DF::resetDependencies_().

◆ isValid()

bool bpp::Node_DF::isValid ( ) const
inlinenoexceptinherited

◆ makeInvalid()

void bpp::Node_DF::makeInvalid ( )
inlineprotectednoexceptinherited

Definition at line 270 of file DataFlow.h.

References bpp::Node_DF::isValid_.

Referenced by bpp::Node_DF::resetDependencies_().

◆ makeValid()

void bpp::Node_DF::makeValid ( )
inlineprotectednoexceptinherited

◆ modify()

void bpp::Value< std::shared_ptr< BranchModelInterface > >::modify ( Callable &&  modifier,
bool  makeValid 
)
inlineinherited

General case for modification of the T object.

Takes a callable object (lambda, function pointer) that performs the modification. It must take a single T& as argument, which will refer to the T object to modify. The callable is called exactly once.

Parameters
modifiercallable to modify this object
makeValidboolean if this object is valid after modification (which means no call to this->compute()

Definition at line 405 of file DataFlow.h.

◆ nbDependencies()

◆ nbDependentNodes()

std::size_t bpp::Node_DF::nbDependentNodes ( ) const
inlinenoexceptinherited

Number of dependent nodes (ie nodes that depend on this)

Definition at line 172 of file DataFlow.h.

References bpp::Node_DF::dependentNodes_.

◆ recreate()

NodeRef ConfiguredModel::recreate ( Context c,
NodeRefVec &&  deps 
)
finalvirtual

Recreate the node with different dependencies.

Reimplemented from bpp::Node_DF.

Definition at line 64 of file Model.cpp.

References config, and model_.

◆ registerNode()

void bpp::Node_DF::registerNode ( Node_DF n)
privateinherited

Definition at line 240 of file DataFlow.cpp.

References bpp::Node_DF::dependentNodes_.

◆ resetDependencies_()

void bpp::Node_DF::resetDependencies_ ( NodeRefVec &&  dependenciesArg)
inlineprotectedinherited

◆ shape()

◆ targetValue()

const std::shared_ptr< BranchModelInterface > & bpp::Value< std::shared_ptr< BranchModelInterface > >::targetValue ( )
inlineinherited

Access value, recompute if needed.

Recompute the value if it is not up to date. Then access it as const. Recomputation is single threaded and not thread safe.

Definition at line 374 of file DataFlow.h.

◆ unregisterNode()

void bpp::Node_DF::unregisterNode ( const Node_DF n)
privateinherited

Definition at line 245 of file DataFlow.cpp.

References bpp::Node_DF::dependentNodes_.

Member Data Documentation

◆ config

NumericalDerivativeConfiguration bpp::ConfiguredModel::config

Configuration for numerical derivation of computation nodes using this Model.

Definition at line 77 of file Model.h.

Referenced by recreate().

◆ dependencyNodes_

◆ dependentNodes_

std::vector<Node_DF*> bpp::Node_DF::dependentNodes_ {}
privateinherited

◆ isValid_

bool bpp::Node_DF::isValid_ {false}
privateinherited

◆ model_

std::shared_ptr<BranchModelInterface> bpp::ConfiguredModel::model_
private

◆ value_

std::shared_ptr< BranchModelInterface > bpp::Value< std::shared_ptr< BranchModelInterface > >::value_
privateinherited

Definition at line 419 of file DataFlow.h.


The documentation for this class was generated from the following files: