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 ScoreLog2Likelihood< ALLOC >& from,
73 Score< ALLOC >(from, alloc),
74 __internal_apriori(from.__internal_apriori, alloc) {
80 template <
template <
typename >
class ALLOC >
82 const ScoreLog2Likelihood< ALLOC >& from) :
87 template <
template <
typename >
class ALLOC >
89 ScoreLog2Likelihood< ALLOC >&& from,
91 Score< ALLOC >(
std::move(from), alloc),
92 __internal_apriori(
std::move(from.__internal_apriori), alloc) {
98 template <
template <
typename >
class ALLOC >
100 ScoreLog2Likelihood< ALLOC >&& from) :
105 template <
template <
typename >
class ALLOC >
108 ALLOC< ScoreLog2Likelihood< ALLOC > > allocator(alloc);
109 ScoreLog2Likelihood< 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 >
138 operator=(
const ScoreLog2Likelihood< ALLOC >& from) {
141 __internal_apriori = from.__internal_apriori;
148 template <
template <
typename >
class ALLOC >
150 operator=(ScoreLog2Likelihood< ALLOC >&& from) {
153 __internal_apriori = std::move(from.__internal_apriori);
160 template <
template <
typename >
class ALLOC >
162 const std::string& apriori_type,
double weight) {
171 std::stringstream msg;
172 msg <<
"The apriori '" << apriori_type
173 <<
"' is not yet supported by method isAprioriCompatible of " 174 <<
"Score Log2Likelihood";
180 template <
template <
typename >
class ALLOC >
182 const Apriori< ALLOC >& apriori) {
188 template <
template <
typename >
class ALLOC >
195 template <
template <
typename >
class ALLOC >
196 INLINE
const Apriori< ALLOC >&
198 return __internal_apriori;
203 template <
template <
typename >
class ALLOC >
206 std::vector< double, ALLOC< double > > N_ijk(
207 this->
_counter.counts(idset,
true));
208 const bool informative_external_apriori = this->
_apriori->isInformative();
209 if (informative_external_apriori)
210 this->
_apriori->addAllApriori(idset, N_ijk);
214 if (idset.hasConditioningSet()) {
216 std::vector< double, ALLOC< double > > N_ij(
224 for (
const auto n_ijk : N_ijk) {
225 if (n_ijk) { score += n_ijk * std::log(n_ijk); }
227 for (
const auto n_ij : N_ij) {
228 if (n_ij) { score -= n_ij * std::log(n_ij); }
244 for (
const auto n_ijk : N_ijk) {
246 score += n_ijk * std::log(n_ijk);
250 score -= N * std::log(N);
261 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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
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
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.