aGrUM  0.14.2
apriori_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
26 
27 namespace gum {
28 
29  namespace learning {
30 
32  template < template < typename > class ALLOC >
34  const DatabaseTable< ALLOC >& database,
35  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
36  nodeId2columns,
37  const typename Apriori< ALLOC >::allocator_type& alloc) :
38  ALLOC< NodeId >(alloc),
39  _database(&database), _nodeId2columns(nodeId2columns) {
40  GUM_CONSTRUCTOR(Apriori);
41  }
42 
43 
45  template < template < typename > class ALLOC >
47  const Apriori< ALLOC >& from,
48  const typename Apriori< ALLOC >::allocator_type& alloc) :
49  ALLOC< NodeId >(alloc),
50  _weight(from._weight), _database(from._database),
52  GUM_CONS_CPY(Apriori);
53  }
54 
55 
57  template < template < typename > class ALLOC >
58  INLINE Apriori< ALLOC >::Apriori(const Apriori< ALLOC >& from) :
59  Apriori(from, from.getAllocator()) {}
60 
61 
63  template < template < typename > class ALLOC >
65  Apriori< ALLOC >&& from,
66  const typename Apriori< ALLOC >::allocator_type& alloc) :
67  ALLOC< NodeId >(alloc),
68  _weight(from._weight), _database(from._database),
69  _nodeId2columns(std::move(from._nodeId2columns)) {
70  GUM_CONS_MOV(Apriori);
71  }
72 
73 
75  template < template < typename > class ALLOC >
76  INLINE Apriori< ALLOC >::Apriori(Apriori< ALLOC >&& from) :
77  Apriori(std::move(from), from.getAllocator()) {}
78 
79 
81  template < template < typename > class ALLOC >
83  GUM_DESTRUCTOR(Apriori);
84  }
85 
86 
88  template < template < typename > class ALLOC >
89  Apriori< ALLOC >& Apriori< ALLOC >::operator=(const Apriori< ALLOC >& from) {
90  if (this != &from) {
91  _nodeId2columns = from._nodeId2columns;
92  _weight = from._weight;
93  _database = from._database;
94  }
95  return *this;
96  }
97 
98 
100  template < template < typename > class ALLOC >
101  Apriori< ALLOC >& Apriori< ALLOC >::operator=(Apriori< ALLOC >&& from) {
102  if (this != &from) {
103  _nodeId2columns = std::move(from._nodeId2columns);
104  _weight = from._weight;
105  _database = from._database;
106  }
107  return *this;
108  }
109 
110 
112  template < template < typename > class ALLOC >
113  INLINE void Apriori< ALLOC >::setWeight(const double weight) {
114  if (weight < 0.0) {
115  GUM_ERROR(OutOfBounds,
116  "A negative weight (" << weight
117  << ") is forbidden for an apriori");
118  }
119  _weight = weight;
120  }
121 
122 
124  template < template < typename > class ALLOC >
125  INLINE double Apriori< ALLOC >::weight() const {
126  return _weight;
127  }
128 
129 
131  template < template < typename > class ALLOC >
132  INLINE typename Apriori< ALLOC >::allocator_type
134  return *this;
135  }
136 
137 
138  } /* namespace learning */
139 
140 } /* namespace gum */
141 
142 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual void setWeight(const double weight)
sets the weight of the a priori (kind of effective sample size)
STL namespace.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
const DatabaseTable< ALLOC > * _database
a reference to the database in order to have access to its variables
Definition: apriori.h:143
double weight() const
returns the weight assigned to the apriori
double _weight
the weight of the apriori
Definition: apriori.h:140
Apriori< ALLOC > & operator=(const Apriori< ALLOC > &from)
copy operator
allocator_type getAllocator() const
returns the allocator used by the internal apriori
Bijection< NodeId, std::size_t, ALLOC< std::size_t > > _nodeId2columns
a mapping from the NodeIds of the variables to the indices of the columns in the database ...
Definition: apriori.h:147
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: apriori.h:50
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Apriori(const DatabaseTable< ALLOC > &database, 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
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
virtual ~Apriori()
destructor