27 #ifndef GUM_LEARNING_INDEPENDENCE_TEST_H 28 #define GUM_LEARNING_INDEPENDENCE_TEST_H 32 #include <agrum/agrum.h> 33 #include <agrum/tools/core/math/math_utils.h> 34 #include <agrum/tools/core/OMPThreads.h> 36 #include <agrum/tools/stattests/recordCounter.h> 37 #include <agrum/BN/learning/scores_and_tests/scoringCache.h> 38 #include <agrum/BN/learning/aprioris/apriori.h> 39 #include <agrum/BN/learning/structureUtils/graphChange.h> 50 template <
template <
typename >
class ALLOC =
std::
allocator >
85 const Apriori< ALLOC >& external_apriori,
86 const std::vector< std::pair< std::size_t, std::size_t >,
87 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
111 const Apriori< ALLOC >& external_apriori,
160 template <
template <
typename >
class XALLOC >
162 const std::vector< std::pair< std::size_t, std::size_t >,
163 XALLOC< std::pair< std::size_t, std::size_t > > >& new_ranges);
175 double score(
const NodeId var1,
const NodeId var2);
182 double score(
const NodeId var1,
187 virtual void clear();
193 virtual void useCache(
const bool on_off);
234 IndependenceTest(
const IndependenceTest< ALLOC >& from,
const allocator_type& alloc);
240 IndependenceTest(IndependenceTest< ALLOC >&& from,
const allocator_type& alloc);
252 virtual double score_(
const IdCondSet< ALLOC >& idset) = 0;
277 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 278 extern template class gum::learning::IndependenceTest<>;
283 #include <agrum/tools/stattests/independenceTest_tpl.h> 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
IndependenceTest(const IndependenceTest< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
INLINE void emplace(Args &&... args)
IndependenceTest(const IndependenceTest< ALLOC > &from)
copy constructor
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
virtual double score_(const IdCondSet< ALLOC > &idset)=0
returns the score for a given IdCondSet
virtual void clearCache()
clears the current cache
IndependenceTest< ALLOC > & operator=(IndependenceTest< ALLOC > &&from)
move operator
ScoringCache< ALLOC > cache_
the scoring 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 ...
IndependenceTest(IndependenceTest< ALLOC > &&from)
move constructor
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
bool use_cache_
a Boolean indicating whether we wish to use the cache
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
IndependenceTest(IndependenceTest< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
double score(const NodeId var1, const NodeId var2, const std::vector< NodeId, ALLOC< NodeId > > &rhs_ids)
returns the score of a pair of nodes given some other nodes
double score(const NodeId var1, const NodeId var2)
returns the score of a pair of nodes
virtual ~IndependenceTest()
destructor
virtual IndependenceTest< ALLOC > * clone(const allocator_type &alloc) const =0
virtual copy constructor with a given allocator
const double one_log2_
1 / log(2)
RecordCounter< ALLOC > counter_
the record counter used for the countings over discrete variables
virtual void useCache(const bool on_off)
turn on/off the use of a cache of the previously computed score
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
virtual std::size_t nbThreads() const
returns the number of threads used to parse the database
IndependenceTest(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &external_apriori, 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
virtual void clear()
clears all the data structures from memory, including the cache
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 contingency tables