aGrUM  0.14.2
DBRowGeneratorEM.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 GUM_LEARNING_DBROW_GENERATOR_EM_H
26 #define GUM_LEARNING_DBROW_GENERATOR_EM_H
27 
28 #include <vector>
29 
30 #include <agrum/agrum.h>
31 #include <agrum/core/bijection.h>
32 #include <agrum/BN/BayesNet.h>
35 
36 namespace gum {
37 
38  namespace learning {
39 
76  template < typename GUM_SCALAR = double,
77  template < typename > class ALLOC = std::allocator >
78  class DBRowGeneratorEM : public DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > {
79  public:
81  using allocator_type = ALLOC< DBTranslatedValue >;
82 
83  // ##########################################################################
85  // ##########################################################################
86 
88 
91  const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > >
92  column_types,
93  const BayesNet< GUM_SCALAR >& bn,
94  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
95  nodeId2columns =
96  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
97  const allocator_type& alloc = allocator_type());
98 
101 
104  const allocator_type& alloc);
105 
108 
111  const allocator_type& alloc);
112 
114  virtual DBRowGeneratorEM< GUM_SCALAR, ALLOC >* clone() const override final;
115 
117  virtual DBRowGeneratorEM< GUM_SCALAR, ALLOC >*
118  clone(const allocator_type& alloc) const override final;
119 
121  ~DBRowGeneratorEM();
122 
124 
125 
126  // ##########################################################################
128  // ##########################################################################
129 
131 
133  DBRowGeneratorEM< GUM_SCALAR, ALLOC >&
134  operator=(const DBRowGeneratorEM< GUM_SCALAR, ALLOC >& from);
135 
137  DBRowGeneratorEM< GUM_SCALAR, ALLOC >&
138  operator=(DBRowGeneratorEM< GUM_SCALAR, ALLOC >&& from);
139 
141 
142 
143  // ##########################################################################
145  // ##########################################################################
146 
148 
150  virtual const DBRow< DBTranslatedValue, ALLOC >& generate() override final;
151 
153  virtual void
154  setBayesNet(const BayesNet< GUM_SCALAR >& new_bn) override final;
155 
158 
160 
161 
162  protected:
164  virtual std::size_t
165  _computeRows(const DBRow< DBTranslatedValue, ALLOC >& row) override final;
166 
167 
168 #ifndef DOXYGEN_SHOULD_SKIP_THIS
169 
170  private:
172  const DBRow< DBTranslatedValue, ALLOC >* __input_row{nullptr};
173 
175  std::vector< std::size_t, ALLOC< std::size_t > > __missing_cols;
176 
178  std::size_t __nb_miss;
179 
181  Potential< GUM_SCALAR > __joint_proba;
182 
184  Instantiation* __joint_inst{nullptr};
185 
187 
193  DBRow< DBTranslatedValue, ALLOC > __filled_row1;
194 
196  DBRow< DBTranslatedValue, ALLOC > __filled_row2;
197 
199  bool __use_filled_row1{true};
200 
202  double __original_weight;
203 
204 
205 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
206  };
207 
208  } /* namespace learning */
209 
210 } /* namespace gum */
211 
212 
213 // always include the template implementation
215 
216 #endif /* GUM_LEARNING_DBROW_GENERATOR_EM_H */
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
Class representing a Bayesian Network.
Definition: BayesNet.h:76
A DBRowGenerator class that returns incomplete rows as EM would do.
DBRowGeneratorEM(const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > column_types, const BayesNet< GUM_SCALAR > &bn, 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
Base class for DBRowGenerator classes that use a BN for computing their outputs.
STL namespace.
A DBRowGenerator class that returns incomplete rows as EM would do.
Class representing Bayesian networks.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The union class for storing the translated values in learning databases.
Implementation of a variable elimination algorithm for inference in Bayesian Networks.
virtual DBRowGeneratorEM< GUM_SCALAR, ALLOC > * clone() const override final
virtual copy constructor
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
Base class for DBRowGenerator classes that use a BN for computing their outputs.
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
virtual void setBayesNet(const BayesNet< GUM_SCALAR > &new_bn) override final
assign a new Bayes net to the generator
The class for storing a record in a database.
Definition: DBRow.h:53
virtual std::size_t _computeRows(const DBRow< DBTranslatedValue, ALLOC > &row) override final
computes the rows it will provide as output
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
virtual const DBRow< DBTranslatedValue, ALLOC > & generate() override final
generates one ouput DBRow for each DBRow passed to method setInputRow
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Set of pairs of elements with fast search for both elements.
allocator_type getAllocator() const
returns the allocator used
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods