30 #ifndef DOXYGEN_SHOULD_SKIP_THIS 37 template <
template <
typename >
class ALLOC >
39 const DBRowGeneratorParser< ALLOC >& parser,
40 const Apriori< ALLOC >& apriori,
41 const std::vector< std::pair< std::size_t, std::size_t >,
42 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
43 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
46 IndependenceTest< ALLOC >(parser, apriori, ranges, nodeId2columns, alloc),
47 __param_complexity(alloc) {
48 GUM_CONSTRUCTOR(
KNML);
53 template <
template <
typename >
class ALLOC >
55 const DBRowGeneratorParser< ALLOC >& parser,
56 const Apriori< ALLOC >& apriori,
57 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
61 __param_complexity(alloc) {
62 GUM_CONSTRUCTOR(
KNML);
67 template <
template <
typename >
class ALLOC >
72 __param_complexity(from.__param_complexity, alloc) {
78 template <
template <
typename >
class ALLOC >
84 template <
template <
typename >
class ALLOC >
89 __param_complexity(
std::move(from.__param_complexity), alloc) {
95 template <
template <
typename >
class ALLOC >
101 template <
template <
typename >
class ALLOC >
104 ALLOC< KNML< ALLOC > > allocator(alloc);
105 KNML< ALLOC >* new_score = allocator.allocate(1);
107 allocator.construct(new_score, *
this, alloc);
109 allocator.deallocate(new_score, 1);
118 template <
template <
typename >
class ALLOC >
125 template <
template <
typename >
class ALLOC >
127 GUM_DESTRUCTOR(
KNML);
132 template <
template <
typename >
class ALLOC >
136 __param_complexity = from.__param_complexity;
143 template <
template <
typename >
class ALLOC >
147 __param_complexity = std::move(from.__param_complexity);
154 template <
template <
typename >
class ALLOC >
157 __param_complexity.clearCache();
162 template <
template <
typename >
class ALLOC >
165 __param_complexity.clearCache();
170 template <
template <
typename >
class ALLOC >
173 __param_complexity.useCache(on_off);
178 template <
template <
typename >
class ALLOC >
185 const bool informative_external_apriori = this->
_apriori->isInformative();
190 std::size_t r_x, r_y;
191 if (!node2cols.empty()) {
192 r_x = db.domainSize(node2cols.second(idset[0]));
193 r_y = db.domainSize(node2cols.second(idset[1]));
195 r_x = db.domainSize(idset[0]);
196 r_y = db.domainSize(idset[1]);
202 if (idset.hasConditioningSet()) {
204 IdSet< ALLOC > idset_xui = idset;
205 idset_xui.erase(idset[1]);
206 IdSet< ALLOC > idset_yui = idset;
207 idset_yui.erase(idset[0]);
209 std::vector< double, ALLOC< double > > N_ui =
210 this->
_counter.counts(idset.conditionalIdSet(),
false);
211 std::vector< double, ALLOC< double > > N_xui =
212 this->
_counter.counts(idset_xui,
false);
213 std::vector< double, ALLOC< double > > N_yui =
214 this->
_counter.counts(idset_yui,
false);
216 if (informative_external_apriori) {
217 this->
_apriori->addConditioningApriori(idset, N_ui);
218 this->
_apriori->addAllApriori(idset, N_xui);
219 this->
_apriori->addAllApriori(idset, N_yui);
227 for (
auto n_xui : N_xui)
228 score += __param_complexity.log2Cnr(r_y, n_xui);
229 for (
auto n_yui : N_yui)
230 score += __param_complexity.log2Cnr(r_x, n_yui);
231 for (
auto n_ui : N_ui) {
232 score -= __param_complexity.log2Cnr(r_y, n_ui);
233 score -= __param_complexity.log2Cnr(r_x, n_ui);
242 IdSet< ALLOC > idset_xui(idset[0], this->
_empty_ids,
true);
243 IdSet< ALLOC > idset_yui(idset[1], this->
_empty_ids,
true);
245 std::vector< double, ALLOC< double > > N_xui =
246 this->
_counter.counts(idset_xui,
false);
247 std::vector< double, ALLOC< double > > N_yui =
248 this->
_counter.counts(idset_yui,
false);
250 if (informative_external_apriori) {
251 this->
_apriori->addAllApriori(idset, N_xui);
252 this->
_apriori->addAllApriori(idset, N_yui);
261 for (
auto n_xui : N_xui) {
262 score += __param_complexity.log2Cnr(r_y, n_xui);
265 for (
auto n_yui : N_yui)
266 score += __param_complexity.log2Cnr(r_x, n_yui);
267 score -= __param_complexity.log2Cnr(r_y, N);
268 score -= __param_complexity.log2Cnr(r_x, N);
RecordCounter< ALLOC > _counter
the record counter used for the countings over discrete variables
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
virtual void clear()
clears all the data structures from memory, including the C_n^r cache
virtual ~KNML()
destructor
IndependenceTest< ALLOC > & operator=(const IndependenceTest< ALLOC > &from)
copy operator
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
double score(const NodeId var1, const NodeId var2)
returns the score of a pair of nodes
virtual void clearCache()
clears the current C_n^r cache
KNML< ALLOC > & operator=(const KNML< ALLOC > &from)
copy operator
virtual void useCache(const bool on_off)
turn on/off the use of a cache of the previously computed score
virtual void useCache(const bool on_off)
turn on/off the use of the C_n^r cache
virtual KNML< ALLOC > * clone() const
virtual copy constructor
Size NodeId
Type for node ids.
virtual void clear()
clears all the data structures from memory, including the cache
KNML(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &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
Apriori< ALLOC > * _apriori
the expert knowledge a priori we add to the contongency tables