aGrUM  0.14.2
concreteLeaf.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 // =========================================================================
28 #ifndef GUM_CONCRETE_LEAF_H
29 #define GUM_CONCRETE_LEAF_H
30 // =========================================================================
31 #include <agrum/agrum.h>
32 #include <agrum/core/hashTable.h>
34 #include <agrum/core/sequence.h>
35 // =========================================================================
37 // =========================================================================
41 // =========================================================================
42 
43 namespace gum {
44 
54  template < TESTNAME AttributeSelection, bool isScalar >
55  class ConcreteLeaf : public AbstractLeaf {
57 
58  public:
59  // ==========================================================================
61  // ==========================================================================
63 
64  // ###################################################################
66  // ###################################################################
69  const Sequence< ValueType >* valueDomain) :
70  AbstractLeaf(leafId),
71  __n1(n1), __valueDomain(valueDomain) {
72  GUM_CONSTRUCTOR(ConcreteLeaf);
73  }
74 
75  // ###################################################################
77  // ###################################################################
78  ~ConcreteLeaf() { GUM_DESTRUCTOR(ConcreteLeaf); }
79 
80  // ============================================================================
82  // ============================================================================
83  void* operator new(size_t s) {
85  }
86  void operator delete(void* p) {
88  }
89 
91 
92  // ###################################################################
94  // ###################################################################
95  virtual double effectif(Idx moda) const {
96  return __effectif(moda, Int2Type< isScalar >());
97  }
98 
99  private:
100  double __effectif(Idx moda, Int2Type< true >) const {
101  return (double)__n1->effectif(Idx(__valueDomain->atPos(moda)));
102  }
103  double __effectif(Idx moda, Int2Type< false >) const {
104  return (double)__n1->effectif(moda);
105  }
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:
117  std::string toString() {
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
Template trick for efficient development.
Priority queues in which the same element can appear several times.
Headers of the abstract Leaf class.
double __effectif(Idx moda, Int2Type< false >) const
Definition: concreteLeaf.h:103
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
std::string toString()
Definition: concreteLeaf.h:117
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1019
<agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
Definition: abstractLeaf.h:50
Idx nbModa() const
Definition: concreteLeaf.h:110
const Sequence< ValueType > * __valueDomain
Definition: concreteLeaf.h:125
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
ValueSelect< isScalar, double, Idx >::type ValueType
Definition: concreteLeaf.h:56
<agrum/FMDP/learning/datastructure/leaves/concreteLeaf.h>
Definition: concreteLeaf.h:55
~ConcreteLeaf()
Default destructor.
Definition: concreteLeaf.h:78
double __effectif(Idx moda, Int2Type< true >) const
Definition: concreteLeaf.h:100
ConcreteLeaf(NodeId leafId, NodeDatabase< AttributeSelection, isScalar > *n1, const Sequence< ValueType > *valueDomain)
Default constructor.
Definition: concreteLeaf.h:67
Headers of the NodeDatabase class.
virtual double total() const
Definition: concreteLeaf.h:108
Idx __nbModa(Int2Type< false >) const
Definition: concreteLeaf.h:114
Idx __nbModa(Int2Type< true >) const
Definition: concreteLeaf.h:113
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
virtual double effectif(Idx moda) const
Gaves the leaf effectif for given modality.
Definition: concreteLeaf.h:95
NodeDatabase< AttributeSelection, isScalar > * __n1
Definition: concreteLeaf.h:124
Size Idx
Type for indexes.
Definition: types.h:50
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()
Class hash tables iterators.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
some utils for topology : NodeId, Edge, Arc and consorts ...
<agrum/FMDP/learning/datastructure/nodeDatabase.h>
Definition: nodeDatabase.h:55