aGrUM  0.13.2
partialEntropy.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
29 #ifndef GUM_LEARNING_PARTIALENTROPY_H
30 #define GUM_LEARNING_PARTIALENTROPY_H
31 
32 #include <agrum/config.h>
33 #include <agrum/core/math/math.h>
34 #include <vector>
35 
38 
39 namespace gum {
40 
41  namespace learning {
42 
43  /* =========================================================================
44  */
45  /* === PARTIAL ENTROPY CLASS ===
46  */
47  /* =========================================================================
48  */
49  template < typename IdSetAlloc = std::allocator< Idx >,
50  typename CountAlloc = std::allocator< double > >
51  class PartialEntropy : public Counter< IdSetAlloc, CountAlloc > {
52  public:
53  // ##########################################################################
55  // ##########################################################################
57 
58 
59  template < typename RowFilter >
60  PartialEntropy(const RowFilter& filter,
61  const std::vector< Size >& var_modalities,
62  Size min_range = 0,
63  Size max_range = std::numeric_limits< Size >::max());
64 
67 
68 
69  // ##########################################################################
71  // ##########################################################################
73  Idx addNodeSet(const std::vector< Idx >& var_set);
74 
75  Idx addNodeSet(Idx var);
76 
77  Idx addNodeSet(Idx var1, Idx var2);
78 
80  void clear();
81 
83  void clearCache();
84 
86  void useCache(bool on_off) noexcept;
87 
88 
90  double score(Idx nodeset_index);
91 
93 
97  void setRange(Size min_range, Size max_range);
98 
100  const Size N();
102 
103  protected:
105  const double _1log2{M_LOG2E};
106 
108 
120 
122 
124 
126 
129 
132 
134  bool _isInCache(Idx nodeset_index) const noexcept;
135 
137  void _insertIntoCache(Idx nodeset_index, double score);
138 
140  double _cachedScore(Idx nodeset_index) const noexcept;
141 
143  bool _isUsingCache() const noexcept;
144 
145  private:
147  Size __N = 0;
148 
151 
153  bool __use_cache{true};
154 
156  std::vector< bool > __is_cached_score;
157 
159  std::vector< double > __cached_score;
160 
162  const std::vector< Idx, IdSetAlloc > __empty_conditioning_set;
163  };
164 
165  } /* namespace learning */
166 
167 } /* namespace gum */
168 
169 
170 extern template class gum::learning::PartialEntropy<>;
171 
172 
173 // always include the template implementation
175 
176 #endif /* GUM_LEARNING_PARTIALENTROPY_H */
Useful macros for maths.
Idx addNodeSet(const std::vector< Idx > &var_set)
clears all the data structures from memory
void _insertIntoCache(Idx nodeset_index, double score)
inserts a new score into the cache
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
double score(Idx nodeset_index)
returns the score corresponding to a given nodeset
const double _1log2
1 / log(2)
Size __N
Size of the database.
const Size N()
return the size of the database
a cache for caching partial entropy in PartEntropy classCaching previously computed scores is very im...
std::vector< double > __cached_score
the vector of scores for the current nodesets
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool __use_cache
a Boolean indicating whether we wish to use the cache
void clear()
clears all the data structures from memory
Implementation of gum::learning::Entropy.
#define M_LOG2E
Definition: math.h:33
the base class for all the countings used for learning (BIC, BDeu, etc) as well as all the independen...
void clearCache()
clears the current cache (clear nodesets as well)
The counting class for all the scores used for learning (BIC, BDeu, etc) as well as for all the indep...
Definition: counter.h:108
a cache for caching partial entropy in 3off2
PartialEntropy(const RowFilter &filter, const std::vector< Size > &var_modalities, Size min_range=0, Size max_range=std::numeric_limits< Size >::max())
void setRange(Size min_range, Size max_range)
sets the range of records taken into account by the counter
const std::vector< Idx, IdSetAlloc > __empty_conditioning_set
an empty conditioning set
std::vector< bool > __is_cached_score
indicates whether the ith nodeset&#39;s score is in the cache or not
void useCache(bool on_off) noexcept
turn on/off the use of a cache of the previously computed score
bool _isInCache(Idx nodeset_index) const noexcept
indicates whether a score belongs to the cache
double _cachedScore(Idx nodeset_index) const noexcept
returns a cached score
bool _isUsingCache() const noexcept
indicates whether we use the cache or not
unsigned long Idx
Type for indexes.
Definition: types.h:43
Cache4PartEntropy __cache
a cache for the previously computed scores