14 ConfiguredDistribution::ConfiguredDistribution (
Context& context,
NodeRefVec&& deps, std::unique_ptr<DiscreteDistributionInterface>&& distrib)
16 , distrib_(std::move(distrib))
20 const auto& param = std::dynamic_pointer_cast<ConfiguredParameter>(dep);
38 const auto* derived =
dynamic_cast<const Self*
>(&other);
39 if (derived ==
nullptr)
46 const auto& otherDistrib = *derived->distrib_;
47 return typeid (thisDistrib) ==
typeid (otherDistrib);
54 return typeid (bppDistrib).hash_code ();
59 auto m = ConfiguredParametrizable::createConfigured<Target, Self>(c, std::move (deps), std::unique_ptr<DiscreteDistributionInterface>{
dynamic_cast<DiscreteDistributionInterface*
>(
distrib_->clone ())});
69 :
Value<
Eigen::RowVectorXd>(std::move (deps)), nbClass_ (dim) {}
74 using namespace numeric;
81 return dynamic_cast<const Self*
>(&other) !=
nullptr;
88 auto& distrib =
static_cast<Dep&
>(*distribDep);
89 auto buildPWithNewDistrib = [
this, &c](
NodeRef&& newDistrib) {
90 return ConfiguredParametrizable::createRowVector<Dep, Self>(c, {std::move(newDistrib)},
nbClass_);
93 NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<ConfiguredDistribution, T >(
94 c, distrib, node,
nbClass_, buildPWithNewDistrib);
100 return ConfiguredParametrizable::createRowVector<Dep, Self>(c, std::move (deps),
nbClass_);
105 const auto* distrib = accessValueConstCast<const DiscreteDistributionInterface*>(*this->
dependency (0));
106 const auto& probasFromDistrib = distrib->getProbabilities();
108 r = Eigen::Map<const T>(probasFromDistrib.data(),
static_cast<Eigen::Index
>(probasFromDistrib.size ()));
116 checkNthDependencyIs<ConfiguredDistribution>(
typeid (
Self), deps, 0);
117 size_t nbCat = accessValueConstCast<DiscreteDistributionInterface*>(*deps[0])->getNumberOfCategories();
118 return cachedAs<ProbabilitiesFromDiscreteDistribution>(c, std::make_shared<ProbabilitiesFromDiscreteDistribution>(std::move(deps),
RowVectorDimension(Eigen::Index(nbCat))));
127 :
Value<double>(std::move (deps)), nCat_ (nCat) {}
132 using namespace numeric;
139 const auto* derived =
dynamic_cast<const Self*
>(&other);
140 return derived !=
nullptr &&
nCat_ == derived->nCat_;
147 checkNthDependencyIs<ConfiguredDistribution>(
typeid (
Self), deps, 0);
148 return cachedAs<ProbabilityFromDiscreteDistribution>(c, std::make_shared<ProbabilityFromDiscreteDistribution>(std::move (deps), nCat));
155 auto& distrib =
static_cast<Dep&
>(*distribDep);
156 auto buildPWithNewDistrib = [
this, &c](
NodeRef&& newDistrib) {
157 return this->
create (c, {std::move (newDistrib)},
nCat_);
160 NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<Dep, T >(
161 c, distrib, node, 1, buildPWithNewDistrib);
172 const auto* distrib = accessValueConstCast<const DiscreteDistributionInterface*>(*this->
dependency (0));
181 :
Value<double>(std::move (deps)),
nCat_ (nCat) {}
186 using namespace numeric;
193 const auto* derived =
dynamic_cast<const Self*
>(&other);
194 return derived !=
nullptr &&
nCat_ == derived->nCat_;
201 checkNthDependencyIs<ConfiguredDistribution>(
typeid (
Self), deps, 0);
202 return cachedAs<CategoryFromDiscreteDistribution>(c, std::make_shared<CategoryFromDiscreteDistribution>(std::move (deps), nCat));
209 auto& distrib =
static_cast<Dep&
>(*distribDep);
210 auto buildPWithNewDistrib = [
this, &c](
NodeRef&& newDistrib) {
211 return this->
create (c, {std::move (newDistrib)},
nCat_);
214 NodeRefVec derivativeSumDeps = ConfiguredParametrizable::generateDerivativeSumDepsForComputations<Dep, T >(
215 c, distrib, node, 1, buildPWithNewDistrib);
226 const auto* distrib = accessValueConstCast<const DiscreteDistributionInterface*>(*this->
dependency (0));
227 double categoryFromDistrib = distrib->getCategory(
nCat_);
virtual void shareParameter_(const std::shared_ptr< Parameter > ¶meter)
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
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).
void compute() final
Computation implementation.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
CategoryFromDiscreteDistribution(NodeRefVec &&deps, uint nCat_)
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps, uint nCat)
Context for dataflow node construction.
Base dataflow Node class.
const NodeRef & dependency(std::size_t i) const noexcept
const NodeRefVec & dependencies() const noexcept
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps)
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
ProbabilitiesFromDiscreteDistribution(NodeRefVec &&deps, const Dimension< T > &dim)
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
void compute() final
Computation implementation.
void compute() final
Computation implementation.
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps, uint nCat)
NodeRef derive(Context &c, const Node_DF &node) final
Returns a node computing d(this_node_expression)/d(node_expression).
ProbabilityFromDiscreteDistribution(NodeRefVec &&deps, uint nCat_)
bool compareAdditionalArguments(const Node_DF &other) const final
Compare node-specific configuration to another.
NodeRef recreate(Context &c, NodeRefVec &&deps) final
Recreate the node with different dependencies.
std::string debugInfo() const final
Node debug info (default = ""): user defined detailed info for DF graph debug.
Abstract Node storing a value of type T.
const Eigen::RowVectorXd & accessValueConst() const noexcept
Raw value access (const).
Eigen::RowVectorXd & accessValueMutable() noexcept
std::string toString(T t)
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.
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
Store a dimension for type T.