aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
CNMonteCarloSampling.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
48
49
#ifndef GUM_CN_MONTE_CARLO_SAMPLING_H
50
#define GUM_CN_MONTE_CARLO_SAMPLING_H
51
52
#include <limits>
53
#include <thread>
54
55
#include <
agrum/CN/inference/multipleInferenceEngine.h
>
56
57
namespace
gum
{
58
namespace
credal
{
59
79
template
< GUM_Numeric GUM_SCALAR,
class
BNInferenceEngine = LazyPropagation< GUM_SCALAR > >
80
class
PYGUM_PUBLIC
CNMonteCarloSampling
:
81
public
MultipleInferenceEngine
< GUM_SCALAR, BNInferenceEngine > {
85
using
_infEs_
=
MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >
;
86
89
90
void
_mcInitApproximationScheme_
();
92
void
_mcThreadDataCopy_
();
94
97
98
inline
void
_verticesSampling_
(
Size
this_thread);
99
101
inline
void
_insertEvidence_
(
Size
this_thread);
102
105
inline
void
_threadInference_
(
Size
this_thread);
106
108
inline
void
_threadUpdate_
(
Size
this_thread);
109
117
inline
void
_binaryRep_
(std::vector< bool >& toFill,
const
Idx
value)
const
;
118
120
121
protected
:
122
123
public
:
126
130
explicit
CNMonteCarloSampling
(
const
CredalNet< GUM_SCALAR >
&
credalNet
);
132
~CNMonteCarloSampling
()
override
;
134
137
139
void
makeInference
()
override
;
140
142
144
145
void
insertEvidenceFile
(std::string_view path)
override
;
146
147
protected
:
148
bool
repetitiveInd_
;
149
};
150
151
152
#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
153
extern
template
class
CNMonteCarloSampling< float, LazyPropagation< float >
>;
154
155
extern
template
class
CNMonteCarloSampling< double, LazyPropagation< double >
>;
156
#endif
157
158
159
}
// namespace credal
160
}
// namespace gum
161
162
#include <
agrum/CN/inference/CNMonteCarloSampling_tpl.h
>
163
164
#endif
CNMonteCarloSampling_tpl.h
gum::credal::CNMonteCarloSampling
<agrum/CN/CNMonteCarloSampling.h>
Definition
CNMonteCarloSampling.h:81
gum::credal::CNMonteCarloSampling::_verticesSampling_
void _verticesSampling_(Size this_thread)
Thread samples a IBayesNet from the CredalNet.
Definition
CNMonteCarloSampling_tpl.h:235
gum::credal::CNMonteCarloSampling::CNMonteCarloSampling
CNMonteCarloSampling(const CredalNet< GUM_SCALAR > &credalNet)
Constructor.
Definition
CNMonteCarloSampling_tpl.h:50
gum::credal::CNMonteCarloSampling::_binaryRep_
void _binaryRep_(std::vector< bool > &toFill, const Idx value) const
Get the binary representation of a given value.
Definition
CNMonteCarloSampling_tpl.h:221
gum::credal::CNMonteCarloSampling::_threadInference_
void _threadInference_(Size this_thread)
Thread performs an inference using BNInferenceEngine.
Definition
CNMonteCarloSampling_tpl.h:157
gum::credal::CNMonteCarloSampling::repetitiveInd_
bool repetitiveInd_
Definition
CNMonteCarloSampling.h:148
gum::credal::CNMonteCarloSampling::_insertEvidence_
void _insertEvidence_(Size this_thread)
Insert CredalNet evidence into a thread BNInferenceEngine.
Definition
CNMonteCarloSampling_tpl.h:338
gum::credal::CNMonteCarloSampling::_mcInitApproximationScheme_
void _mcInitApproximationScheme_()
Initialize approximation Scheme.
Definition
CNMonteCarloSampling_tpl.h:166
gum::credal::CNMonteCarloSampling::_infEs_
MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine > _infEs_
To easily acces MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine.
Definition
CNMonteCarloSampling.h:85
gum::credal::CNMonteCarloSampling::_mcThreadDataCopy_
void _mcThreadDataCopy_()
Initialize threads data.
Definition
CNMonteCarloSampling_tpl.h:177
gum::credal::CNMonteCarloSampling::_threadUpdate_
void _threadUpdate_(Size this_thread)
Update thread data after a IBayesNet inference.
Definition
CNMonteCarloSampling_tpl.h:135
gum::credal::CNMonteCarloSampling::insertEvidenceFile
void insertEvidenceFile(std::string_view path) override
unsigned int notOptDelete;
Definition
CNMonteCarloSampling_tpl.h:374
gum::credal::CNMonteCarloSampling::makeInference
void makeInference() override
Starts the inference.
Definition
CNMonteCarloSampling_tpl.h:71
gum::credal::CredalNet
Class template representing a Credal Network.
Definition
credalNet.h:97
gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >::credalNet
const CredalNet< GUM_SCALAR > & credalNet() const
Definition
inferenceEngine_tpl.h:82
gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >::MultipleInferenceEngine
MultipleInferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Definition
multipleInferenceEngine_tpl.h:51
gum::Size
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition
types.h:74
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
multipleInferenceEngine.h
Abstract class representing CredalNet inference engines.
gum::credal
namespace for all credal networks entities
Definition
agrum.h:61
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0