40 template <
template <
typename >
class ALLOC >
48 template <
template <
typename >
class ALLOC >
51 ALLOC< NodeId >(alloc) {
57 template <
template <
typename >
class ALLOC >
62 ALLOC< NodeId >(alloc) {
68 template <
template <
typename >
class ALLOC >
74 template <
template <
typename >
class ALLOC >
79 ALLOC< NodeId >(alloc) {
85 template <
template <
typename >
class ALLOC >
91 template <
template <
typename >
class ALLOC >
94 ALLOC< DAG2BNLearner< ALLOC > > allocator(alloc);
97 allocator.construct(new_learner, *
this, alloc);
99 allocator.deallocate(new_learner, 1);
108 template <
template <
typename >
class ALLOC >
115 template <
template <
typename >
class ALLOC >
122 template <
template <
typename >
class ALLOC >
125 ApproximationScheme::operator=(from);
131 template <
template <
typename >
class ALLOC >
134 ApproximationScheme::operator=(std::move(from));
140 template <
template <
typename >
class ALLOC >
141 template <
typename GUM_SCALAR >
157 pot.
set(j, other_pot[i]);
162 template <
template <
typename >
class ALLOC >
163 template <
typename GUM_SCALAR >
171 const auto& database = estimator.
database();
172 if (node2cols.empty()) {
173 for (
const auto id : dag) {
174 bn.
add(dynamic_cast< const DiscreteVariable& >(database.variable(
id)),
178 for (
const auto id : dag) {
179 const std::size_t col = node2cols.second(
id);
180 bn.
add(dynamic_cast< const DiscreteVariable& >(database.variable(col)),
187 for (
const auto& arc : dag.
arcs()) {
188 bn.
addArc(arc.tail(), arc.head());
194 for (
const auto id : dag) {
202 std::vector< NodeId > conditioning_ids(vars.size() - 1);
203 for (
auto i = std::size_t(1); i < vars.size(); ++i) {
204 conditioning_ids[i - 1] = varmap.
get(*(vars[i]));
213 template <
template <
typename >
class ALLOC >
214 template <
typename GUM_SCALAR >
221 for (
const auto& nod : bn.
nodes()) {
222 bn.
cpt(nod).noising(0.1);
232 const auto& xdag = bn.
dag();
233 for (
const auto node : xdag) {
239 createBN< GUM_SCALAR >(general_estimator, dag);
242 delta = GUM_SCALAR(0.0);
243 for (
const auto node : dag) {
244 const auto& old_cpt = bn.
cpt(node);
245 const auto& new_cpt = new_bn.
cpt(node);
250 for (; !old_inst.
end(); ++old_inst, ++new_inst) {
251 const GUM_SCALAR old_val = old_cpt.get(old_inst);
253 const GUM_SCALAR new_val = new_cpt.get(new_inst);
254 const GUM_SCALAR diff = new_val - old_val;
256 (diff < 0.0) ? (-diff / old_val) : (diff / old_val);
257 if (delta < diffrel) delta = diffrel;
262 bn = std::move(new_bn);
273 template <
template <
typename >
class ALLOC >
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head's CPT.
aGrUM's Potential is a multi-dimensional array with tensor operators.
Class representing a Bayesian Network.
static BayesNet< GUM_SCALAR > createBN(ParamEstimator< ALLOC > &estimator, const DAG &dag)
create a BN from a DAG using a one pass generator (typically ML)
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > & nodeId2Columns() const
returns the mapping from ids to column positions in the database
void setParameters(const NodeId target_node, const std::vector< NodeId, ALLOC< NodeId > > &conditioning_nodes, Potential< GUM_SCALAR > &pot)
sets the CPT's parameters corresponding to a given Potential
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
The generic class for storing (ordered) sequences of objects.
Container used to map discrete variables with nodes.
virtual ~DAG2BNLearner()
destructor
void initApproximationScheme()
Initialise the scheme.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
void setBayesNet(const BayesNet< GUM_SCALAR > &new_bn)
assign a new Bayes net to all the counter's generators depending on a BN
ApproximationScheme(bool verbosity=false)
void beginTopologyTransformation()
When inserting/removing arcs, node CPTs change their dimension with a cost in time.
allocator_type getAllocator() const
returns the allocator used by the score
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
const VariableNodeMap & variableNodeMap() const final
Returns a map between variables and nodes of this gum::BayesNet.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
DAG2BNLearner< ALLOC > & operator=(const DAG2BNLearner< ALLOC > &from)
copy operator
void stopApproximationScheme()
Stop the approximation scheme.
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
const DatabaseTable< ALLOC > & database() const
returns the database on which we perform the counts
Class for assigning/browsing values to tuples of discrete variables.
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
virtual DAG2BNLearner< ALLOC > * clone() const
virtual copy constructor
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const final
Default implementation of MultiDimContainer::set().
void setFirst()
Assign the first values to the tuple of the Instantiation.
void endTopologyTransformation()
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
A class that, given a structure and a parameter estimator returns a full Bayes net.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
The base class for estimating parameters of CPTs.
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
#define GUM_ERROR(type, msg)
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it's node id.
bool end() const
Returns true if the Instantiation reached the end.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
DAG2BNLearner(const allocator_type &alloc=allocator_type())
default constructor