29 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 template <
template <
typename >
class ALLOC >
40 const DBRowGeneratorParser< ALLOC >& parser,
41 const Apriori< ALLOC >& apriori,
42 const std::vector< std::pair< std::size_t, std::size_t >,
43 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
44 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
47 Score< ALLOC >(parser, apriori, ranges, nodeId2columns, alloc),
48 __internal_apriori(parser.database(), nodeId2columns) {
54 template <
template <
typename >
class ALLOC >
56 const DBRowGeneratorParser< ALLOC >& parser,
57 const Apriori< ALLOC >& apriori,
58 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
61 Score< ALLOC >(parser, apriori, nodeId2columns, alloc),
62 __internal_apriori(parser.
database(), nodeId2columns) {
68 template <
template <
typename >
class ALLOC >
70 const ScorefNML< ALLOC >& from,
72 Score< ALLOC >(from, alloc),
73 __internal_apriori(from.__internal_apriori, alloc) {
79 template <
template <
typename >
class ALLOC >
85 template <
template <
typename >
class ALLOC >
87 ScorefNML< ALLOC >&& from,
89 Score< ALLOC >(
std::move(from), alloc),
90 __internal_apriori(
std::move(from.__internal_apriori), alloc) {
96 template <
template <
typename >
class ALLOC >
102 template <
template <
typename >
class ALLOC >
105 ALLOC< ScorefNML< ALLOC > > allocator(alloc);
106 ScorefNML< ALLOC >* new_score = allocator.allocate(1);
108 allocator.construct(new_score, *
this, alloc);
110 allocator.deallocate(new_score, 1);
119 template <
template <
typename >
class ALLOC >
126 template <
template <
typename >
class ALLOC >
133 template <
template <
typename >
class ALLOC >
135 operator=(
const ScorefNML< ALLOC >& from) {
138 __internal_apriori = from.__internal_apriori;
145 template <
template <
typename >
class ALLOC >
149 __internal_apriori = std::move(from.__internal_apriori);
156 template <
template <
typename >
class ALLOC >
168 std::stringstream msg;
169 msg <<
"The apriori '" << apriori_type
170 <<
"' is not yet supported by method isAprioriCompatible os Score fNML";
176 template <
template <
typename >
class ALLOC >
184 template <
template <
typename >
class ALLOC >
191 template <
template <
typename >
class ALLOC >
193 return __internal_apriori;
198 template <
template <
typename >
class ALLOC >
201 std::vector< double, ALLOC< double > > N_ijk(
202 this->
_counter.counts(idset,
true));
203 const bool informative_external_apriori = this->
_apriori->isInformative();
204 if (informative_external_apriori)
205 this->
_apriori->addAllApriori(idset, N_ijk);
206 const std::size_t all_size = N_ijk.size();
210 if (idset.hasConditioningSet()) {
212 std::vector< double, ALLOC< double > > N_ij(
214 const std::size_t target_domsize = all_size / N_ij.size();
221 for (
const auto n_ijk : N_ijk) {
222 if (n_ijk) { score += n_ijk * std::log(n_ijk); }
224 for (
const auto n_ij : N_ij) {
225 if (n_ij) { score -= n_ij * std::log(n_ij); }
232 double penalty = 0.0;
233 for (
const auto n_ij : N_ij) {
234 penalty += __ctable.log2Cnr(target_domsize, n_ij);
249 for (
const auto n_ijk : N_ijk) {
251 score += n_ijk * std::log(n_ijk);
255 score -= N * std::log(N);
261 score -= __ctable.log2Cnr(all_size, N);
const DatabaseTable< ALLOC > & database() const
return the database used by the score
double score(const NodeId var)
returns the score of a single node
virtual std::string isAprioriCompatible() const final
indicates whether the apriori is compatible (meaningful) with the score
static const std::string type
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual ScorefNML< ALLOC > * clone() const
virtual copy constructor
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)
virtual ~ScorefNML()
destructor
virtual const Apriori< ALLOC > & internalApriori() const final
returns the internal apriori of the score
ScorefNML(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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
ScorefNML< ALLOC > & operator=(const ScorefNML< ALLOC > &from)
copy operator
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
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
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
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
Size NodeId
Type for node ids.