26 #ifndef DOXYGEN_SHOULD_SKIP_THIS 36 template <
template <
typename >
class ALLOC >
38 const DBRowGeneratorParser< ALLOC >& parser,
39 const Apriori< ALLOC >& apriori,
40 const std::vector< std::pair< std::size_t, std::size_t >,
41 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
42 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
45 Score< ALLOC >(parser, apriori, ranges, nodeId2columns, alloc),
46 __internal_apriori(parser.database(), nodeId2columns) {
52 template <
template <
typename >
class ALLOC >
54 const DBRowGeneratorParser< ALLOC >& parser,
55 const Apriori< ALLOC >& apriori,
56 const Bijection<
NodeId, std::size_t, ALLOC< std::size_t > >&
59 Score< ALLOC >(parser, apriori, nodeId2columns, alloc),
60 __internal_apriori(parser.
database(), nodeId2columns) {
66 template <
template <
typename >
class ALLOC >
68 const ScoreLog2Likelihood< ALLOC >& from,
70 Score< ALLOC >(from, alloc),
71 __internal_apriori(from.__internal_apriori, alloc) {
77 template <
template <
typename >
class ALLOC >
79 const ScoreLog2Likelihood< ALLOC >& from) :
84 template <
template <
typename >
class ALLOC >
86 ScoreLog2Likelihood< ALLOC >&& from,
88 Score< ALLOC >(
std::move(from), alloc),
89 __internal_apriori(
std::move(from.__internal_apriori), alloc) {
95 template <
template <
typename >
class ALLOC >
97 ScoreLog2Likelihood< ALLOC >&& from) :
102 template <
template <
typename >
class ALLOC >
105 ALLOC< ScoreLog2Likelihood< ALLOC > > allocator(alloc);
106 ScoreLog2Likelihood< 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 ScoreLog2Likelihood< ALLOC >& from) {
138 __internal_apriori = from.__internal_apriori;
145 template <
template <
typename >
class ALLOC >
147 operator=(ScoreLog2Likelihood< ALLOC >&& from) {
150 __internal_apriori = std::move(from.__internal_apriori);
157 template <
template <
typename >
class ALLOC >
159 const std::string& apriori_type,
double weight) {
168 std::stringstream msg;
169 msg <<
"The apriori '" << apriori_type
170 <<
"' is not yet supported by method isAprioriCompatible of " 171 <<
"Score Log2Likelihood";
177 template <
template <
typename >
class ALLOC >
179 const Apriori< ALLOC >& apriori) {
185 template <
template <
typename >
class ALLOC >
192 template <
template <
typename >
class ALLOC >
193 INLINE
const Apriori< ALLOC >&
195 return __internal_apriori;
200 template <
template <
typename >
class ALLOC >
203 std::vector< double, ALLOC< double > > N_ijk(
204 this->
_counter.counts(idset,
true));
205 const bool informative_external_apriori = this->
_apriori->isInformative();
206 if (informative_external_apriori)
207 this->
_apriori->addAllApriori(idset, N_ijk);
211 if (idset.hasConditioningSet()) {
213 std::vector< double, ALLOC< double > > N_ij(
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); }
241 for (
const auto n_ijk : N_ijk) {
243 score += n_ijk * std::log(n_ijk);
247 score -= N * std::log(N);
258 template <
template <
typename >
class ALLOC >
const DatabaseTable< ALLOC > & database() const
return the database used by the score
double score(const IdSet< ALLOC > &idset)
returns the score for a given IdSet
static const std::string type
the class for computing Log2-likelihood scores
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
virtual ScoreLog2Likelihood< ALLOC > * clone() const
virtual copy constructor
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
static const std::string type
const double _1log2
1 / log(2)
virtual ~ScoreLog2Likelihood()
destructor
virtual const Apriori< ALLOC > & internalApriori() const final
returns the internal apriori of the score
gum is the global namespace for all aGrUM entities
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
ScoreLog2Likelihood< ALLOC > & operator=(const ScoreLog2Likelihood< ALLOC > &from)
copy operator
ScoreLog2Likelihood(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
allocator_type getAllocator() const
returns the allocator used by the score
virtual std::string isAprioriCompatible() const final
indicates whether the apriori is compatible (meaningful) with 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
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
Size NodeId
Type for node ids.