1 /** 2 * 3 * Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) 4 * {prenom.nom}_at_lip6.fr 5 * 6 * This library is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this library. If not, see <http://www.gnu.org/licenses/>. 18 * 19 */ 20 /* INCLUDES */ 21 %{ 22 #include <iostream> 23 #include <iomanip> 24 #include <string> 25 #include <ostream> 26 #include <sstream> 27 #include <vector> 28 #include <limits> 29 #include <utility> 30 #include <new> 31 #include <exception> 32 #include <typeinfo> 33 34 #include <agrum/tools/core/types.h> 35 #include <agrum/tools/core/utils_misc.h> 36 #include <agrum/tools/core/hashFunc.h> 37 #include <agrum/tools/core/bijection.h> 38 #include <agrum/tools/core/set.h> 39 #include <agrum/tools/core/debug.h> 40 #include <agrum/tools/core/exceptions.h> 41 #include <agrum/tools/core/hashTable.h> 42 #include <agrum/tools/core/refPtr.h> 43 #include <agrum/tools/core/list.h> 44 #include <agrum/tools/core/OMPThreads.h> 45 46 #include <agrum/tools/graphs/parts/edgeGraphPart.h> 47 #include <agrum/tools/graphs/parts/arcGraphPart.h> 48 #include <agrum/tools/graphs/parts/nodeGraphPart.h> 49 50 #include <agrum/tools/graphs/diGraph.h> 51 #include <agrum/tools/graphs/DAG.h> 52 #include <agrum/tools/graphs/undiGraph.h> 53 #include <agrum/tools/graphs/mixedGraph.h> 54 #include <agrum/tools/graphs/cliqueGraph.h> 55 #include <agrum/tools/graphs/algorithms/triangulations/defaultTriangulation.h> 56 #include <agrum/tools/variables/discreteVariable.h> 57 #include <agrum/tools/multidim/implementations/multiDimInterface.h> 58 #include <agrum/tools/multidim/implementations/multiDimAdressable.h> 59 #include <agrum/tools/multidim/instantiation.h> 60 #include <agrum/tools/multidim/implementations/multiDimContainer.h> 61 #include <agrum/tools/multidim/implementations/multiDimDecorator.h> 62 #include <agrum/tools/multidim/implementations/multiDimImplementation.h> 63 #include <agrum/tools/multidim/implementations/multiDimWithOffset.h> 64 #include <agrum/tools/multidim/implementations/multiDimReadOnly.h> 65 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORCompound.h> 66 #include <agrum/tools/multidim/ICIModels/multiDimNoisyAND.h> 67 68 #include <agrum/tools/graphicalModels/graphicalModel.h> 69 #include <agrum/tools/graphicalModels/DAGmodel.h> 70 #include <agrum/tools/graphicalModels/UGmodel.h> 71 #include <agrum/tools/graphicalModels/variableNodeMap.h> 72 73 #include <agrum/tools/core/sequence.h> 74 #include <agrum/tools/variables/variable.h> 75 #include <agrum/tools/variables/discreteVariable.h> 76 #include <agrum/tools/variables/labelizedVariable.h> 77 #include <agrum/tools/variables/rangeVariable.h> 78 #include <agrum/tools/variables/integerVariable.h> 79 #include <agrum/tools/variables/IDiscretizedVariable.h> 80 #include <agrum/tools/variables/discretizedVariable.h> 81 #include <agrum/tools/graphs/graphElements.h> 82 #include <agrum/tools/multidim/potential.h> 83 #include <agrum/tools/multidim/implementations/multiDimArray.h> 84 85 #include <agrum/BN/IBayesNet.h> 86 #include <agrum/BN/BayesNet.h> 87 #include <agrum/BN/BayesNetFragment.h> 88 89 #include <agrum/MN/IMarkovNet.h> 90 #include <agrum/MN/MarkovNet.h> 91 #include <agrum/MN/inference/ShaferShenoyMNInference.h> 92 #include <agrum/MN/io/UAI/UAIMNReader.h> 93 #include <agrum/MN/io/UAI/UAIMNWriter.h> 94 95 #include <agrum/BN/algorithms/essentialGraph.h> 96 #include <agrum/BN/algorithms/MarkovBlanket.h> 97 #include <agrum/BN/algorithms/structuralComparator.h> 98 99 #include <agrum/BN/io/BIF/BIFReader.h> 100 #include <agrum/BN/io/BIF/BIFWriter.h> 101 #include <agrum/BN/io/DSL/DSLReader.h> 102 #include <agrum/BN/io/DSL/DSLWriter.h> 103 #include <agrum/BN/io/net/netReader.h> 104 #include <agrum/BN/io/net/netWriter.h> 105 #include <agrum/BN/io/BIFXML/BIFXMLBNReader.h> 106 #include <agrum/BN/io/BIFXML/BIFXMLBNWriter.h> 107 #include <agrum/PRM/o3prm/O3prmBNReader.h> 108 #include <agrum/PRM/o3prm/O3prmBNWriter.h> 109 #include <agrum/BN/io/UAI/UAIBNReader.h> 110 #include <agrum/BN/io/UAI/UAIBNWriter.h> 111 112 #include <agrum/tools/core/approximations/IApproximationSchemeConfiguration.h> 113 #include <agrum/tools/core/approximations/approximationScheme.h> 114 115 #include <agrum/BN/inference/tools/BayesNetInference.h> 116 117 #include <agrum/BN/inference/lazyPropagation.h> 118 #include <agrum/BN/inference/ShaferShenoyInference.h> 119 #include <agrum/BN/inference/variableElimination.h> 120 121 #include <agrum/BN/inference/GibbsSampling.h> 122 #include <agrum/BN/inference/importanceSampling.h> 123 #include <agrum/BN/inference/weightedSampling.h> 124 #include <agrum/BN/inference/MonteCarloSampling.h> 125 #include <agrum/BN/inference/loopySamplingInference.h> 126 127 #include <agrum/BN/inference/loopyBeliefPropagation.h> 128 129 #include <agrum/BN/algorithms/divergence/BNdistance.h> 130 #include <agrum/BN/algorithms/divergence/exactBNdistance.h> 131 #include <agrum/BN/algorithms/divergence/GibbsBNdistance.h> 132 133 #include <agrum/tools/core/signal/listener.h> 134 #include <agrum/tools/graphs/parts/listeners/diGraphListener.h> 135 136 #include <agrum/CN/credalNet.h> 137 #include <agrum/CN/tools/varMod2BNsMap.h> 138 #include <agrum/CN/inference/inferenceEngine.h> 139 #include <agrum/CN/inference/multipleInferenceEngine.h> 140 #include <agrum/CN/inference/CNMonteCarloSampling.h> 141 #include <agrum/CN/inference/CNLoopyPropagation.h> 142 143 #include <agrum/tools/database/databaseTable.h> 144 #include <agrum/BN/learning/BNLearner.h> 145 #include <agrum/BN/database/BNDatabaseGenerator.h> 146 147 #include <agrum/ID/influenceDiagram.h> 148 #include <agrum/ID/inference/tools/influenceDiagramInference.h> 149 #include <agrum/ID/inference/ShaferShenoyLIMIDInference.h> 150 #include <agrum/ID/io/BIFXML/BIFXMLIDReader.h> 151 #include <agrum/ID/io/BIFXML/BIFXMLIDWriter.h> 152 #include <agrum/ID/generator/influenceDiagramGenerator.h> 153 154 %} 155 156 157 %include "typemaps.i" 158 %include "std_vector.i" 159 %include "std_string.i" 160 161 namespace std { 162 %template ( Vector) vector<double>; 163 %template ( Vector_int) vector<unsigned int>; 164 %template ( Vector_string) vector<string>; 165 } 166 167 /* CLASS EXTENSIONS */ 168 %extend gum::DiscreteVariable { toLabelizedVar()169 gum::LabelizedVariable toLabelizedVar() { 170 return gum::LabelizedVariable(* dynamic_cast<gum::LabelizedVariable*>(self )); 171 } 172 toRangeVar()173 gum::RangeVariable toRangeVar() { 174 return gum::RangeVariable(* dynamic_cast<gum::RangeVariable*>(self )); 175 } 176 toIntegerVar()177 gum::IntegerVariable toIntegerVar() { 178 return gum::IntegerVariable(* dynamic_cast<gum::IntegerVariable*>(self )); 179 } 180 toDiscretizedVar()181 gum::DiscretizedVariable<double> toDiscretizedVar() { 182 return gum::DiscretizedVariable<double>(* dynamic_cast<gum::DiscretizedVariable<double> *> (self )); 183 } 184 toDiscretizedVar()185 gum::DiscretizedVariable<double> toDiscretizedVar() { 186 return gum::DiscretizedVariable<double>(* dynamic_cast<gum::DiscretizedVariable<double> *> (self )); 187 } 188 } 189 190 %include "forUsing.i" 191 192 /* EXCEPTION HANDLING */ 193 %exceptionclass std::bad_cast; 194 195 %exceptionclass gum::Exception; 196 197 %exceptionclass gum::CPTError; 198 %exceptionclass gum::DefaultInLabel; 199 %exceptionclass gum::DuplicateElement; 200 %exceptionclass gum::DuplicateLabel; 201 %exceptionclass gum::FatalError; 202 %exceptionclass gum::FormatNotFound; 203 %exceptionclass gum::GraphError; 204 %exceptionclass gum::IOError; 205 %exceptionclass gum::InvalidArc; 206 %exceptionclass gum::InvalidArgument; 207 %exceptionclass gum::InvalidArgumentsNumber; 208 %exceptionclass gum::InvalidDirectedCycle; 209 %exceptionclass gum::InvalidEdge; 210 %exceptionclass gum::InvalidNode; 211 %exceptionclass gum::DatabaseError; 212 %exceptionclass gum::MissingValueInDatabase; 213 %exceptionclass gum::MissingVariableInDatabase; 214 %exceptionclass gum::NoChild; 215 %exceptionclass gum::NoNeighbour; 216 %exceptionclass gum::NoParent; 217 %exceptionclass gum::NotFound; 218 %exceptionclass gum::NullElement; 219 %exceptionclass gum::OperationNotAllowed; 220 %exceptionclass gum::OutOfBounds; 221 %exceptionclass gum::ArgumentError; 222 %exceptionclass gum::SizeError; 223 %exceptionclass gum::SyntaxError; 224 %exceptionclass gum::UndefinedElement; 225 %exceptionclass gum::UndefinedIteratorKey; 226 %exceptionclass gum::UndefinedIteratorValue; 227 %exceptionclass gum::UnknownLabelInDatabase; 228 229 %rename gum::Exception GumException; 230 231 /* WRAPPED HEADERS (pyAgrum API) */ 232 %import <agrum/config.h> 233 %import <agrum/tools/core/inline.h> 234 235 %import <agrum/tools/core/types.h> 236 %include <agrum/tools/core/set.h> 237 %include <agrum/tools/core/exceptions.h> 238 %include <agrum/tools/core/sequence.h> 239 %include <agrum/tools/core/utils_random.h> 240 241 %include <agrum/tools/core/OMPThreads.h> 242 243 %include <agrum/tools/variables/variable.h> 244 %include <agrum/tools/variables/discreteVariable.h> 245 %include <agrum/tools/variables/labelizedVariable.h> 246 %include <agrum/tools/variables/rangeVariable.h> 247 %include <agrum/tools/variables/integerVariable.h> 248 %include <agrum/tools/variables/IDiscretizedVariable.h> 249 %include <agrum/tools/variables/discretizedVariable.h> 250 251 %include <agrum/tools/graphs/graphElements.h> 252 253 %import <agrum/tools/graphs/parts/edgeGraphPart.h> 254 %import <agrum/tools/graphs/parts/arcGraphPart.h> 255 %import <agrum/tools/graphs/parts/nodeGraphPart.h> 256 257 %include <agrum/tools/graphs/undiGraph.h> 258 %include <agrum/tools/graphs/diGraph.h> 259 %include <agrum/tools/graphs/DAG.h> 260 %include <agrum/tools/graphs/mixedGraph.h> 261 %include <agrum/tools/graphs/cliqueGraph.h> 262 %import <agrum/tools/graphs/algorithms/triangulations/defaultTriangulation.h> 263 %import <agrum/tools/graphs/algorithms/triangulations/triangulation.h> 264 265 266 %import <agrum/tools/multidim/implementations/multiDimInterface.h> 267 %import <agrum/tools/multidim/implementations/multiDimAdressable.h> 268 %import <agrum/tools/multidim/implementations/multiDimContainer.h> 269 %import <agrum/tools/multidim/implementations/multiDimDecorator.h> 270 %import <agrum/tools/multidim/implementations/multiDimImplementation.h> 271 %import <agrum/tools/multidim/implementations/multiDimWithOffset.h> 272 %import <agrum/tools/multidim/implementations/multiDimReadOnly.h> 273 %import <agrum/tools/multidim/implementations/multiDimArray.h> 274 275 %include <agrum/tools/multidim/ICIModels/multiDimNoisyORCompound.h> 276 %include <agrum/tools/multidim/ICIModels/multiDimNoisyAND.h> 277 278 %include <agrum/tools/multidim/instantiation.h> 279 %include <agrum/tools/multidim/potential.h> 280 281 %import <agrum/tools/core/refPtr.h> 282 %include <agrum/tools/core/list.h> 283 284 %import <agrum/tools/graphicalModels/variableNodeMap.h> 285 %include <agrum/tools/graphicalModels/graphicalModel.h> 286 %include <agrum/tools/graphicalModels/DAGmodel.h> 287 %include <agrum/tools/graphicalModels/UGmodel.h> 288 289 %include <agrum/BN/IBayesNet.h> 290 %include <agrum/BN/BayesNet.h> 291 %include <agrum/BN/BayesNetFragment.h> 292 293 %include <agrum/MN/IMarkovNet.h> 294 %include <agrum/MN/MarkovNet.h> 295 %include <agrum/MN/inference/ShaferShenoyMNInference.h> 296 297 298 %include <agrum/BN/algorithms/essentialGraph.h> 299 %include <agrum/BN/algorithms/MarkovBlanket.h> 300 %include <agrum/BN/algorithms/structuralComparator.h> 301 302 %import <agrum/tools/core/approximations/IApproximationSchemeConfiguration.h> 303 %include <agrum/tools/core/approximations/approximationScheme.h> 304 305 %import <agrum/BN/inference/tools/relevantPotentialsFinderType.h> 306 307 %ignore gum::BayesNetInference; 308 %include <agrum/BN/inference/tools/BayesNetInference.h> 309 %include <agrum/BN/inference/lazyPropagation.h> 310 %include <agrum/BN/inference/ShaferShenoyInference.h> 311 %include <agrum/BN/inference/variableElimination.h> 312 313 %include <agrum/BN/inference/GibbsSampling.h> 314 %include <agrum/BN/inference/importanceSampling.h> 315 %include <agrum/BN/inference/weightedSampling.h> 316 %include <agrum/BN/inference/MonteCarloSampling.h> 317 %include <agrum/BN/inference/loopySamplingInference.h> 318 319 %include <agrum/BN/inference/loopyBeliefPropagation.h> 320 321 %import <agrum/BN/algorithms/divergence/BNdistance.h> 322 %include <agrum/BN/algorithms/divergence/exactBNdistance.h> 323 %include <agrum/BN/algorithms/divergence/GibbsBNdistance.h> 324 325 %import <agrum/tools/core/signal/listener.h> 326 %import <agrum/tools/graphs/parts/listeners/diGraphListener.h> 327 %import <agrum/BN/io/BIF/BIFReader.h> 328 329 %import <agrum/tools/database/databaseTable.h> 330 %import <agrum/BN/learning/BNLearnUtils/genericBNLearner.h> 331 %include <agrum/BN/learning/BNLearner.h> 332 %include <agrum/BN/database/BNDatabaseGenerator.h> 333 334 %include <agrum/CN/credalNet.h> 335 %include <agrum/CN/tools/varMod2BNsMap.h> 336 %include <agrum/CN/inference/inferenceEngine.h> 337 %include <agrum/CN/inference/multipleInferenceEngine.h> 338 %include <agrum/CN/inference/CNMonteCarloSampling.h> 339 %include <agrum/CN/inference/CNLoopyPropagation.h> 340 341 %include <agrum/ID/influenceDiagram.h> 342 %include <agrum/ID/inference/ShaferShenoyLIMIDInference.h> 343 344 /* TEMPLATES INSTANTIATIONS */ 345 346 %template ( randomDistribution ) gum::randomDistribution<double>; 347 348 %template ( DiscretizedVariable ) gum::DiscretizedVariable<double>; 349 350 %template ( MultiDimContainer ) gum::MultiDimContainer<double>; 351 %template ( MultiDimImplementation ) gum::MultiDimImplementation<double>; 352 %template ( MultiDimDecorator ) gum::MultiDimDecorator<double>; 353 %template ( MultiDimWithOffset ) gum::MultiDimWithOffset<double>; 354 %template ( MultiDimArray ) gum::MultiDimArray<double>; 355 356 %template ( Potential ) gum::Potential<double>; 357 358 %template (IBayesNet ) gum::IBayesNet<double>; 359 %template ( BayesNet ) gum::BayesNet<double>; 360 %template ( BayesNetFragment ) gum::BayesNetFragment<double>; 361 362 %template (IMarkovNet ) gum::IMarkovNet<double>; 363 %template ( MarkovNet ) gum::MarkovNet<double>; 364 %template ( ShaferShenoyMNInference ) gum::ShaferShenoyMNInference<double>; 365 366 //%template ( BayesNetInference ) gum::BayesNetInference<double>; 367 %template ( LazyPropagation ) gum::LazyPropagation<double>; 368 %template ( ShaferShenoyInference ) gum::ShaferShenoyInference<double>; 369 %template ( VariableElimination ) gum::VariableElimination<double>; 370 371 %template ( GibbsSampling ) gum::GibbsSampling<double>; 372 %template ( ImportanceSampling ) gum::ImportanceSampling<double>; 373 %template ( WeightedSampling ) gum::WeightedSampling<double>; 374 %template ( MonteCarloSampling ) gum::MonteCarloSampling<double>; 375 %template ( LoopyImportanceSampling ) gum::LoopySamplingInference<double,gum::ImportanceSampling>; 376 %template ( LoopyWeightedSampling ) gum::LoopySamplingInference<double,gum::WeightedSampling>; 377 %template ( LoopyGibbsSampling ) gum::LoopySamplingInference<double,gum::GibbsSampling>; 378 %template ( LoopyMonteCarloSampling ) gum::LoopySamplingInference<double,gum::MonteCarloSampling>; 379 380 %template ( LoopyBeliefPropagation ) gum::LoopyBeliefPropagation<double>; 381 382 %template ( ExactBNdistance ) gum::ExactBNdistance<double>; 383 %template ( GibbsBNdistance ) gum::GibbsBNdistance<double>; 384 385 %template ( CredalNet ) gum::credal::CredalNet<double>; 386 %template ( CNMonteCarloSampling ) gum::credal::CNMonteCarloSampling<double>; 387 %template ( CNLoopyPropagation ) gum::credal::CNLoopyPropagation<double>; 388 389 %template ( InfluenceDiagram) gum::InfluenceDiagram<double>; 390 %template ( ShaferShenoyLIMIDInference) gum::ShaferShenoyLIMIDInference<double>; 391 392 %template ( BNLearner) gum::learning::BNLearner<double>; 393 %template ( BNDatabaseGenerator) gum::learning::BNDatabaseGenerator<double>; 394 395 /* for debug */ 396 namespace gum { 397 void statsObj(void); 398 } 399 %{ 400 namespace gum { statsObj(void)401 void statsObj(void) { 402 #ifdef GUM_DEBUG_MODE 403 gum::__debug__::__atexit(); 404 #else 405 //std::cout<<"Stats on aGrUM objects only available in debug mode"<<std::endl; 406 #endif // GUM_DEBUG_MODE 407 } 408 } 409 %} 410