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) {
54 GUM_CONSTRUCTOR(
Score);
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 > >&
68 GUM_CONSTRUCTOR(
Score);
73 template <
template <
typename >
class ALLOC >
75 const Score< ALLOC >& from,
85 template <
template <
typename >
class ALLOC >
91 template <
template <
typename >
class ALLOC >
93 Score< ALLOC >&& from,
98 from._apriori =
nullptr;
104 template <
template <
typename >
class ALLOC >
110 template <
template <
typename >
class ALLOC >
113 ALLOC< Apriori< ALLOC > > allocator(this->
getAllocator());
117 GUM_DESTRUCTOR(
Score);
122 template <
template <
typename >
class ALLOC >
125 Apriori< ALLOC >* new_apriori = from._apriori->clone();
126 RecordCounter< ALLOC > new_counter = from._counter;
127 ScoringCache< ALLOC > new_cache = from._cache;
130 ALLOC< Apriori< ALLOC > > allocator(this->
getAllocator());
137 _cache = std::move(new_cache);
146 template <
template <
typename >
class ALLOC >
151 _counter = std::move(from._counter);
152 _cache = std::move(from._cache);
160 template <
template <
typename >
class ALLOC >
167 template <
template <
typename >
class ALLOC >
175 template <
template <
typename >
class ALLOC >
182 template <
template <
typename >
class ALLOC >
184 return _counter.minNbRowsPerThread();
195 template <
template <
typename >
class ALLOC >
196 template <
template <
typename >
class XALLOC >
198 const std::vector< std::pair< std::size_t, std::size_t >,
199 XALLOC< std::pair< std::size_t, std::size_t > > >&
201 std::vector< std::pair< std::size_t, std::size_t >,
202 ALLOC< std::pair< std::size_t, std::size_t > > >
210 template <
template <
typename >
class ALLOC >
212 std::vector< std::pair< std::size_t, std::size_t >,
213 ALLOC< std::pair< std::size_t, std::size_t > > >
221 template <
template <
typename >
class ALLOC >
222 INLINE
const std::vector< std::pair< std::size_t, std::size_t >,
223 ALLOC< std::pair< std::size_t, std::size_t > > >&
230 template <
template <
typename >
class ALLOC >
235 return _cache.score(idset);
236 }
catch (NotFound&) {}
237 double the_score =
_score(idset);
238 _cache.insert(std::move(idset), the_score);
241 return _score(std::move(idset));
250 template <
template <
typename >
class ALLOC >
252 const NodeId var,
const std::vector<
NodeId, ALLOC< NodeId > >& rhs_ids) {
253 IdSet< ALLOC > idset(var, rhs_ids,
false, this->
getAllocator());
256 return _cache.score(idset);
257 }
catch (NotFound&) {}
258 double the_score =
_score(idset);
259 _cache.insert(std::move(idset), the_score);
268 template <
template <
typename >
class ALLOC >
276 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 >
315 template <
template <
typename >
class ALLOC >
318 const std::vector<
double, ALLOC< double > >& N_xyz)
const {
321 const auto& nodeId2cols = this->
_counter.nodeId2Columns();
323 const std::size_t X_size =
database.domainSize(
324 nodeId2cols.empty() ? X_id : nodeId2cols.second(X_id));
327 std::size_t out_size = N_xyz.size() / X_size;
330 std::vector< double, ALLOC< double > > res(out_size, 0.0);
333 std::size_t xyz = std::size_t(0);
334 for (std::size_t z = std::size_t(0); z < out_size; ++z) {
335 for (std::size_t x = std::size_t(0); x < X_size; ++x, ++xyz) {
336 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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.