aGrUM  0.16.0
correctedMutualInformation.h
Go to the documentation of this file.
1 
30 #ifndef GUM_LEARNING_CORRECTED_MUTUAL_INFORMATION_H
31 #define GUM_LEARNING_CORRECTED_MUTUAL_INFORMATION_H
32 
33 #include <agrum/config.h>
34 #include <agrum/core/math/math.h>
35 #include <vector>
36 
40 
41 namespace gum {
42 
43  namespace learning {
44 
55  template < template < typename > class ALLOC = std::allocator >
57  public:
59  using allocator_type = ALLOC< NodeId >;
60 
61  // ##########################################################################
63  // ##########################################################################
65 
67 
90  const DBRowGeneratorParser< ALLOC >& parser,
91  const Apriori< ALLOC >& apriori,
92  const std::vector< std::pair< std::size_t, std::size_t >,
93  ALLOC< std::pair< std::size_t, std::size_t > > >&
94  ranges,
95  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
96  nodeId2columns =
97  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
98  const allocator_type& alloc = allocator_type());
99 
101 
118  const DBRowGeneratorParser< ALLOC >& parser,
119  const Apriori< ALLOC >& apriori,
120  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
121  nodeId2columns =
122  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
123  const allocator_type& alloc = allocator_type());
124 
127 
130  const allocator_type& alloc);
131 
134 
137  const allocator_type& alloc);
138 
141 
144  clone(const allocator_type& alloc) const;
145 
147  virtual ~CorrectedMutualInformation();
148 
150 
151 
152  // ##########################################################################
154  // ##########################################################################
155 
157 
161 
165 
167 
168 
169  // ##########################################################################
171  // ##########################################################################
173 
175  virtual void clear();
176 
178 
186  virtual void clearCache();
187 
189 
197  virtual void useCache(bool on_off);
198 
200  void useICache(bool on_off);
201 
203  void clearICache();
204 
206  void useHCache(bool on_off);
207 
209  void clearHCache();
210 
212  void useKCache(bool on_off);
213 
215  void clearKCache();
216 
218  void useCnrCache(bool on_off);
219 
221  void clearCnrCache();
222 
224 
225 
226  // ##########################################################################
228  // ##########################################################################
230 
232  double score(NodeId var1, NodeId var2);
233 
235  double score(NodeId var1,
236  NodeId var2,
237  const std::vector< NodeId, ALLOC< NodeId > >& conditioning_ids);
238 
240  double score(NodeId var1, NodeId var2, NodeId var3);
241 
243  double score(NodeId var1,
244  NodeId var2,
245  NodeId var3,
246  const std::vector< NodeId, ALLOC< NodeId > >& conditioning_ids);
247 
249 
250 
251  // ##########################################################################
253  // ##########################################################################
255 
257  void useMDL();
258 
260  void useNML();
261 
263  void useNoCorr();
264 
266  virtual void setMaxNbThreads(std::size_t nb) const;
267 
269  virtual std::size_t nbThreads() const;
270 
280  virtual void setMinNbRowsPerThread(const std::size_t nb) const;
281 
283  virtual std::size_t minNbRowsPerThread() const;
284 
286 
292  template < template < typename > class XALLOC >
293  void setRanges(
294  const std::vector< std::pair< std::size_t, std::size_t >,
295  XALLOC< std::pair< std::size_t, std::size_t > > >&
296  new_ranges);
297 
299  void clearRanges();
300 
302  const std::vector< std::pair< std::size_t, std::size_t >,
303  ALLOC< std::pair< std::size_t, std::size_t > > >&
304  ranges() const;
305 
306 
309 
311 
312 
314  enum class KModeTypes { MDL, NML, NoCorr };
315 
316 
317 #ifndef DOXYGEN_SHOULD_SKIP_THIS
318 
319  private:
321  /* Note that the log2-likelihood is equal to N times the entropy H */
323 
325  KNML< ALLOC > __k_NML;
326 
329  ScoreMDL< ALLOC > __score_MDL;
330 
332  KModeTypes __kmode{KModeTypes::MDL};
333 
334 
336 
338  bool __use_ICache{true};
339 
341 
344  bool __use_HCache{true};
345 
347 
350  bool __use_KCache{true};
351 
353 
357  bool __use_CnrCache{true};
358 
359 
361  ScoringCache< ALLOC > __ICache;
362 
364  ScoringCache< ALLOC > __KCache;
365 
366 
368  const std::vector< NodeId, ALLOC< NodeId > > __empty_conditioning_set;
369 
371  const double __threshold{1e-10};
372 
373 
375  double __NI_score(NodeId var_x,
376  NodeId var_y,
377  const std::vector< NodeId, ALLOC< NodeId > >& vars_z);
378 
380  double __NI_score(NodeId var_x,
381  NodeId var_y,
382  NodeId var_z,
383  const std::vector< NodeId, ALLOC< NodeId > >& vars_ui);
384 
386  double __K_score(NodeId var_x,
387  NodeId var_y,
388  const std::vector< NodeId, ALLOC< NodeId > >& vars_z);
389 
391  double __K_score(NodeId var_x,
392  NodeId var_y,
393  NodeId var_z,
394  const std::vector< NodeId, ALLOC< NodeId > >& vars_ui);
395 
396 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
397  };
398 
399  } /* namespace learning */
400 
401 } /* namespace gum */
402 
403 
404 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
405 extern template class gum::learning::CorrectedMutualInformation<>;
406 #endif
407 
408 
409 // always include the template implementation
411 
412 #endif /* GUM_LEARNING_CORRECTED_MUTUAL_INFORMATION_H */
void useNML()
use the kNML penalty function
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void clearRanges()
reset the ranges to the one range corresponding to the whole database
KModeTypes
the description type for the complexity correction
void useCnrCache(bool on_off)
turn on/off the use of the CnrCache (the cache for the Cnr formula)
virtual void useCache(bool on_off)
turn on/off the use of all the caches
void useHCache(bool on_off)
turn on/off the use of the HCache (the cache for the entropies)
The class computing n times the corrected mutual information, as used in the 3off2 algorithm...
virtual ~CorrectedMutualInformation()
destructor
virtual void clear()
clears all the data structures from memory
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void clearICache()
clears the ICache (the mutual information cache)
CorrectedMutualInformation< ALLOC > & operator=(const CorrectedMutualInformation< ALLOC > &from)
copy operator
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
allocator_type getAllocator() const
returns the allocator used by the score
void useKCache(bool on_off)
turn on/off the use of the KCache (the cache for the penalties)
the base class for all a priori
Definition: apriori.h:50
virtual CorrectedMutualInformation< ALLOC > * clone() const
virtual copy constructor
virtual void clearCache()
clears all the current caches
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
virtual std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
the class for computing Log2-likelihood scores
const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > > & ranges() const
returns the current ranges
double score(NodeId var1, NodeId var2)
returns the 2-point mutual information corresponding to a given nodeset
void setRanges(const std::vector< std::pair< std::size_t, std::size_t >, XALLOC< std::pair< std::size_t, std::size_t > > > &new_ranges)
sets new ranges to perform the countings used by the mutual information
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
the class for computing BIC scores
Definition: scoreBIC.h:52
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
CorrectedMutualInformation(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &apriori, const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > > &ranges, const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > &nodeId2columns=Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(), const allocator_type &alloc=allocator_type())
default constructor
void clearKCache()
clears the KCache (the cache for the penalties)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
a cache for caching scores and independence tests resultsCaching previously computed scores or the re...
Definition: scoringCache.h:60
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void clearHCache()
clears the HCache (the cache for the entropies)
virtual std::size_t nbThreads() const
returns the number of threads used to parse the database
the class for computing the NML penalty used by 3off2
Definition: kNML.h:50
virtual void setMinNbRowsPerThread(const std::size_t nb) const
changes the number min of rows a thread should process in a multithreading context ...
void useMDL()
use the MDL penalty function
void useICache(bool on_off)
turn on/off the use of the ICache (the mutual information cache)
void clearCnrCache()
clears the CnrCache (the cache for the Cnr formula)
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void useNoCorr()
use no correction/penalty function
virtual void setMaxNbThreads(std::size_t nb) const
changes the max number of threads used to parse the database