27 #ifndef GUM_LEARNING_SCORE_H 28 #define GUM_LEARNING_SCORE_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 >
83 Score(
const DBRowGeneratorParser< ALLOC >& parser,
84 const Apriori< ALLOC >& external_apriori,
85 const std::vector< std::pair< std::size_t, std::size_t >,
86 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
108 Score(
const DBRowGeneratorParser< ALLOC >& parser,
109 const Apriori< ALLOC >& external_apriori,
158 template <
template <
typename >
class XALLOC >
160 const std::vector< std::pair< std::size_t, std::size_t >,
161 XALLOC< std::pair< std::size_t, std::size_t > > >& new_ranges);
172 double score(
const NodeId var);
251 Score(
const Score< ALLOC >& from);
254 Score(
const Score< ALLOC >& from,
const allocator_type& alloc);
257 Score(Score< ALLOC >&& from);
260 Score(Score< ALLOC >&& from,
const allocator_type& alloc);
272 virtual double score_(
const IdCondSet< ALLOC >& idset) = 0;
288 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 289 extern template class gum::learning::Score<>;
294 #include <agrum/BN/learning/scores_and_tests/score_tpl.h> const DatabaseTable< ALLOC > & database() const
return the database used by the score
double score(const NodeId var)
returns the score of a single node
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 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
Score(Score< ALLOC > &&from)
move constructor
bool use_cache_
a Boolean indicating whether we wish to use the cache
Score(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
INLINE void emplace(Args &&... args)
virtual void setMaxNbThreads(std::size_t nb) const
changes the max number of threads used to parse the database
Score(Score< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
virtual std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
Score(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
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 std::size_t nbThreads() const
returns the number of threads used to parse the database
ScoringCache< ALLOC > cache_
the scoring cache
std::vector< double, ALLOC< double > > marginalize_(const NodeId X_id, const std::vector< double, ALLOC< double > > &N_xyz) const
returns a counting vector where variables are marginalized from N_xyz
virtual ~Score()
destructor
Score< ALLOC > & operator=(const Score< ALLOC > &from)
copy operator
void clear()
clears all the data structures from memory, including the cache
virtual const Apriori< ALLOC > & internalApriori() const =0
returns the internal apriori of the score
RecordCounter< ALLOC > counter_
the record counter used for the countings over discrete variables
Apriori< ALLOC > * apriori_
the expert knowledge a priori we add to the score
bool isUsingCache() const
indicates whether the score uses a cache
double score(const NodeId var, const std::vector< NodeId, ALLOC< NodeId > > &rhs_ids)
returns the score of a single node given some other nodes
Score< ALLOC > & operator=(Score< ALLOC > &&from)
move operator
void clearCache()
clears the current cache
virtual std::string isAprioriCompatible() const =0
indicates whether the apriori is compatible (meaningful) with the score
void useCache(const bool on_off)
turn on/off the use of a cache of the previously computed score
void clearRanges()
reset the ranges to the one range corresponding to the whole database
virtual Score< ALLOC > * clone(const allocator_type &alloc) const =0
virtual copy constructor with a given allocator
allocator_type getAllocator() const
returns the allocator used by the score
const double one_log2_
1 / log(2)
virtual void setMinNbRowsPerThread(const std::size_t nb) const
changes the number min of rows a thread should process in a multithreading context ...
virtual double score_(const IdCondSet< ALLOC > &idset)=0
returns the score for a given IdCondSet
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
virtual Score< ALLOC > * clone() const =0
virtual copy constructor
Score(const Score< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
Score(const Score< ALLOC > &from)
copy constructor