aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
groundedInference.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@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 Headers of GroundedInference.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 #ifndef GUM_GROUNDED_INFERENCE_H
29 #define GUM_GROUNDED_INFERENCE_H
30 
31 #include <agrum/BN/inference/tools/marginalTargetedInference.h>
32 #include <agrum/PRM/inference/PRMInference.h>
33 
34 namespace gum {
35  namespace prm {
36  /**
37  * @class GroundedInference groundedInference.h
38  *<agrum/PRM/groundedInference.h>
39  * @brief This class is used to realise grounded inference in a
40  *PRM<GUM_SCALAR>.
41  *
42  * The best way to build this class is to use the static creation methods.
43  *
44  */
45  template < typename GUM_SCALAR >
47  public:
48  // ========================================================================
49  /// @name Constructor & destructor.
50  // ========================================================================
51  /// @{
52 
53  /// Default constructor.
54  GroundedInference(const PRM< GUM_SCALAR >& prm, const PRMSystem< GUM_SCALAR >& system);
55 
56  /// Destructor.
57  virtual ~GroundedInference();
58 
59  /// @}
60  // ========================================================================
61  /// @name Getters & setters.
62  // ========================================================================
63  /// @{
64 
65  /**
66  * @brief Returns the bayesnet inference engine used by this class.
67  * @return the bayesnet inference engine used by this class.
68  *
69  * @throw NotFound Raised if no inference engine have been defined for
70  * this class.
71  */
73 
74  /**
75  * @brief Defines the bayesnet inference engine used by this class.
76  * The inference engine is given to this class, it will be deleted
77  * when ~GroundedInference() is called.
78  * @param bn_inf The bayesnet inference engine used by this class.
79  *
80  * @throw OperationNotAllowed If bn_inf does not inference over the
81  * SystemBayesNet of this class.
82  * @todo MarginalTargetedInference should have copy constructors.
83  */
84  void setBNInference(MarginalTargetedInference< GUM_SCALAR >* bn_inf);
85 
86  virtual std::string name() const;
87 
88  /// @}
89  protected:
90  // ========================================================================
91  /// @name Private evidence handling methods and members.
92  // ========================================================================
93  /// @{
94 
95  /// This method is called whenever an evidence is added, but AFTER
96  /// any processing made by PRMInference.
97  virtual void evidenceAdded_(const typename PRMInference< GUM_SCALAR >::Chain& chain);
98 
99  /// This method is called whenever an evidence is removed, but BEFORE
100  /// any processing made by PRMInference.
101  virtual void evidenceRemoved_(const typename PRMInference< GUM_SCALAR >::Chain& chain);
102 
103  /// @brief Generic method to compute the marginal of given element.
104  /// @param chain
105  /// @param m CPF filled with the marginal of elt. It is initialized
106  /// properly.
107  virtual void posterior_(const typename PRMInference< GUM_SCALAR >::Chain& chain,
108  Potential< GUM_SCALAR >& m);
109 
110  /// @brief Generic method to compute the marginal of given element.
111  /// @param queries Set of pairs of PRMInstance and PRMAttribute.
112  /// @param j CPF filled with the joint probability of queries. It is
113  /// initialized properly.
114  virtual void joint_(const std::vector< typename PRMInference< GUM_SCALAR >::Chain >& queries,
115  Potential< GUM_SCALAR >& j);
116 
117  /// @}
118  private:
119  /// Copy constructor.
120  GroundedInference(const GroundedInference& source);
121 
122  /// Copy operator.
124 
125  /// The bayesnet inference engine used by this class.
127 
129  };
130 
131 
132 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
133  extern template class GroundedInference< double >;
134 #endif
135 
136 
137  } /* namespace prm */
138 } /* namespace gum */
139 
140 #include <agrum/PRM/inference/groundedInference_tpl.h>
141 
142 #endif /* GUM_GROUNDED_INFERENCE_H */
List< const Potential< GUM_SCALAR > *> _obs_
virtual std::string name() const
Returns the bayesnet inference engine used by this class.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual ~GroundedInference()
Destructor.
virtual void posterior_(const typename PRMInference< GUM_SCALAR >::Chain &chain, Potential< GUM_SCALAR > &m)
Generic method to compute the marginal of given element.
virtual void evidenceAdded_(const typename PRMInference< GUM_SCALAR >::Chain &chain)
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference...
MarginalTargetedInference< GUM_SCALAR > * _inf_
The bayesnet inference engine used by this class.
virtual void joint_(const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Potential< GUM_SCALAR > &j)
Generic method to compute the marginal of given element.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
MarginalTargetedInference< GUM_SCALAR > & getBNInference()
Returns the bayesnet inference engine used by this class.
virtual void evidenceRemoved_(const typename PRMInference< GUM_SCALAR >::Chain &chain)
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
GroundedInference & operator=(const GroundedInference &source)
Copy operator.
GroundedInference(const GroundedInference &source)
Copy constructor.
void setBNInference(MarginalTargetedInference< GUM_SCALAR > *bn_inf)
Defines the bayesnet inference engine used by this class.
<agrum/PRM/groundedInference.h>