aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
PRMScalarAttribute.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 gum::PRMScalarAttribute.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_SCALAR_ATTRIBUTE_H
30 #define GUM_SCALAR_ATTRIBUTE_H
31 
32 #include <agrum/agrum.h>
33 #include <agrum/tools/core/bijection.h>
34 #include <agrum/tools/multidim/potential.h>
35 #include <agrum/PRM/elements/PRMAttribute.h>
36 
37 
38 namespace gum {
39  namespace prm {
40 
41  /**
42  * @class PRMScalarAttribute scalarAttribute.h
43  *<agrum/PRM/elements/scalarAttribute.h>
44  * @brief PRMScalarAttribute is a member of a Class in a PRM.
45  *
46  * A PRMScalarAttribute is defined by its name, its containing class, its
47  *type
48  *and
49  * by a Conditional Probability Function (aka CPF but represented by a
50  * Potential).
51  *
52  * An attribute in a PRM is the equivalent of a random variable in a
53  *bayesian
54  * network.
55  *
56  * This class is constructed by a gum::PRMFactory and is deleted by its
57  * gum::Class.
58  *
59  * Built-in copies (copy constructor and copy operator) are illegal due to
60  * various problems raised by redondant information.
61  *
62  * @see PRM PRMFactory Class PRMClassElement PRMType Potential
63  * @ingroup prm_group
64  */
65  template < typename GUM_SCALAR >
67  public:
68  // ========================================================================
69  /// @name Constructor & destructor.
70  // ========================================================================
71  /// @{
72 
73  /**
74  * @brief Constructor used by gum::Class.
75  * This will create an PRMAttribute with only one variable: type and with
76  * the
77  * given
78  * implementation.
79  * @param name The name of this PRMAttribute.
80  * @param type The type of this PRMAttribute, it is copied.
81  * @param impl The MultiDimImplementation used by the internal Potential
82  * of this PRMAttribute.
83  * it will be deleted after the call of ~PRMAttribute.
84  */
85  PRMScalarAttribute(const std::string& name,
86  const PRMType& type,
87  MultiDimImplementation< GUM_SCALAR >* impl
88  = new MultiDimArray< GUM_SCALAR >());
89 
90  /// Destructor.
91  virtual ~PRMScalarAttribute();
92 
93  /// @}
94  // ========================================================================
95  /// @name Getters & setters
96  // ========================================================================
97  /// @{
98 
99  virtual PRMAttribute< GUM_SCALAR >* newFactory(const PRMClass< GUM_SCALAR >& c) const;
100  virtual PRMAttribute< GUM_SCALAR >*
101  copy(Bijection< const DiscreteVariable*, const DiscreteVariable* > bij) const;
102 
103  virtual void copyCpf(const Bijection< const DiscreteVariable*, const DiscreteVariable* >& bif,
104  const PRMAttribute< GUM_SCALAR >& source);
105 
106  /// See gum::PRMClassElement::elt_type().
107  virtual typename PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const;
108 
109  /// See gum::PRMClassElement::type().
110  virtual PRMType& type();
111 
112  /// See gum::PRMClassElement::type().
113  virtual const PRMType& type() const;
114 
115  /// See gum::PRMClassElement::cpf().
116  virtual const Potential< GUM_SCALAR >& cpf() const;
117 
118  /// See gum::PRMClassElement::addParent_().
119  virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt);
120 
121  /// See gum::PRMClassElement::addChild_().
122  virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt);
123 
124  virtual PRMAttribute< GUM_SCALAR >* getCastDescendant() const;
125  virtual void setAsCastDescendant(PRMAttribute< GUM_SCALAR >* attr);
126  virtual void becomeCastDescendant(PRMType& subtype);
127 
128  /// Swap old_type with new_type in the PRMClassElement cpt.
129  virtual void swap(const PRMType& old_type, const PRMType& new_type);
130 
131  /// @}
132  protected:
133  /// Copy constructor. Don't use it.
134  PRMScalarAttribute(const PRMScalarAttribute& source);
135 
136  /// Copy operator. Don't use it.
138 
139  virtual PRMType* type_();
140  virtual void type_(PRMType* t);
141 
142  private:
143  // ========================================================================
144  /// @name Private members
145  // ========================================================================
146  /// @{
147 
148  /// The random variable type of this attribute
150 
151  /// A pointer on the Potential of this attribute
153 
154  /// @}
155  };
156 
157 
158 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
159  extern template class PRMScalarAttribute< double >;
160 #endif
161 
162 
163  } /* namespace prm */
164 } // namespace gum
165 
166 #include <agrum/PRM/elements/PRMScalarAttribute_tpl.h>
167 
168 #endif /* GUM_SCALAR_ATTRIBUTE_H */
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::addChild_().
virtual void becomeCastDescendant(PRMType &subtype)
See gum::PRMClassElement::elt_type().
virtual ~PRMScalarAttribute()
Destructor.
virtual void swap(const PRMType &old_type, const PRMType &new_type)
Swap old_type with new_type in the PRMClassElement cpt.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
PRMType * _type_
The random variable type of this attribute.
virtual PRMType & type()
See gum::PRMClassElement::type().
virtual PRMAttribute< GUM_SCALAR > * newFactory(const PRMClass< GUM_SCALAR > &c) const
See gum::PRMClassElement::elt_type().
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
See gum::PRMClassElement::elt_type().
virtual void copyCpf(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)
See gum::PRMClassElement::elt_type().
virtual const Potential< GUM_SCALAR > & cpf() const
See gum::PRMClassElement::cpf().
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
virtual PRMAttribute< GUM_SCALAR > * copy(Bijection< const DiscreteVariable *, const DiscreteVariable * > bij) const
See gum::PRMClassElement::elt_type().
PRMScalarAttribute(const PRMScalarAttribute &source)
Copy constructor. Don&#39;t use it.
virtual void setAsCastDescendant(PRMAttribute< GUM_SCALAR > *attr)
See gum::PRMClassElement::elt_type().
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const
See gum::PRMClassElement::elt_type().
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::addParent_().
virtual void type_(PRMType *t)
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
PRMScalarAttribute(const std::string &name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
Constructor used by gum::Class.
virtual const PRMType & type() const
See gum::PRMClassElement::type().
PRMScalarAttribute & operator=(const PRMScalarAttribute &from)
Copy operator. Don&#39;t use it.