aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
instanceBayesNet.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 InstanceBayesNet.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_INSTANCE_BAYESNET_H
30 #define GUM_INSTANCE_BAYESNET_H
31 
32 #include <list>
33 
34 #include <agrum/BN/IBayesNet.h>
35 
36 #include <agrum/PRM/PRM.h>
37 
38 namespace gum {
39  namespace prm {
40 
41  /**
42  * @class InstanceBayesNet
43  * @headerfile instanceBayesNet.h <agrum/PRM/instanceBayesNet.h>
44  * @brief This class decorates an PRMInstance<GUM_SCALAR> as an
45  *IBaseBayesNet.
46  *
47  * Remember that an InstanceBayesNet does not contain input nodes parents
48  *and
49  * output nodes children. Thus you should be careful when using one of the
50  * BayesNetInference over a InstanceBayesNet since some variables are
51  *missing in
52  * the DAG but not in the nodes CPT.
53  *
54  */
55  template < typename GUM_SCALAR >
57  public:
58  // ========================================================================
59  /// @name Constructors & destructor.
60  // ========================================================================
61  /// @{
62 
63  /// Default constructor.
64  /// @param i The PRMInstance<GUM_SCALAR> decorated by this
65  /// InstanceBayesNet.
66  InstanceBayesNet(const PRMInstance< GUM_SCALAR >& i);
67 
68  /// Copy constructor.
70 
71  /// Copy operator.
73 
74  /// Destructor.
75  virtual ~InstanceBayesNet();
76 
77  /// @}
78  // ===========================================================================
79  /// @name Variable manipulation methods.
80  // ===========================================================================
81  /// @{
82 
83  /// See gum::IBaseBayesNet::cpt().
84  virtual const Potential< GUM_SCALAR >& cpt(NodeId varId) const;
85 
86  /// See gum::IBaseBayesNet::variableNodeMap().
87  virtual const VariableNodeMap& variableNodeMap() const;
88 
89  /// See gum::IBaseBayesNet::variable().
90  virtual const DiscreteVariable& variable(NodeId id) const;
91 
92  /// See gum::IBaseBayesNet::nodeId().
93  virtual NodeId nodeId(const DiscreteVariable& var) const;
94 
95  /// See gum::IBaseBayesNet::idFromName().
96  virtual NodeId idFromName(const std::string& name) const;
97 
98  /// See gum::IBaseBayesNet::variableFromName().
99  virtual const DiscreteVariable& variableFromName(const std::string& name) const;
100 
101  const NodeProperty< Size >& modalities() const;
102 
103  /// @}
104  // ===========================================================================
105  /// @name Graphical methods
106  // ===========================================================================
107  /// @{
108  /// @return Returns a dot representation of this IBayesNet.
109  virtual std::string toDot() const;
110 
111  /// @}
112  private:
113  /// Mapping between DiscreteVariable and their NodeId
115 
116  /// Private getter with type checking in case the id is not a formal
117  /// PRMAttribute<GUM_SCALAR>.
118  /// @throw NotFound Raised if id is not a formal attribute.
119  const PRMClassElement< GUM_SCALAR >& _get_(NodeId id) const;
120 
121  const PRMClassElement< GUM_SCALAR >& _get_(const std::string& name) const;
122 
123  /// The PRMClassElementContainer decorated by this.
125 
127 
128  void _init_(const PRMInstance< GUM_SCALAR >& i);
129  };
130 
131 
132 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
133  extern template class InstanceBayesNet< double >;
134 #endif
135 
136 
137  } /* namespace prm */
138 } /* namespace gum */
139 
140 #include <agrum/PRM/instanceBayesNet_tpl.h>
141 
142 #endif /* GUM_INSTANCE_BAYESNET_H */
virtual NodeId idFromName(const std::string &name) const
See gum::IBaseBayesNet::idFromName().
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
See gum::IBaseBayesNet::cpt().
virtual const VariableNodeMap & variableNodeMap() const
See gum::IBaseBayesNet::variableNodeMap().
virtual const DiscreteVariable & variable(NodeId id) const
See gum::IBaseBayesNet::variable().
void _init_(const PRMInstance< GUM_SCALAR > &i)
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
const NodeProperty< Size > & modalities() const
See gum::IBaseBayesNet::cpt().
virtual std::string toDot() const
InstanceBayesNet(const PRMInstance< GUM_SCALAR > &i)
Default constructor.
virtual const DiscreteVariable & variableFromName(const std::string &name) const
See gum::IBaseBayesNet::variableFromName().
HashTable< const DiscreteVariable *, const PRMAttribute< GUM_SCALAR > *> _varNodeMap_
Mapping between DiscreteVariable and their NodeId.
virtual NodeId nodeId(const DiscreteVariable &var) const
See gum::IBaseBayesNet::nodeId().
NodeProperty< Size > _modalities_
InstanceBayesNet & operator=(const InstanceBayesNet &from)
Copy operator.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
InstanceBayesNet(const InstanceBayesNet &from)
Copy constructor.
virtual ~InstanceBayesNet()
Destructor.
const PRMInstance< GUM_SCALAR > * _inst_
The PRMClassElementContainer decorated by this.
const PRMClassElement< GUM_SCALAR > & _get_(NodeId id) const
Private getter with type checking in case the id is not a formal PRMAttribute<GUM_SCALAR>.
const PRMClassElement< GUM_SCALAR > & _get_(const std::string &name) const