aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
groundedInference.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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,
55  const PRMSystem< GUM_SCALAR >& system);
56 
57  /// Destructor.
58  virtual ~GroundedInference();
59 
60  /// @}
61  // ========================================================================
62  /// @name Getters & setters.
63  // ========================================================================
64  /// @{
65 
66  /**
67  * @brief Returns the bayesnet inference engine used by this class.
68  * @return the bayesnet inference engine used by this class.
69  *
70  * @throw NotFound Raised if no inference engine have been defined for
71  * this class.
72  */
74 
75  /**
76  * @brief Defines the bayesnet inference engine used by this class.
77  * The inference engine is given to this class, it will be deleted
78  * when ~GroundedInference() is called.
79  * @param bn_inf The bayesnet inference engine used by this class.
80  *
81  * @throw OperationNotAllowed If bn_inf does not inference over the
82  * SystemBayesNet of this class.
83  * @todo MarginalTargetedInference should have copy constructors.
84  */
85  void setBNInference(MarginalTargetedInference< GUM_SCALAR >* bn_inf);
86 
87  virtual std::string name() const;
88 
89  /// @}
90  protected:
91  // ========================================================================
92  /// @name Private evidence handling methods and members.
93  // ========================================================================
94  /// @{
95 
96  /// This method is called whenever an evidence is added, but AFTER
97  /// any processing made by PRMInference.
98  virtual void
99  evidenceAdded_(const typename PRMInference< GUM_SCALAR >::Chain& chain);
100 
101  /// This method is called whenever an evidence is removed, but BEFORE
102  /// any processing made by PRMInference.
103  virtual void
104  evidenceRemoved_(const typename PRMInference< GUM_SCALAR >::Chain& chain);
105 
106  /// @brief Generic method to compute the marginal of given element.
107  /// @param chain
108  /// @param m CPF filled with the marginal of elt. It is initialized
109  /// properly.
110  virtual void
111  posterior_(const typename PRMInference< GUM_SCALAR >::Chain& chain,
112  Potential< GUM_SCALAR >& m);
113 
114  /// @brief Generic method to compute the marginal of given element.
115  /// @param queries Set of pairs of PRMInstance and PRMAttribute.
116  /// @param j CPF filled with the joint probability of queries. It is
117  /// initialized properly.
118  virtual void joint_(
119  const std::vector< typename PRMInference< GUM_SCALAR >::Chain >& queries,
120  Potential< GUM_SCALAR >& j);
121 
122  /// @}
123  private:
124  /// Copy constructor.
125  GroundedInference(const GroundedInference& source);
126 
127  /// Copy operator.
129 
130  /// The bayesnet inference engine used by this class.
132 
134  };
135 
136 
137 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
138  extern template class GroundedInference< double >;
139 #endif
140 
141 
142  } /* namespace prm */
143 } /* namespace gum */
144 
145 #include <agrum/PRM/inference/groundedInference_tpl.h>
146 
147 #endif /* GUM_GROUNDED_INFERENCE_H */
virtual std::string name() const
Returns the bayesnet inference engine used by this class.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
virtual ~GroundedInference()
Destructor.
List< const Potential< GUM_SCALAR > *> obs__
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...
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.
MarginalTargetedInference< GUM_SCALAR > * inf__
The bayesnet inference engine used by this class.
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>