bpp-phyl3  3.0.0
bpp::ConstantOne< T > Class Template Reference

r = 1 for each component. More...

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

+ Inheritance diagram for bpp::ConstantOne< T >:
+ Collaboration diagram for bpp::ConstantOne< T >:

Public Types

using Self = ConstantOne
 

Public Member Functions

 ConstantOne (const Dimension< T > &dim)
 
std::string debugInfo () const override
 Node debug info (default = ""): user defined detailed info for DF graph debug. More...
 
bool hasNumericalProperty (NumericalProperty prop) const final
 Test if the node has the given numerical property. More...
 
bool compareAdditionalArguments (const Node_DF &other) const final
 Compare node-specific configuration to another. More...
 
std::size_t hashAdditionalArguments () const final
 Return the hash of node-specific configuration. More...
 
NodeRef derive (Context &c, const Node_DF &node) final
 Returns a node computing d(this_node_expression)/d(node_expression). More...
 
NodeRef recreate (Context &, NodeRefVec &&deps) final
 Recreate the node with different dependencies. More...
 
const T & targetValue ()
 Access value, recompute if needed. More...
 
const T & accessValueConst () const noexcept
 Raw value access (const). More...
 
ValueRef< T > deriveAsValue (Context &c, const Node_DF &node)
 
template<typename Callable >
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 description () const
 Node pretty name (default = type name). More...
 
virtual std::string color () const
 
virtual std::string shape () const
 
void computeRecursively ()
 Compute this node value, recomputing dependencies (transitively) as needed. More...
 

Static Public Member Functions

static std::shared_ptr< Selfcreate (Context &c, const Dimension< T > &dim)
 Build a new ConstantOne node of the given dimension. More...
 

Protected Member Functions

T & accessValueMutable () noexcept
 
void invalidateRecursively () noexcept
 Invalidate (transitively) dependent nodes from this one. More...
 
void makeInvalid () noexcept
 
void makeValid () noexcept
 
void resetDependencies_ (NodeRefVec &&dependenciesArg)
 

Private Member Functions

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

Private Attributes

Dimension< T > targetDimension_
 
value_
 
NodeRefVec dependencyNodes_ {}
 
std::vector< Node_DF * > dependentNodes_ {}
 
bool isValid_ {false}
 

Detailed Description

template<typename T>
class bpp::ConstantOne< T >

r = 1 for each component.

  • r: T.

Node construction should be done with the create static method. Value is only created at first use (lazy).

Definition at line 1040 of file DataFlowNumeric.h.

Member Typedef Documentation

◆ Self

template<typename T >
using bpp::ConstantOne< T >::Self = ConstantOne

Definition at line 1043 of file DataFlowNumeric.h.

Constructor & Destructor Documentation

◆ ConstantOne()

template<typename T >
bpp::ConstantOne< T >::ConstantOne ( const Dimension< T > &  dim)
inlineexplicit

Definition at line 1051 of file DataFlowNumeric.h.

Member Function Documentation

◆ accessValueConst()

◆ accessValueMutable()

template<typename T >
T& bpp::Value< T >::accessValueMutable ( )
inlineprotectednoexceptinherited

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

Definition at line 416 of file DataFlow.h.

References bpp::Value< T >::value_.

Referenced by bpp::ConstantZero< T >::compute(), bpp::ConstantOne< T >::compute(), bpp::Convert< R, F >::compute(), bpp::Identity< R >::compute(), and bpp::Value< T >::modify().

◆ color()

◆ compareAdditionalArguments()

template<typename T >
bool bpp::ConstantOne< T >::compareAdditionalArguments ( const Node_DF other) const
inlinefinalvirtual

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 1069 of file DataFlowNumeric.h.

References bpp::ConstantZero< T >::targetDimension_.

◆ compute()

template<typename T >
void bpp::ConstantOne< T >::compute ( )
inlinefinalprivatevirtual

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 1092 of file DataFlowNumeric.h.

References bpp::Value< T >::accessValueMutable(), bpp::numeric::one(), and bpp::ConstantZero< T >::targetDimension_.

◆ 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().

◆ create()

template<typename T >
static std::shared_ptr<Self> bpp::ConstantOne< T >::create ( Context c,
const Dimension< T > &  dim 
)
inlinestatic

Build a new ConstantOne node of the given dimension.

Definition at line 1046 of file DataFlowNumeric.h.

Referenced by bpp::CWiseMul< R, std::tuple< T0, T1 > >::create(), bpp::CWiseMul< R, ReductionOf< T > >::create(), bpp::Convert< R, F >::create(), bpp::CWiseInverse< T >::create(), bpp::CWiseExp< T >::create(), 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::LogSumExp< R, T0, T1 >::derive(), bpp::MatrixProduct< R, T0, T1 >::derive(), bpp::ShiftDelta< T >::derive(), bpp::CombineDeltaShifted< T >::derive(), bpp::ConstantZero< T >::derive(), bpp::ConstantOne< T >::derive(), bpp::NumericConstant< T >::derive(), bpp::NumericMutable< T >::derive(), bpp::Convert< R, F >::derive(), bpp::Identity< R >::derive(), bpp::ShiftParameter::derive(), bpp::ValueFromConfiguredParameter::derive(), bpp::Sequence_DF::derive(), bpp::ForwardHmmLikelihood_DF::derive(), bpp::ForwardHmmDLikelihood_DF::derive(), bpp::ConfiguredParameter::derive(), bpp::LikelihoodCalculationOnABranch::makeLikelihoods(), bpp::LikelihoodCalculationSingleProcess::makeLikelihoodsAtDAGNode_(), bpp::LikelihoodCalculationSingleProcess::makeLikelihoodsAtNode_(), and bpp::ProbabilityDAG::ProbabilityDAG().

◆ debugInfo()

template<typename T >
std::string bpp::ConstantOne< T >::debugInfo ( ) const
inlineoverridevirtual

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

Reimplemented from bpp::Node_DF.

Definition at line 1053 of file DataFlowNumeric.h.

References bpp::ConstantZero< T >::targetDimension_, 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()

template<typename T >
NodeRef bpp::ConstantOne< T >::derive ( Context c,
const Node_DF node 
)
inlinefinalvirtual

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 from bpp::Node_DF.

Definition at line 1076 of file DataFlowNumeric.h.

References bpp::ConstantZero< T >::create(), bpp::ConstantOne< T >::create(), and bpp::ConstantZero< T >::targetDimension_.

◆ deriveAsValue()

template<typename T >
ValueRef<T> bpp::Value< T >::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.

References bpp::Node_DF::derive().

◆ description()

◆ hashAdditionalArguments()

template<typename T >
std::size_t bpp::ConstantOne< T >::hashAdditionalArguments ( ) const
inlinefinalvirtual

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 1074 of file DataFlowNumeric.h.

References bpp::hash(), and bpp::ConstantZero< T >::targetDimension_.

◆ hasNumericalProperty()

template<typename T >
bool bpp::ConstantOne< T >::hasNumericalProperty ( NumericalProperty  prop) const
inlinefinalvirtual

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 from bpp::Node_DF.

Definition at line 1055 of file DataFlowNumeric.h.

References bpp::Constant, and bpp::ConstantOne.

◆ 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()

template<typename T >
template<typename Callable >
void bpp::Value< T >::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.

References bpp::Value< T >::accessValueMutable(), bpp::Node_DF::invalidateRecursively(), and bpp::Node_DF::makeValid().

Referenced by bpp::NumericMutable< T >::setValue().

◆ 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()

template<typename T >
NodeRef bpp::ConstantOne< T >::recreate ( Context c,
NodeRefVec &&  deps 
)
inlinefinalvirtual

Recreate the node with different dependencies.

Reimplemented from bpp::Node_DF.

Definition at line 1085 of file DataFlowNumeric.h.

References bpp::checkRecreateWithoutDependencies().

◆ 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()

template<typename T >
const T& bpp::Value< T >::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.

References bpp::Value< T >::accessValueConst(), and bpp::Node_DF::computeRecursively().

◆ 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

◆ dependencyNodes_

◆ dependentNodes_

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

◆ isValid_

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

◆ targetDimension_

template<typename T >
Dimension<T> bpp::ConstantOne< T >::targetDimension_
private

Definition at line 1098 of file DataFlowNumeric.h.

◆ value_

template<typename T >
T bpp::Value< T >::value_
privateinherited

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