aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
gum::KTBNModality Class Reference

A parent's value in gum::KTBN::fillCPT(): a modality index or a modality label. More...

#include <agrum/KTBN/KTBN.h>

Collaboration diagram for gum::KTBNModality:
[legend]

Public Member Functions

template<std::integral T>
 KTBNModality (T modality)
 From a modality index.
 KTBNModality (const char *modality)
 From a modality label.
 KTBNModality (std::string modality)
 From a modality label.
Idx toIndex (const DiscreteVariable &var) const
 Resolves this value to a modality index of var, looking the label up when one was given.

Public Attributes

bool isLabel
 Whether the value was spelled as a label rather than an index.
Idx index {}
 The index, when isLabel is false.
std::string label
 The label, when isLabel is true.

Detailed Description

A parent's value in gum::KTBN::fillCPT(): a modality index or a modality label.

Implicitly built from either spelling, so a single fillCPT() signature serves both and one parent map may mix them:

m.fillCPT("X", 1, {{{"X", 0}, 1}, {{"C", KTBN::ATEMPORAL}, "high"}}, {0.6, 0.4});
static constexpr int ATEMPORAL
Conventional time-slice value denoting an atemporal (static) variable.
Definition KTBN.h:200
Warning
An unquoted integer is always an index, a quoted string always a label. The two differ for a variable whose modalities are themselves numeric: on a RangeVariable over 2..5, 2 is the third modality (the one labelled "4") while "2" is the first. Quote the value whenever you mean the label.
Note
Two overloads differing only in the value type (Idx vs std::string) would be ambiguous for every braced argument, a braced list having no type to resolve on — hence this wrapper.

Definition at line 95 of file KTBN.h.

Constructor & Destructor Documentation

◆ KTBNModality() [1/3]

template<std::integral T>
gum::KTBNModality::KTBNModality ( T modality)

From a modality index.

Definition at line 71 of file KTBN_tpl.h.

71: isLabel(false), index(static_cast< Idx >(modality)) {}
Size Idx
Type for indexes.
Definition types.h:79
Idx index
The index, when isLabel is false.
Definition KTBN.h:118
bool isLabel
Whether the value was spelled as a label rather than an index.
Definition KTBN.h:116

References index, and isLabel.

◆ KTBNModality() [2/3]

gum::KTBNModality::KTBNModality ( const char * modality)

From a modality label.

◆ KTBNModality() [3/3]

gum::KTBNModality::KTBNModality ( std::string modality)

From a modality label.

Member Function Documentation

◆ toIndex()

Idx gum::KTBNModality::toIndex ( const DiscreteVariable & var) const

Resolves this value to a modality index of var, looking the label up when one was given.

Exceptions
NotFound/ OutOfBounds if the index is out of var's domain or the label is not one of its modalities (which of the two is raised for an unknown label depends on the variable type).

Referenced by gum::KTBNInference< GUM_SCALAR >::addIntervention(), and gum::KTBNInference< GUM_SCALAR >::addObservation().

Here is the caller graph for this function:

Member Data Documentation

◆ index

Idx gum::KTBNModality::index {}

The index, when isLabel is false.

Definition at line 118 of file KTBN.h.

Referenced by KTBNModality().

◆ isLabel

bool gum::KTBNModality::isLabel

Whether the value was spelled as a label rather than an index.

Definition at line 116 of file KTBN.h.

Referenced by KTBNModality().

◆ label

std::string gum::KTBNModality::label

The label, when isLabel is true.

Definition at line 120 of file KTBN.h.


The documentation for this class was generated from the following files: