aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
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 125 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 227 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

227  :
228  SearchStrategy< GUM_SCALAR >(), _freq_(freq) {
229  GUM_CONSTRUCTOR(FrequenceSearch);
230  }
FrequenceSearch(Size freq)
Default constructor.
+ Here is the call graph for this function:

◆ 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 234 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

234  :
235  SearchStrategy< GUM_SCALAR >(from),
236  _freq_(from._freq_) {
237  GUM_CONS_CPY(FrequenceSearch);
238  }
FrequenceSearch(Size freq)
Default constructor.
+ Here is the call graph for this function:

◆ ~FrequenceSearch()

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

Destructor.

Definition at line 241 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

241  {
242  GUM_DESTRUCTOR(FrequenceSearch);
243  }
FrequenceSearch(Size freq)
Default constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ 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

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

Definition at line 259 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

261  {
262  return this->tree_->frequency(*child) >= _freq_;
263  }
DFSTree< GUM_SCALAR > * tree_
+ Here is the call graph for this function:

◆ accept_root()

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

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

Definition at line 253 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

253  {
254  return this->tree_->frequency(*r) >= _freq_;
255  }
DFSTree< GUM_SCALAR > * tree_
+ Here is the call graph for this function:

◆ computeCost_()

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

Definition at line 35 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

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

◆ 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 272 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

272  {
273  return (this->tree_->graph().size(i) > this->tree_->graph().size(j));
274  }
DFSTree< GUM_SCALAR > * tree_
+ Here is the call graph for this function:

◆ 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 266 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

266  {
267  // We want a descending order
268  return this->tree_->frequency(*i) > this->tree_->frequency(*j);
269  }
DFSTree< GUM_SCALAR > * tree_
+ Here is the call graph for this function:

◆ 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 247 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

247  {
248  _freq_ = from._freq_;
249  return *this;
250  }
+ Here is the call 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 219 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

219  {
220  this->tree_ = tree;
221  }
DFSTree< GUM_SCALAR > * tree_
+ Here is the call graph for this function:

Member Data Documentation

◆ _freq_

template<typename GUM_SCALAR >
Size gum::prm::gspan::FrequenceSearch< GUM_SCALAR >::_freq_
private

Definition at line 161 of file searchStrategy.h.

◆ tree_

template<typename GUM_SCALAR >
DFSTree< GUM_SCALAR >* gum::prm::gspan::SearchStrategy< GUM_SCALAR >::tree_
protectedinherited

Definition at line 111 of file searchStrategy.h.


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