aGrUM  0.14.2
BNDatabaseGenerator.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}@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 wil 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  ***************************************************************************/
65 #ifndef GUM_BN_DATABASE_GENERATOR
66 #define GUM_BN_DATABASE_GENERATOR
67 
68 #include <agrum/BN/BayesNet.h>
71 #include <fstream>
72 
73 namespace gum {
74 
75  namespace learning {
76  template < typename GUM_SCALAR >
78  public:
79  // #######################################################################
81  // #######################################################################
83 
86 
89 
91 
92  // #######################################################################
94  // #######################################################################
96 
97 
100  double drawSamples(Size nbSamples); // drawSamples
101 
103  void toCSV(const std::string& csvFileURL,
104  bool useLabels = true,
105  bool append = false,
106  std::string csvSeparator = ",",
107  bool checkOnAppend = false) const;
108 
110  DatabaseTable<> toDatabaseTable(bool useLabels = true) const;
111 
114  std::vector< std::vector< Idx > > database() const;
115 
117  void setVarOrder(const std::vector< Idx >& varOrder);
118 
120  void setVarOrder(const std::vector< std::string >& varOrder);
121 
123  void setVarOrderFromCSV(const std::string& csvFileURL,
124  const std::string& csvSeparator = ",");
125 
127  void setTopologicalVarOrder();
128 
131 
133  void setRandomVarOrder();
134 
136  std::vector< Idx > varOrder() const;
137 
139  std::vector< std::string > varOrderNames() const;
140 
142  double log2likelihood() const;
143 
145 
146  private:
149 
152 
155 
157  std::vector< std::vector< Idx > > __database;
158 
160  std::vector< Idx > __varOrder;
161 
163  bool __drawnSamples = false;
164 
166  double __log2likelihood = 0;
167 
169  std::vector< Idx >
170  __varOrderFromCSV(const std::string& csvFileURL,
171  const std::string& csvSeparator = ",") const;
172 
174  std::vector< Idx >
175  __varOrderFromCSV(std::ifstream& csvFile,
176  const std::string& csvSeparator = ",") const;
177 
178  // forbidden copies / moves
179  BNDatabaseGenerator(const BNDatabaseGenerator&) = delete;
183  };
184 
185 
186 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
187  extern template class BNDatabaseGenerator< double >;
188 #endif
189 
190  } /* namespace learning */
191 } /* namespace gum */
192 
194 #endif /* BN_DATABASE_GENERTOR */
Notification for progress using listener.
Class representing a Bayesian Network.
Definition: BayesNet.h:76
BNDatabaseGenerator & operator=(const BNDatabaseGenerator &)=delete
double __log2likelihood
log2Likelihood of generated samples
The class representing a tabular database stored in RAM.
std::vector< std::string > varOrderNames() const
returns variable order.
double drawSamples(Size nbSamples)
generate and stock database, returns log2likelihood using ProgressNotifier as notification ...
Class representing Bayesian networks.
Bijection< std::string, NodeId > __names2ids
bijection nodes names
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
DatabaseTable toDatabaseTable(bool useLabels=true) const
generates a DatabaseVectInRAM
void setTopologicalVarOrder()
set columns in topoligical order
const BayesNet< GUM_SCALAR > & __bn
Bayesian network.
std::vector< Idx > __varOrderFromCSV(const std::string &csvFileURL, const std::string &csvSeparator=",") const
returns varOrder from a csv file
void toCSV(const std::string &csvFileURL, bool useLabels=true, bool append=false, std::string csvSeparator=",", bool checkOnAppend=false) const
generates csv database according to bn
double log2likelihood() const
returns log2Likelihood of generated samples
std::vector< std::vector< Idx > > database() const
generates database according to bn into a std::vector
std::vector< std::vector< Idx > > __database
generated database
The class representing a tabular database as used by learning tasks.
void setVarOrder(const std::vector< Idx > &varOrder)
change columns order
void setRandomVarOrder()
set columns in random order
void setAntiTopologicalVarOrder()
set columns in antiTopoligical order
std::vector< Idx > varOrder() const
returns variable order indexes
priority queues (in which an element cannot appear more than once)
bool __drawnSamples
whether drawSamples has been already called.
std::vector< Idx > __varOrder
variable order in generated database
void setVarOrderFromCSV(const std::string &csvFileURL, const std::string &csvSeparator=",")
change columns order according to a csv file
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
BNDatabaseGenerator(const BayesNet< GUM_SCALAR > &bn)
default constructor