26 #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 template <
template <
typename >
class ALLOC >
37 const DBRowGeneratorParser< ALLOC >& parser,
38 const Apriori< ALLOC >& apriori,
39 const std::vector< std::pair< std::size_t, std::size_t >,
40 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
41 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
44 Score< ALLOC >(parser, apriori, ranges, nodeId2columns, alloc),
45 __internal_apriori(parser.database(), nodeId2columns) {
51 template <
template <
typename >
class ALLOC >
53 const DBRowGeneratorParser< ALLOC >& parser,
54 const Apriori< ALLOC >& apriori,
55 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
58 Score< ALLOC >(parser, apriori, nodeId2columns, alloc),
59 __internal_apriori(parser.
database(), nodeId2columns) {
65 template <
template <
typename >
class ALLOC >
67 const ScorefNML< ALLOC >& from,
69 Score< ALLOC >(from, alloc),
70 __internal_apriori(from.__internal_apriori, alloc) {
76 template <
template <
typename >
class ALLOC >
82 template <
template <
typename >
class ALLOC >
84 ScorefNML< ALLOC >&& from,
86 Score< ALLOC >(
std::move(from), alloc),
87 __internal_apriori(
std::move(from.__internal_apriori), alloc) {
93 template <
template <
typename >
class ALLOC >
99 template <
template <
typename >
class ALLOC >
102 ALLOC< ScorefNML< ALLOC > > allocator(alloc);
103 ScorefNML< ALLOC >* new_score = allocator.allocate(1);
105 allocator.construct(new_score, *
this, alloc);
107 allocator.deallocate(new_score, 1);
116 template <
template <
typename >
class ALLOC >
123 template <
template <
typename >
class ALLOC >
130 template <
template <
typename >
class ALLOC >
132 operator=(
const ScorefNML< ALLOC >& from) {
135 __internal_apriori = from.__internal_apriori;
142 template <
template <
typename >
class ALLOC >
146 __internal_apriori = std::move(from.__internal_apriori);
153 template <
template <
typename >
class ALLOC >
165 std::stringstream msg;
166 msg <<
"The apriori '" << apriori_type
167 <<
"' is not yet supported by method isAprioriCompatible os Score fNML";
173 template <
template <
typename >
class ALLOC >
181 template <
template <
typename >
class ALLOC >
188 template <
template <
typename >
class ALLOC >
190 return __internal_apriori;
195 template <
template <
typename >
class ALLOC >
198 std::vector< double, ALLOC< double > > N_ijk(
199 this->
_counter.counts(idset,
true));
200 const bool informative_external_apriori = this->
_apriori->isInformative();
201 if (informative_external_apriori)
202 this->
_apriori->addAllApriori(idset, N_ijk);
203 const std::size_t all_size = N_ijk.size();
207 if (idset.hasConditioningSet()) {
209 std::vector< double, ALLOC< double > > N_ij(
211 const std::size_t target_domsize = all_size / N_ij.size();
218 for (
const auto n_ijk : N_ijk) {
219 if (n_ijk) { score += n_ijk * std::log(n_ijk); }
221 for (
const auto n_ij : N_ij) {
222 if (n_ij) { score -= n_ij * std::log(n_ij); }
229 double penalty = 0.0;
230 for (
const auto n_ij : N_ij) {
231 penalty += __ctable.log2Cnr(target_domsize, n_ij);
246 for (
const auto n_ijk : N_ijk) {
248 score += n_ijk * std::log(n_ijk);
252 score -= N * std::log(N);
258 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
the class for computing fNML scores
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
gum is the global namespace for all aGrUM entities
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.