aGrUM  0.16.0
gum::prm::gspan::FrequenceSearch< GUM_SCALAR > Class Template Reference

This is class is an implementation of a simple serach strategy for the gspan algorithm: it accept a growth if its frequency is above a user defined value. More...

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

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

Public Member Functions

Constructor and destructor.
 FrequenceSearch (Size freq)
 Default constructor. More...
 
 FrequenceSearch (const FrequenceSearch &from)
 Copy constructor. More...
 
virtual ~FrequenceSearch ()
 Destructor. More...
 
FrequenceSearchoperator= (const FrequenceSearch &from)
 Copy operator. More...
 
Search methods.
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::FrequenceSearch< GUM_SCALAR >

This is class is an implementation of a simple serach strategy for the gspan algorithm: it accept a growth if its frequency is above a user defined value.

Definition at line 126 of file searchStrategy.h.

Constructor & Destructor Documentation

◆ FrequenceSearch() [1/2]

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::FrequenceSearch< GUM_SCALAR >::FrequenceSearch ( Size  freq)
explicit

Default constructor.

Definition at line 241 of file searchStrategy_tpl.h.

241  :
242  SearchStrategy< GUM_SCALAR >(), __freq(freq) {
243  GUM_CONSTRUCTOR(FrequenceSearch);
244  }
FrequenceSearch(Size freq)
Default constructor.

◆ FrequenceSearch() [2/2]

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

Copy constructor.

Definition at line 247 of file searchStrategy_tpl.h.

248  :
249  SearchStrategy< GUM_SCALAR >(from),
250  __freq(from.__freq) {
251  GUM_CONS_CPY(FrequenceSearch);
252  }
FrequenceSearch(Size freq)
Default constructor.

◆ ~FrequenceSearch()

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

Destructor.

Definition at line 255 of file searchStrategy_tpl.h.

References gum::prm::gspan::FrequenceSearch< GUM_SCALAR >::operator=().

255  {
256  GUM_DESTRUCTOR(FrequenceSearch);
257  }
FrequenceSearch(Size freq)
Default constructor.
+ Here is the call graph for this function:

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::FrequenceSearch< GUM_SCALAR >::accept_growth ( const Pattern parent,
const Pattern child,
const EdgeGrowth< GUM_SCALAR > &  growth 
)
virtual

◆ accept_root()

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

◆ operator()() [1/2]

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

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

Definition at line 287 of file searchStrategy_tpl.h.

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

288  {
289  return (this->_tree->graph().size(i) > this->_tree->graph().size(j));
290  }
DFSTree< GUM_SCALAR > * _tree

◆ operator()() [2/2]

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

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

Definition at line 280 of file searchStrategy_tpl.h.

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

281  {
282  // We want a descending order
283  return this->_tree->frequency(*i) > this->_tree->frequency(*j);
284  }
DFSTree< GUM_SCALAR > * _tree

◆ operator=()

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

Copy operator.

Definition at line 261 of file searchStrategy_tpl.h.

References gum::prm::gspan::FrequenceSearch< GUM_SCALAR >::__freq.

Referenced by gum::prm::gspan::FrequenceSearch< GUM_SCALAR >::~FrequenceSearch().

261  {
262  __freq = from.__freq;
263  return *this;
264  }
+ Here is the caller graph for this function:

◆ 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

◆ __freq

◆ _tree


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