aGrUM  0.14.2
structuredBayesBall.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #include <sstream>
28 #include <string>
29 #include <utility>
30 
31 #include <agrum/core/hashTable.h>
32 #include <agrum/core/set.h>
33 
34 #include <agrum/PRM/PRM.h>
36 
37 #ifndef GUM_STRUCTURED_BB_H
38 # define GUM_STRUCTURED_BB_H
39 namespace gum {
40  namespace prm {
41 
47  template < typename GUM_SCALAR >
49  public:
50  // ========================================================================
52  // ========================================================================
54 
57 
60 
62  // ========================================================================
64  // ========================================================================
66 
68  const std::string& key(const PRMInstance< GUM_SCALAR >* i) const;
69 
71  const std::string& key(const PRMInstance< GUM_SCALAR >& i) const;
72 
74  const Set< NodeId >&
76 
78  const Set< NodeId >&
80 
83  Size occurrence(const std::string& key) const;
84 
87  float liftRatio() const;
88 
90  bool exists(const PRMInstance< GUM_SCALAR >* i) const;
91 
93  bool exists(const PRMInstance< GUM_SCALAR >& i) const;
94 
96 
100  void compute(const PRMInstance< GUM_SCALAR >* i, NodeId n);
101 
105  void compute(const PRMInstance< GUM_SCALAR >& i, NodeId n);
106 
109 
110  private:
113 
116 
122  std::pair< bool, bool >& __getMark(InstanceMap& marks,
123  const PRMInstance< GUM_SCALAR >* i,
124  NodeId n);
127  NodeId n);
128 
130  void __clean();
131 
133  void __compute(const PRMInstance< GUM_SCALAR >* i, NodeId n);
134 
137  NodeId n,
138  InstanceMap& marks);
139 
142  NodeId n,
143  InstanceMap& marks);
144 
146  void __fillMaps(InstanceMap& marks);
147 
149  std::string __buildHashKey(const PRMInstance< GUM_SCALAR >* i,
150  Set< NodeId >& req_nodes);
151 
154 
159  HashTable< const PRMInstance< GUM_SCALAR >*,
160  std::pair< std::string, Set< NodeId >* > >
162 
166  };
167 
168 
169 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
170  extern template class StructuredBayesBall< double >;
171 # endif
172 
173 
174  } /* namespace prm */
175 } /* namespace gum */
176 
178 
179 #endif /* GUM_STRUCTURED_BB_H */
<agrum/PRM/structuredBayesBall.h>
Sets of elements (i.e.
const Set< NodeId > & requisiteNodes(const PRMInstance< GUM_SCALAR > *i) const
Returns the set of requisite nodes w.r.t. d-separation for i.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:60
Headers of PRM.
std::pair< bool, bool > & __getMark(InstanceMap &marks, const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
void compute(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Compute the set or requisite nodes for each required instance given the current set of observations...
bool __isHardEvidence(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Returns true if there is a hard evidence on i->get(n).
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
HashTable< const PRMInstance< GUM_SCALAR > *, std::pair< std::string, Set< NodeId > *> > __keyMap
Associate an PRMInstance<GUM_SCALAR> with a unique key w.r.t. d-separation and the set of requisite n...
The class for generic Hash Tables.
Definition: hashTable.h:676
HashTable< std::string, std::pair< Set< NodeId > *, Size > > __reqMap
Associate a Key with the set of requisite nodes associated with it. The Size value is the number of i...
void __fillMaps(InstanceMap &marks)
Fill __keyMap and __reqMap.
bool exists(const PRMInstance< GUM_SCALAR > *i) const
Returns true if i has requisite nodes.
HashTable< NodeId, std::pair< bool, bool > > MarkMap
Code alias.
void __fromChild(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is received on i->get(n) from a child.
Size occurrence(const std::string &key) const
Returns the number of occurrence of the given key, which is the number of PRMInstance<GUM_SCALAR> sha...
StructuredBayesBall & operator=(const StructuredBayesBall &source)
Copy operator.
Headers of PRMInference.
std::string __buildHashKey(const PRMInstance< GUM_SCALAR > *i, Set< NodeId > &req_nodes)
Builds the HashKey for the given instance and requisite nodes set.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Definition: PRMObject.h:218
const std::string & key(const PRMInstance< GUM_SCALAR > *i) const
Returns a unique key w.r.t. d-separation for i.
void __clean()
Cleans this before a new computation.
const PRMSlotChain< GUM_SCALAR > & __getSC(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
Inline implementation of StructuredBayesBall.
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
Definition: PRMInference.h:49
StructuredBayesBall(const PRMInference< GUM_SCALAR > &inference)
Default Constructor.
const PRMInference< GUM_SCALAR > * __inf
The PRM at which __model belongs.
void __compute(const PRMInstance< GUM_SCALAR > *i, NodeId n)
The real compute method.
HashTable< const PRMInstance< GUM_SCALAR > *, MarkMap *> InstanceMap
Code alias.
float liftRatio() const
Returns the ratio between the total number of instances and the number of instances with the same con...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
void __fromParent(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is receive on i->get(n) from a parent.
Class hash tables iterators.
Size NodeId
Type for node ids.
Definition: graphElements.h:97