aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
concreteLeaf.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 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  // ###################################################################
82  GUM_DESTRUCTOR(ConcreteLeaf);
83  ;
84  }
85 
86  // ============================================================================
87  /// Allocators and Deallocators redefinition
88  // ============================================================================
89  void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
90  void operator delete(void* p) {
91  SmallObjectAllocator::instance().deallocate(p, sizeof(ConcreteLeaf));
92  }
93 
94  /// @}
95 
96  // ###################################################################
97  /// Gaves the leaf effectif for given modality
98  // ###################################################################
99  virtual double effectif(Idx moda) const { return _effectif_(moda, Int2Type< isScalar >()); }
100 
101  private:
102  double _effectif_(Idx moda, Int2Type< true >) const {
103  return (double)_n1_->effectif(Idx(_valueDomain_->atPos(moda)));
104  }
105  double _effectif_(Idx moda, Int2Type< false >) const { return (double)_n1_->effectif(moda); }
106 
107  public:
108  virtual double total() const { return double(_n1_->nbObservation()); }
109 
110  Idx nbModa() const { return _nbModa_(Int2Type< isScalar >()); }
111 
112  private:
113  Idx _nbModa_(Int2Type< true >) const { return _valueDomain_->size(); }
114  Idx _nbModa_(Int2Type< false >) const { return _n1_->valueDomain(); }
115 
116  public:
118  std::stringstream ss;
119  ss << "{ Id : " << this->id() << "}";
120  return ss.str();
121  }
122 
123  private:
126  };
127 
128 
129 } /* namespace gum */
130 
131 
132 #endif // GUM_CONCRETE_LEAF_H
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: concreteLeaf.h:89
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
std::string toString()
Definition: concreteLeaf.h:117
const Sequence< ValueType > * _valueDomain_
Definition: concreteLeaf.h:125
Idx nbModa() const
Definition: concreteLeaf.h:110
Idx _nbModa_(Int2Type< false >) const
Definition: concreteLeaf.h:114
NodeDatabase< AttributeSelection, isScalar > * _n1_
Definition: concreteLeaf.h:124
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:108
virtual double effectif(Idx moda) const
Gaves the leaf effectif for given modality.
Definition: concreteLeaf.h:99
double _effectif_(Idx moda, Int2Type< false >) const
Definition: concreteLeaf.h:105
void operator delete(void *p)
Default constructor.
Definition: concreteLeaf.h:90