35 template <
typename GUM_SCALAR >
39 *(this->_tree->data(p).iso_map.begin().val());
42 for (
const auto inst : seq) {
43 for (
const auto input : inst->type().slotChains())
44 for (
const auto inst2 : inst->getInstances(input->id()))
45 if ((!seq.exists(inst2))
47 &(inst2->get(input->lastElt().safeName()))))) {
48 cost += std::log(input->type().variable().domainSize());
49 input_set.
insert(&(inst2->get(input->lastElt().safeName())));
52 for (
auto vec = inst->beginInvRef(); vec != inst->endInvRef(); ++vec)
53 for (
const auto inverse : *vec.val())
54 if (!seq.exists(inverse.first)) {
56 std::log(inst->get(vec.key()).type().variable().domainSize());
64 template <
typename GUM_SCALAR >
69 for (
const auto inst : match) {
70 for (
const auto& elt : *inst) {
74 data.
mod.insert(
id, elt.second->type()->domainSize());
75 data.
vars.insert(
id, &elt.second->type().variable());
82 for (
const auto inst : match)
83 for (
const auto& elt : *inst) {
89 for (
const auto chld :
90 inst->type().containerDag().children(elt.second->id())) {
97 inst->type().containerDag().parents(elt.second->id())) {
98 switch (inst->type().get(par).elt_type()) {
107 for (
const auto inst2 : inst->getInstances(par))
108 if (match.exists(inst2))
114 inst->type().get(par)))));
125 if (inst->hasRefAttr(elt.second->id())) {
127 std::pair< PRMInstance< GUM_SCALAR >*, std::string > >& ref_attr =
128 inst->getRefAttr(elt.second->id());
130 for (
auto pair = ref_attr.begin(); pair != ref_attr.end(); ++pair) {
131 if (match.exists(pair->first)) {
132 NodeId id = pair->first->type().get(pair->second).id();
134 for (
const auto child :
135 pair->first->type().containerDag().children(
id))
138 pair->first, pair->first->get(child))));
152 template <
typename GUM_SCALAR >
164 Size max(0), max_count(1);
168 for (
size_t idx = 0; idx < data.
inners.
size(); ++idx) {
170 pot->
add(*(data.
vars.second(elim_order[idx])));
174 for (
const auto p : pool)
175 if (p->contains(*(data.
vars.second(elim_order[idx])))) {
176 for (
auto var = p->variablesSequence().begin();
177 var != p->variablesSequence().end();
194 for (
const auto p : toRemove)
197 pot->
erase(*(data.
vars.second(elim_order[idx])));
200 for (
const auto pot : trash)
203 return std::make_pair(max, max_count);
207 template <
typename GUM_SCALAR >
212 template <
typename GUM_SCALAR >
219 template <
typename GUM_SCALAR >
224 template <
typename GUM_SCALAR >
231 template <
typename GUM_SCALAR >
240 template <
typename GUM_SCALAR >
246 template <
typename GUM_SCALAR >
254 template <
typename GUM_SCALAR >
259 template <
typename GUM_SCALAR >
266 template <
typename GUM_SCALAR >
271 template <
typename GUM_SCALAR >
279 template <
typename GUM_SCALAR >
283 return this->
_tree->frequency(*i) > this->
_tree->frequency(*j);
286 template <
typename GUM_SCALAR >
289 return (this->
_tree->graph().size(i) > this->
_tree->graph().size(j));
295 template <
typename GUM_SCALAR >
301 template <
typename GUM_SCALAR >
309 template <
typename GUM_SCALAR >
314 template <
typename GUM_SCALAR >
321 template <
typename GUM_SCALAR >
326 template <
typename GUM_SCALAR >
336 template <
typename GUM_SCALAR >
343 template <
typename GUM_SCALAR >
350 template <
typename GUM_SCALAR >
353 return __map[p].first;
356 return __map[p].first;
360 template <
typename GUM_SCALAR >
363 return __map[p].second;
366 return __map[p].second;
370 template <
typename GUM_SCALAR >
377 template <
typename GUM_SCALAR >
384 template <
typename GUM_SCALAR >
391 template <
typename GUM_SCALAR >
396 data, pool, *(this->
_tree->data(*p).iso_map.begin().val()));
399 __map.insert(p, std::make_pair(inner, outer));
404 template <
typename GUM_SCALAR >
410 template <
typename GUM_SCALAR >
417 template <
typename GUM_SCALAR >
422 template <
typename GUM_SCALAR >
428 template <
typename GUM_SCALAR >
438 template <
typename GUM_SCALAR >
442 for (
const auto n : r->
nodes())
445 return tree_width >=
cost(*r);
448 template <
typename GUM_SCALAR >
453 return cost(*parent) >=
cost(*child);
456 template <
typename GUM_SCALAR >
462 template <
typename GUM_SCALAR >
void setTree(DFSTree< GUM_SCALAR > *tree)
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
aGrUM's Potential is a multi-dimensional array with tensor operators.
void __buildPatternGraph(typename StrictSearch< GUM_SCALAR >::PData &data, Set< Potential< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
This class is used to define an edge growth of a pattern in this DFSTree.
NodeSet inners
Returns the set of inner nodes.
virtual Size domainSize() const final
Returns the product of the variables domain size.
virtual bool accept_growth(const Pattern *parent, const Pattern *child, const EdgeGrowth< GUM_SCALAR > &growth)
virtual bool operator()(LabelData *i, LabelData *j)
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
Inner class to handle data about labels in this interface graph.
const std::string & name() const
Returns the name of this object.
virtual bool accept_root(const Pattern *r)
double cost(const Pattern &p)
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
virtual ~TreeWidthSearch()
Destructor.
double __outer_cost(const Pattern *p)
StrictSearch & operator=(const StrictSearch &from)
Copy operator.
The generic class for storing (ordered) sequences of objects.
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
virtual void erase(const DiscreteVariable &var) final
Removes a var from the variables of the multidimensional matrix.
virtual ~FrequenceSearch()
Destructor.
Abstract class representing an element of PRM class.
UndiGraph graph
A yet to be triangulated undigraph.
std::pair< Size, Size > __elimination_cost(typename StrictSearch< GUM_SCALAR >::PData &data, Set< Potential< GUM_SCALAR > * > &pool)
Bijection< NodeId, const DiscreteVariable *> vars
Bijection between graph's nodes and their corresponding DiscreteVariable, for inference purpose...
Generic doubly linked lists.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual NodeId addNode()
insert a new node and return its id
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
DFSTree< GUM_SCALAR > * _tree
virtual bool operator()(LabelData *i, LabelData *j)
FrequenceSearch & operator=(const FrequenceSearch &from)
Copy operator.
Representation of a setA Set is a structure that contains arbitrary elements.
StrictSearch(Size freq=2)
Default constructor.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph...
A growth is accepted if and only if the new growth has a tree width less large or equal than its fath...
std::string __str(const PRMInstance< GUM_SCALAR > *i, const PRMAttribute< GUM_SCALAR > *a) const
virtual ~SearchStrategy()
Destructor.
virtual bool accept_root(const Pattern *r)
HashTable< const Pattern *, double > __map
virtual bool accept_growth(const Pattern *parent, const Pattern *child, const EdgeGrowth< GUM_SCALAR > &growth)
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
NodeSet outputs
Returns the set of outputs nodes given all the matches of pattern.
virtual bool accept_growth(const Pattern *parent, const Pattern *child, const EdgeGrowth< GUM_SCALAR > &growth)
virtual bool accept_root(const Pattern *r)
const std::vector< NodeId > & eliminationOrder()
returns an elimination ordering compatible with the triangulated graph
Bijection< NodeId, std::string > node2attr
A bijection to easily keep track between graph and attributes, its of the form instance_name DOT attr...
TreeWidthSearch()
Default constructor.
bool exists(const Key &k) const
Check the existence of k in the sequence.
NodeProperty< Size > mod
The pattern's variables modalities.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
FrequenceSearch(Size freq)
Default constructor.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
const NodeGraphPart & nodes() const
Private structure to represent data about a pattern.
HashTable< const Pattern *, std::pair< double, double > > __map
This is class is an implementation of a strict strategy for the GSpan algorithm.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
double __inner_cost(const Pattern *p)
This is class is an implementation of a simple serach strategy for the gspan algorithm: it accept a g...
SearchStrategy()
Default constructor.
double _computeCost(const Pattern &p)
void __compute_costs(const Pattern *p)
Size tree_width
The size in terms of tree width of the given label.
PRMAttribute is a member of a Class in a PRM.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
Size size() const noexcept
Returns the number of elements in the set.
TreeWidthSearch & operator=(const TreeWidthSearch &from)
Copy operator.
virtual ~StrictSearch()
Destructor.
This contains all the information we want for a node in a DFSTree.
This is an abstract class used to tune search strategies in the gspan algorithm.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
Multidimensional matrix stored as a sparse array in memory.
SearchStrategy< GUM_SCALAR > & operator=(const SearchStrategy< GUM_SCALAR > &from)
Copy operator.
virtual bool operator()(LabelData *i, LabelData *j)
void insert(const Key &k)
Insert an element at the end of the sequence.