aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
concreteLeaf.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 the Concrete Leaf class.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 
30 // =========================================================================
31 #ifndef GUM_CONCRETE_LEAF_H
32 #define GUM_CONCRETE_LEAF_H
33 // =========================================================================
34 #include <agrum/agrum.h>
35 #include <agrum/tools/core/hashTable.h>
36 #include <agrum/tools/core/multiPriorityQueue.h>
37 #include <agrum/tools/core/sequence.h>
38 // =========================================================================
39 #include <agrum/tools/graphs/graphElements.h>
40 // =========================================================================
41 #include <agrum/FMDP/learning/core/templateStrategy.h>
42 #include <agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
43 #include <agrum/FMDP/learning/datastructure/nodeDatabase.h>
44 // =========================================================================
45 
46 namespace gum {
47 
48  /**
49  * @class ConcreteLeaf concreteLeaf.h
50  * <agrum/FMDP/learning/datastructure/leaves/concreteLeaf.h>
51  * @brief A concrete leaf
52  * @ingroup fmdp_group
53  *
54  */
55 
56 
57  template < TESTNAME AttributeSelection, bool isScalar >
58  class ConcreteLeaf: public AbstractLeaf {
59  typedef typename ValueSelect< isScalar, double, Idx >::type ValueType;
60 
61  public:
62  // ==========================================================================
63  /// @name Constructor & destructor.
64  // ==========================================================================
65  /// @{
66 
67  // ###################################################################
68  /// Default constructor
69  // ###################################################################
70  ConcreteLeaf(NodeId leafId,
71  NodeDatabase< AttributeSelection, isScalar >* n1,
72  const Sequence< ValueType >* valueDomain) :
75  GUM_CONSTRUCTOR(ConcreteLeaf);
76  }
77 
78  // ###################################################################
79  /// Default destructor
80  // ###################################################################
81  ~ConcreteLeaf() { GUM_DESTRUCTOR(ConcreteLeaf); }
82 
83  // ============================================================================
84  /// Allocators and Deallocators redefinition
85  // ============================================================================
86  void* operator new(size_t s) {
87  return SmallObjectAllocator::instance().allocate(s);
88  }
89  void operator delete(void* p) {
90  SmallObjectAllocator::instance().deallocate(p, sizeof(ConcreteLeaf));
91  }
92 
93  /// @}
94 
95  // ###################################################################
96  /// Gaves the leaf effectif for given modality
97  // ###################################################################
98  virtual double effectif(Idx moda) const {
99  return effectif__(moda, Int2Type< isScalar >());
100  }
101 
102  private:
103  double effectif__(Idx moda, Int2Type< true >) const {
104  return (double)n1__->effectif(Idx(valueDomain__->atPos(moda)));
105  }
106  double effectif__(Idx moda, Int2Type< false >) const {
107  return (double)n1__->effectif(moda);
108  }
109 
110  public:
111  virtual double total() const { return double(n1__->nbObservation()); }
112 
113  Idx nbModa() const { return nbModa__(Int2Type< isScalar >()); }
114 
115  private:
116  Idx nbModa__(Int2Type< true >) const { return valueDomain__->size(); }
117  Idx nbModa__(Int2Type< false >) const { return n1__->valueDomain(); }
118 
119  public:
121  std::stringstream ss;
122  ss << "{ Id : " << this->id() << "}";
123  return ss.str();
124  }
125 
126  private:
129  };
130 
131 
132 } /* namespace gum */
133 
134 
135 #endif // GUM_CONCRETE_LEAF_H
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: concreteLeaf.h:86
Idx nbModa__(Int2Type< false >) const
Definition: concreteLeaf.h:117
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
std::string toString()
Definition: concreteLeaf.h:120
Idx nbModa() const
Definition: concreteLeaf.h:113
NodeDatabase< AttributeSelection, isScalar > * n1__
Definition: concreteLeaf.h:127
const Sequence< ValueType > * valueDomain__
Definition: concreteLeaf.h:128
ValueSelect< isScalar, double, Idx >::type ValueType
Definition: concreteLeaf.h:59
~ConcreteLeaf()
Default destructor.
Definition: concreteLeaf.h:81
ConcreteLeaf(NodeId leafId, NodeDatabase< AttributeSelection, isScalar > *n1, const Sequence< ValueType > *valueDomain)
Default constructor.
Definition: concreteLeaf.h:70
virtual double total() const
Definition: concreteLeaf.h:111
double effectif__(Idx moda, Int2Type< false >) const
Definition: concreteLeaf.h:106
virtual double effectif(Idx moda) const
Gaves the leaf effectif for given modality.
Definition: concreteLeaf.h:98
void operator delete(void *p)
Default constructor.
Definition: concreteLeaf.h:89