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 ScoreAIC< ALLOC >& from,
73 Score< ALLOC >(from, alloc),
74 __internal_apriori(from.__internal_apriori, alloc) {
80 template <
template <
typename >
class ALLOC >
86 template <
template <
typename >
class ALLOC >
88 ScoreAIC< ALLOC >&& from,
90 Score< ALLOC >(
std::move(from), alloc),
91 __internal_apriori(
std::move(from.__internal_apriori), alloc) {
97 template <
template <
typename >
class ALLOC >
103 template <
template <
typename >
class ALLOC >
106 ALLOC< ScoreAIC< ALLOC > > allocator(alloc);
107 ScoreAIC< ALLOC >* new_score = allocator.allocate(1);
109 allocator.construct(new_score, *
this, alloc);
111 allocator.deallocate(new_score, 1);
120 template <
template <
typename >
class ALLOC >
127 template <
template <
typename >
class ALLOC >
134 template <
template <
typename >
class ALLOC >
136 operator=(
const ScoreAIC< ALLOC >& from) {
139 __internal_apriori = from.__internal_apriori;
146 template <
template <
typename >
class ALLOC >
150 __internal_apriori = std::move(from.__internal_apriori);
157 template <
template <
typename >
class ALLOC >
169 std::stringstream msg;
170 msg <<
"The apriori '" << apriori_type
171 <<
"' is not yet supported by method isAprioriCompatible os Score AIC";
177 template <
template <
typename >
class ALLOC >
185 template <
template <
typename >
class ALLOC >
192 template <
template <
typename >
class ALLOC >
194 return __internal_apriori;
199 template <
template <
typename >
class ALLOC >
202 std::vector< double, ALLOC< double > > N_ijk(
203 this->
_counter.counts(idset,
true));
204 const bool informative_external_apriori = this->
_apriori->isInformative();
205 if (informative_external_apriori)
206 this->
_apriori->addAllApriori(idset, N_ijk);
207 const std::size_t all_size = N_ijk.size();
211 if (idset.hasConditioningSet()) {
213 std::vector< double, ALLOC< double > > N_ij(
215 const std::size_t conditioning_size = N_ij.size();
219 const std::size_t target_domsize = all_size / conditioning_size;
220 const double penalty =
221 conditioning_size *
double(target_domsize - std::size_t(1));
228 for (
const auto n_ijk : N_ijk) {
229 if (n_ijk) { score += n_ijk * std::log(n_ijk); }
231 for (
const auto n_ij : N_ij) {
232 if (n_ij) { score -= n_ij * std::log(n_ij); }
247 const double penalty =
double(all_size - std::size_t(1));
255 for (
const auto n_ijk : N_ijk) {
257 score += n_ijk * std::log(n_ijk);
261 score -= N * std::log(N);
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
const DatabaseTable< ALLOC > & database() const
return the database used by the score
double score(const NodeId var)
returns the score of a single node
static const std::string type
virtual ~ScoreAIC()
destructor
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
const double _1log2
1 / log(2)
ScoreAIC< ALLOC > & operator=(const ScoreAIC< ALLOC > &from)
copy operator
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
virtual ScoreAIC< ALLOC > * clone() const
virtual copy constructor
virtual const Apriori< ALLOC > & internalApriori() const final
returns the internal apriori of the score
ScoreAIC(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
Score< ALLOC > & operator=(const Score< ALLOC > &from)
copy operator
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
allocator_type getAllocator() const
returns the allocator used by the score
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Apriori< ALLOC > * _apriori
the expert knowledge a priori we add to the score
static const std::string type
RecordCounter< ALLOC > _counter
the record counter used for the countings over discrete variables
virtual std::string isAprioriCompatible() const final
indicates whether the apriori is compatible (meaningful) with the score
Size NodeId
Type for node ids.