28 #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 template <
template <
typename >
class ALLOC >
38 return _counter.getAllocator();
43 template <
template <
typename >
class ALLOC >
45 const DBRowGeneratorParser< ALLOC >& parser,
46 const Apriori< ALLOC >& apriori,
47 const std::vector< std::pair< std::size_t, std::size_t >,
48 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
49 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
52 _apriori(apriori.clone(alloc)),
53 _counter(parser, ranges, nodeId2columns, alloc), _cache(alloc) {
59 template <
template <
typename >
class ALLOC >
61 const DBRowGeneratorParser< ALLOC >& parser,
62 const Apriori< ALLOC >& apriori,
63 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
73 template <
template <
typename >
class ALLOC >
75 const IndependenceTest< ALLOC >& from,
85 template <
template <
typename >
class ALLOC >
87 const IndependenceTest< ALLOC >& from) :
92 template <
template <
typename >
class ALLOC >
94 IndependenceTest< ALLOC >&& from,
99 from._apriori =
nullptr;
105 template <
template <
typename >
class ALLOC >
107 IndependenceTest< ALLOC >&& from) :
112 template <
template <
typename >
class ALLOC >
115 ALLOC< Apriori< ALLOC > > allocator(this->
getAllocator());
124 template <
template <
typename >
class ALLOC >
126 operator=(
const IndependenceTest< ALLOC >& from) {
128 Apriori< ALLOC >* new_apriori = from._apriori->clone();
129 RecordCounter< ALLOC > new_counter = from._counter;
130 ScoringCache< ALLOC > new_cache = from._cache;
133 ALLOC< Apriori< ALLOC > > allocator(this->
getAllocator());
140 _cache = std::move(new_cache);
149 template <
template <
typename >
class ALLOC >
151 operator=(IndependenceTest< ALLOC >&& from) {
155 _counter = std::move(from._counter);
156 _cache = std::move(from._cache);
164 template <
template <
typename >
class ALLOC >
171 template <
template <
typename >
class ALLOC >
179 template <
template <
typename >
class ALLOC >
181 const std::size_t nb)
const {
187 template <
template <
typename >
class ALLOC >
189 return _counter.minNbRowsPerThread();
200 template <
template <
typename >
class ALLOC >
201 template <
template <
typename >
class XALLOC >
203 const std::vector< std::pair< std::size_t, std::size_t >,
204 XALLOC< std::pair< std::size_t, std::size_t > > >&
206 std::vector< std::pair< std::size_t, std::size_t >,
207 ALLOC< std::pair< std::size_t, std::size_t > > >
215 template <
template <
typename >
class ALLOC >
217 std::vector< std::pair< std::size_t, std::size_t >,
218 ALLOC< std::pair< std::size_t, std::size_t > > >
226 template <
template <
typename >
class ALLOC >
227 INLINE
const std::vector< std::pair< std::size_t, std::size_t >,
228 ALLOC< std::pair< std::size_t, std::size_t > > >&
235 template <
template <
typename >
class ALLOC >
238 IdSet< ALLOC > idset(
242 return _cache.score(idset);
243 }
catch (NotFound&) {}
244 double the_score =
_score(idset);
245 _cache.insert(std::move(idset), the_score);
248 return _score(std::move(idset));
254 template <
template <
typename >
class ALLOC >
258 const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids) {
259 IdSet< ALLOC > idset(
260 var1, var2, rhs_ids,
false,
false, this->
getAllocator());
263 return _cache.score(idset);
264 }
catch (NotFound&) {}
265 double the_score =
_score(idset);
266 _cache.insert(std::move(idset), the_score);
275 template <
template <
typename >
class ALLOC >
283 template <
template <
typename >
class ALLOC >
290 template <
template <
typename >
class ALLOC >
297 template <
template <
typename >
class ALLOC >
298 INLINE
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
305 template <
template <
typename >
class ALLOC >
306 INLINE
const DatabaseTable< ALLOC >&
318 template <
template <
typename >
class ALLOC >
320 const std::size_t node_2_marginalize,
321 const std::size_t X_size,
322 const std::size_t Y_size,
323 const std::size_t Z_size,
324 const std::vector<
double, ALLOC< double > >& N_xyz)
const {
326 std::size_t out_size = Z_size;
327 if (node_2_marginalize == std::size_t(0))
329 else if (node_2_marginalize == std::size_t(1))
333 std::vector< double, ALLOC< double > > res(out_size, 0.0);
336 if (node_2_marginalize == std::size_t(0)) {
337 for (std::size_t yz = std::size_t(0), xyz = std::size_t(0); yz < out_size;
339 for (std::size_t x = std::size_t(0); x < X_size; ++x, ++xyz) {
340 res[yz] += N_xyz[xyz];
343 }
else if (node_2_marginalize == std::size_t(1)) {
344 for (std::size_t z = std::size_t(0),
345 xyz = std::size_t(0),
346 beg_xz = std::size_t(0);
348 ++z, beg_xz += X_size) {
349 for (std::size_t y = std::size_t(0); y < Y_size; ++y) {
350 for (std::size_t x = std::size_t(0), xz = beg_xz; x < X_size;
352 res[xz] += N_xyz[xyz];
356 }
else if (node_2_marginalize == std::size_t(2)) {
357 const std::size_t XY_size = X_size * Y_size;
358 for (std::size_t z = std::size_t(0), xyz = std::size_t(0); z < out_size;
360 for (std::size_t xy = std::size_t(0); xy < XY_size; ++xy, ++xyz) {
361 res[z] += N_xyz[xyz];
366 "_marginalize not implemented for nodeset " 367 << node_2_marginalize);
ScoringCache< ALLOC > _cache
the scoring cache
std::vector< double, ALLOC< double > > _marginalize(const std::size_t node_2_marginalize, const std::size_t X_size, const std::size_t Y_size, const std::size_t Z_size, const std::vector< double, ALLOC< double > > &N_xyz) const
returns a counting vector where variables are marginalized from N_xyz
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
RecordCounter< ALLOC > _counter
the record counter used for the countings over discrete variables
virtual std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
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
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
virtual void clearCache()
clears the current cache
const DatabaseTable< ALLOC > & database() const
return the database used by the score
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > & nodeId2Columns() const
return the mapping between the columns of the database and the node ids
virtual void setMinNbRowsPerThread(const std::size_t nb) const
changes the number min of rows a thread should process in a multithreading context ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual double _score(const IdSet< ALLOC > &idset)=0
returns the score for a given IdSet
const std::vector< NodeId, ALLOC< NodeId > > _empty_ids
an empty vector
IndependenceTest(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &external_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
allocator_type getAllocator() const
returns the allocator used by the score
void clearRanges()
reset the ranges to the one range corresponding to the whole database
virtual IndependenceTest< ALLOC > * clone() const =0
virtual copy constructor
virtual void setMaxNbThreads(std::size_t nb) const
changes the max number of threads used to parse the database
IndependenceTest< ALLOC > & operator=(const IndependenceTest< ALLOC > &from)
copy operator
double score(const NodeId var1, const NodeId var2)
returns the score of a pair of nodes
virtual ~IndependenceTest()
destructor
bool _use_cache
a Boolean indicating whether we wish to use the cache
virtual void useCache(const bool on_off)
turn on/off the use of a cache of the previously computed score
virtual std::size_t nbThreads() const
returns the number of threads used to parse the database
Size NodeId
Type for node ids.
virtual void clear()
clears all the data structures from memory, including the cache
#define GUM_ERROR(type, msg)
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 independence test
Apriori< ALLOC > * _apriori
the expert knowledge a priori we add to the contongency tables