1 /** 2 * 3 * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU) 4 * info_at_agrum_dot_org 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 21 22 /** 23 * @file 24 * @brief This file contains Weighted sampling class definition. 25 * 26 * @author Paul ALAM & Pierre-Henri WUILLEMIN(_at_LIP6) 27 */ 28 29 30 #ifndef GUM_WEIGHTED_INFERENCE_H 31 #define GUM_WEIGHTED_INFERENCE_H 32 33 #include <agrum/BN/inference/tools/samplingInference.h> 34 35 namespace gum { 36 37 /** 38 * @class WeightedInference weightedInference.h 39 *<agrum/BN/inference/weightedInference.h> 40 * @brief class for making Weighted sampling inference in Bayesian networks. 41 * @ingroup bn_approximation 42 * 43 * This class overrides pure function declared in the inherited class 44 *ApproximateInference. 45 * It defines the way Weighted sampling draws a sample. 46 * 47 */ 48 49 template < typename GUM_SCALAR > 50 class WeightedSampling: public SamplingInference< GUM_SCALAR > { 51 public: 52 /** 53 * Default constructor 54 */ 55 explicit WeightedSampling(const IBayesNet< GUM_SCALAR >* bn); 56 57 /** 58 * Destructor 59 */ 60 ~WeightedSampling() override; 61 62 protected: 63 /// draws a defined number of samples without updating the estimators 64 Instantiation burnIn_() override; 65 66 /// draws a sample according to Weighted sampling 67 /** 68 * @param w the weight of sample being generated 69 * @param prev the previous sample generated 70 * @param bn the Bayesian network containing the evidence 71 * @param hardEvNodes hard evidence nodes 72 * @param hardEv hard evidences values 73 * 74 * Generates a new sample in topological order. Each sample has a weight bias. 75 * The sample weight is the product of each node's weight. 76 * 77 */ 78 Instantiation draw_(GUM_SCALAR* w, Instantiation prev) override; 79 }; 80 81 82 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 83 extern template class WeightedSampling< double >; 84 #endif 85 } // namespace gum 86 87 #include <agrum/BN/inference/weightedSampling_tpl.h> 88 89 #endif 90