25 #ifndef DOXYGEN_SHOULD_SKIP_THIS 32 template <
template <
typename >
class ALLOC >
35 return _counter.getAllocator();
40 template <
template <
typename >
class ALLOC >
42 const DBRowGeneratorParser< ALLOC >& parser,
43 const Apriori< ALLOC >& apriori,
44 const std::vector< std::pair< std::size_t, std::size_t >,
45 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
46 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
49 _apriori(apriori.clone(alloc)),
50 _counter(parser, ranges, nodeId2columns, alloc), _cache(alloc) {
51 GUM_CONSTRUCTOR(
Score);
56 template <
template <
typename >
class ALLOC >
58 const DBRowGeneratorParser< ALLOC >& parser,
59 const Apriori< ALLOC >& apriori,
60 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
65 GUM_CONSTRUCTOR(
Score);
70 template <
template <
typename >
class ALLOC >
72 const Score< ALLOC >& from,
82 template <
template <
typename >
class ALLOC >
88 template <
template <
typename >
class ALLOC >
90 Score< ALLOC >&& from,
95 from._apriori =
nullptr;
101 template <
template <
typename >
class ALLOC >
107 template <
template <
typename >
class ALLOC >
110 ALLOC< Apriori< ALLOC > > allocator(this->
getAllocator());
114 GUM_DESTRUCTOR(
Score);
119 template <
template <
typename >
class ALLOC >
122 Apriori< ALLOC >* new_apriori = from._apriori->clone();
123 RecordCounter< ALLOC > new_counter = from._counter;
124 ScoringCache< ALLOC > new_cache = from._cache;
127 ALLOC< Apriori< ALLOC > > allocator(this->
getAllocator());
134 _cache = std::move(new_cache);
143 template <
template <
typename >
class ALLOC >
148 _counter = std::move(from._counter);
149 _cache = std::move(from._cache);
157 template <
template <
typename >
class ALLOC >
164 template <
template <
typename >
class ALLOC >
172 template <
template <
typename >
class ALLOC >
179 template <
template <
typename >
class ALLOC >
181 return _counter.minNbRowsPerThread();
192 template <
template <
typename >
class ALLOC >
193 template <
template <
typename >
class XALLOC >
195 const std::vector< std::pair< std::size_t, std::size_t >,
196 XALLOC< std::pair< std::size_t, std::size_t > > >&
198 std::vector< std::pair< std::size_t, std::size_t >,
199 ALLOC< std::pair< std::size_t, std::size_t > > >
207 template <
template <
typename >
class ALLOC >
209 std::vector< std::pair< std::size_t, std::size_t >,
210 ALLOC< std::pair< std::size_t, std::size_t > > >
218 template <
template <
typename >
class ALLOC >
219 INLINE
const std::vector< std::pair< std::size_t, std::size_t >,
220 ALLOC< std::pair< std::size_t, std::size_t > > >&
227 template <
template <
typename >
class ALLOC >
232 return _cache.score(idset);
233 }
catch (NotFound&) {}
234 double the_score =
_score(idset);
235 _cache.insert(std::move(idset), the_score);
238 return _score(std::move(idset));
247 template <
template <
typename >
class ALLOC >
249 const NodeId var,
const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids) {
250 IdSet< ALLOC > idset(var, rhs_ids,
false, this->
getAllocator());
253 return _cache.score(idset);
254 }
catch (NotFound&) {}
255 double the_score =
_score(idset);
256 _cache.insert(std::move(idset), the_score);
265 template <
template <
typename >
class ALLOC >
273 template <
template <
typename >
class ALLOC >
280 template <
template <
typename >
class ALLOC >
287 template <
template <
typename >
class ALLOC >
294 template <
template <
typename >
class ALLOC >
295 INLINE
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
302 template <
template <
typename >
class ALLOC >
312 template <
template <
typename >
class ALLOC >
315 const std::vector<
double, ALLOC< double > >& N_xyz)
const {
318 const auto& nodeId2cols = this->
_counter.nodeId2Columns();
320 const std::size_t X_size =
database.domainSize(
321 nodeId2cols.empty() ? X_id : nodeId2cols.second(X_id));
324 std::size_t out_size = N_xyz.size() / X_size;
327 std::vector< double, ALLOC< double > > res(out_size, 0.0);
330 std::size_t xyz = std::size_t(0);
331 for (std::size_t z = std::size_t(0); z < out_size; ++z) {
332 for (std::size_t x = std::size_t(0); x < X_size; ++x, ++xyz) {
333 res[z] += N_xyz[xyz];
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(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
virtual void setMaxNbThreads(std::size_t nb) const
changes the max number of threads used to parse the database
virtual std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
gum is the global namespace for all aGrUM entities
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
ScoringCache< ALLOC > _cache
the scoring cache
const std::vector< NodeId, ALLOC< NodeId > > _empty_ids
an empty vector
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 std::size_t nbThreads() const
returns the number of threads used to parse the database
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 double _score(const IdSet< ALLOC > &idset)=0
returns the score for a given IdSet
bool isUsingCache() const
indicates whether the score uses a cache
void clearCache()
clears the current cache
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
allocator_type getAllocator() const
returns the allocator used by the score
bool _use_cache
a Boolean indicating whether we wish to use the cache
virtual void setMinNbRowsPerThread(const std::size_t nb) const
changes the number min of rows a thread should process in a multithreading context ...
Apriori< ALLOC > * _apriori
the expert knowledge a priori we add to the score
RecordCounter< ALLOC > _counter
the record counter used for the countings over discrete variables
virtual Score< ALLOC > * clone() const =0
virtual copy constructor
Size NodeId
Type for node ids.