aGrUM  0.17.1
a C++ library for (probabilistic) graphical models
gum::prm::gspan::TreeWidthSearch< GUM_SCALAR > Class Template Reference

A growth is accepted if and only if the new growth has a tree width less large or equal than its father. More...

#include <agrum/PRM/gspan/DFSTree.h>

+ Inheritance diagram for gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >:
+ Collaboration diagram for gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >:

Public Member Functions

Constructor and destructor.
 TreeWidthSearch ()
 Default constructor. More...
 
 TreeWidthSearch (const TreeWidthSearch &from)
 Copy constructor. More...
 
virtual ~TreeWidthSearch ()
 Destructor. More...
 
TreeWidthSearchoperator= (const TreeWidthSearch &from)
 Copy operator. More...
 
Search methods.
double cost (const Pattern &p)
 
virtual bool accept_root (const Pattern *r)
 
virtual bool accept_growth (const Pattern *parent, const Pattern *child, const EdgeGrowth< GUM_SCALAR > &growth)
 
virtual bool operator() (LabelData *i, LabelData *j)
 
virtual bool operator() (Pattern *i, Pattern *j)
 
Search methods.
void setTree (DFSTree< GUM_SCALAR > *tree)
 

Protected Attributes

DFSTree< GUM_SCALAR > * _tree
 

Protected Member Functions

double _computeCost (const Pattern &p)
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >

A growth is accepted if and only if the new growth has a tree width less large or equal than its father.

Definition at line 263 of file searchStrategy.h.

Constructor & Destructor Documentation

◆ TreeWidthSearch() [1/2]

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( )

Default constructor.

Definition at line 406 of file searchStrategy_tpl.h.

406  :
407  SearchStrategy< GUM_SCALAR >() {
408  GUM_CONSTRUCTOR(TreeWidthSearch);
409  }
TreeWidthSearch()
Default constructor.

◆ TreeWidthSearch() [2/2]

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( const TreeWidthSearch< GUM_SCALAR > &  from)

Copy constructor.

Definition at line 412 of file searchStrategy_tpl.h.

413  :
414  SearchStrategy< GUM_SCALAR >(from) {
415  GUM_CONS_CPY(TreeWidthSearch);
416  }
TreeWidthSearch()
Default constructor.

◆ ~TreeWidthSearch()

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::~TreeWidthSearch ( )
virtual

Destructor.

Definition at line 419 of file searchStrategy_tpl.h.

419  {
420  GUM_DESTRUCTOR(TreeWidthSearch);
421  }
TreeWidthSearch()
Default constructor.

Member Function Documentation

◆ _computeCost()

template<typename GUM_SCALAR >
double gum::prm::gspan::SearchStrategy< GUM_SCALAR >::_computeCost ( const Pattern p)
protectedinherited

Definition at line 36 of file searchStrategy_tpl.h.

References gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::exists(), and gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::insert().

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::__compute_costs(), and gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost().

36  {
37  double cost = 0;
38  const Sequence< PRMInstance< GUM_SCALAR >* >& seq =
39  *(this->_tree->data(p).iso_map.begin().val());
40  Sequence< PRMClassElement< GUM_SCALAR >* > input_set;
41 
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))
46  && (!input_set.exists(
47  &(inst2->get(input->lastElt().safeName()))))) {
48  cost += std::log(input->type().variable().domainSize());
49  input_set.insert(&(inst2->get(input->lastElt().safeName())));
50  }
51 
52  for (auto vec = inst->beginInvRef(); vec != inst->endInvRef(); ++vec)
53  for (const auto inverse: *vec.val())
54  if (!seq.exists(inverse.first)) {
55  cost +=
56  std::log(inst->get(vec.key()).type().variable().domainSize());
57  break;
58  }
59  }
60 
61  return cost;
62  }
DFSTree< GUM_SCALAR > * _tree
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ accept_growth()

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_growth ( const Pattern parent,
const Pattern child,
const EdgeGrowth< GUM_SCALAR > &  growth 
)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 451 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost().

454  {
455  return cost(*parent) >= cost(*child);
456  }
+ Here is the call graph for this function:

◆ accept_root()

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_root ( const Pattern r)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 441 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost(), gum::prm::gspan::Pattern::label(), gum::prm::gspan::Pattern::nodes(), and gum::prm::gspan::LabelData::tree_width.

441  {
442  Size tree_width = 0;
443 
444  for (const auto n: r->nodes())
445  tree_width += r->label(n).tree_width;
446 
447  return tree_width >= cost(*r);
448  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:

◆ cost()

template<typename GUM_SCALAR >
INLINE double gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost ( const Pattern p)

Definition at line 431 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::__map, and gum::prm::gspan::SearchStrategy< GUM_SCALAR >::_computeCost().

Referenced by gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_growth(), gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_root(), and gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator()().

431  {
432  try {
433  return __map[&p];
434  } catch (NotFound&) {
435  __map.insert(&p, this->_computeCost(p));
436  return __map[&p];
437  }
438  }
HashTable< const Pattern *, double > __map
double _computeCost(const Pattern &p)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator()() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( LabelData i,
LabelData j 
)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 465 of file searchStrategy_tpl.h.

References gum::prm::gspan::LabelData::tree_width.

466  {
467  return i->tree_width < j->tree_width;
468  }

◆ operator()() [2/2]

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( gspan::Pattern i,
gspan::Pattern j 
)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 459 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost().

460  {
461  return cost(*i) < cost(*j);
462  }
+ Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR >
INLINE TreeWidthSearch< GUM_SCALAR > & gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator= ( const TreeWidthSearch< GUM_SCALAR > &  from)

Copy operator.

Definition at line 425 of file searchStrategy_tpl.h.

426  {
427  return *this;
428  }

◆ setTree()

template<typename GUM_SCALAR >
INLINE void gum::prm::gspan::SearchStrategy< GUM_SCALAR >::setTree ( DFSTree< GUM_SCALAR > *  tree)
inherited

Definition at line 233 of file searchStrategy_tpl.h.

References gum::prm::gspan::SearchStrategy< GUM_SCALAR >::_tree.

233  {
234  this->_tree = tree;
235  }
DFSTree< GUM_SCALAR > * _tree

Member Data Documentation

◆ __map

template<typename GUM_SCALAR>
HashTable< const Pattern*, double > gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::__map
private

◆ _tree


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