29 #ifndef DOXYGEN_SHOULD_SKIP_THIS 39 template <
template <
typename >
class ALLOC >
41 const DBRowGeneratorParser< ALLOC >& parser,
42 const Apriori< ALLOC >& apriori,
43 const std::vector< std::pair< std::size_t, std::size_t >,
44 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
45 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
48 Score< ALLOC >(parser, apriori, ranges, nodeId2columns, alloc),
49 __internal_apriori(parser.database(), nodeId2columns) {
55 template <
template <
typename >
class ALLOC >
57 const DBRowGeneratorParser< ALLOC >& parser,
58 const Apriori< ALLOC >& apriori,
59 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
62 Score< ALLOC >(parser, apriori, nodeId2columns, alloc),
63 __internal_apriori(parser.
database(), nodeId2columns) {
69 template <
template <
typename >
class ALLOC >
71 const ScoreBD< ALLOC >& from,
73 Score< ALLOC >(from, alloc),
74 __internal_apriori(from.__internal_apriori, alloc),
75 __gammalog2(from.__gammalog2) {
81 template <
template <
typename >
class ALLOC >
87 template <
template <
typename >
class ALLOC >
89 ScoreBD< ALLOC >&& from,
91 Score< ALLOC >(
std::move(from), alloc),
92 __internal_apriori(
std::move(from.__internal_apriori), alloc),
93 __gammalog2(
std::move(from.__gammalog2)) {
99 template <
template <
typename >
class ALLOC >
105 template <
template <
typename >
class ALLOC >
108 ALLOC< ScoreBD< ALLOC > > allocator(alloc);
109 ScoreBD< ALLOC >* new_score = allocator.allocate(1);
111 allocator.construct(new_score, *
this, alloc);
113 allocator.deallocate(new_score, 1);
122 template <
template <
typename >
class ALLOC >
129 template <
template <
typename >
class ALLOC >
136 template <
template <
typename >
class ALLOC >
140 __internal_apriori = from.__internal_apriori;
147 template <
template <
typename >
class ALLOC >
151 __internal_apriori = std::move(from.__internal_apriori);
158 template <
template <
typename >
class ALLOC >
163 return "The BD score requires an apriori";
167 return "The apriori is currently compatible with the BD score but if " 168 "you change the weight, it may become biased";
172 std::stringstream msg;
173 msg <<
"The apriori '" << apriori_type
174 <<
"' is not yet supported by method isAprioriCompatible";
180 template <
template <
typename >
class ALLOC >
188 template <
template <
typename >
class ALLOC >
195 template <
template <
typename >
class ALLOC >
197 return __internal_apriori;
202 template <
template <
typename >
class ALLOC >
205 if (!this->
_apriori->isInformative()) {
207 "The BD score requires its external apriori to " 208 <<
"be strictly positive");
212 std::vector< double, ALLOC< double > > N_ijk(
213 this->
_counter.counts(idset,
true));
214 const std::size_t all_size = N_ijk.size();
215 std::vector< double, ALLOC< double > > N_prime_ijk(all_size, 0.0);
216 this->
_apriori->addAllApriori(idset, N_prime_ijk);
222 if (idset.hasConditioningSet()) {
224 std::vector< double, ALLOC< double > > N_ij(
226 const std::size_t conditioning_size = N_ij.size();
228 std::vector< double, ALLOC< double > > N_prime_ij(N_ij.size(), 0.0);
229 this->
_apriori->addConditioningApriori(idset, N_prime_ij);
235 for (std::size_t j = std::size_t(0); j < conditioning_size; ++j) {
237 __gammalog2(N_prime_ij[j]) - __gammalog2(N_ij[j] + N_prime_ij[j]);
239 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
241 __gammalog2(N_ijk[k] + N_prime_ijk[k]) - __gammalog2(N_prime_ijk[k]);
248 double N_prime = 0.0;
249 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
251 __gammalog2(N_ijk[k] + N_prime_ijk[k]) - __gammalog2(N_prime_ijk[k]);
253 N_prime += N_prime_ijk[k];
255 score += __gammalog2(N_prime) - __gammalog2(N + N_prime);
virtual const Apriori< ALLOC > & internalApriori() const final
returns the internal apriori of the score
const DatabaseTable< ALLOC > & database() const
return the database used by the score
double score(const NodeId var)
returns the score of a single node
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
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
static const std::string type
ScoreBD(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
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
virtual ~ScoreBD()
destructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
ScoreBD< ALLOC > & operator=(const ScoreBD< ALLOC > &from)
copy operator
Score< ALLOC > & operator=(const Score< ALLOC > &from)
copy operator
virtual std::string isAprioriCompatible() const final
indicates whether the apriori is compatible (meaningful) with the score
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
allocator_type getAllocator() const
returns the allocator used by the score
virtual ScoreBD< ALLOC > * clone() const
virtual copy constructor
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
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)