#include <Signature.h>
Public Types | |
typedef std::vector< double > | Row |
typedef std::vector< Row > | Table |
Public Member Functions | |
std::vector< double > | cpt () const |
DiscreteKeys | discreteKeys () const |
KeyVector | indices () const |
const DiscreteKey & | key () const |
Signature & | operator, (const DiscreteKey &parent) |
Signature & | operator= (const std::string &spec) |
Signature & | operator= (const Table &table) |
const DiscreteKeys & | parents () const |
Signature (const DiscreteKey &key, const DiscreteKeys &parents, const Table &table) | |
Signature (const DiscreteKey &key, const DiscreteKeys &parents, const std::string &spec) | |
Signature (const DiscreteKey &key) | |
const std::optional< Table > & | table () const |
Private Attributes | |
DiscreteKey | key_ |
DiscreteKeys | parents_ |
std::optional< std::string > | spec_ |
std::optional< Table > | table_ |
Friends | |
GTSAM_EXPORT friend std::ostream & | operator<< (std::ostream &os, const Signature &s) |
Signature for a discrete conditional distribution, used to construct conditionals.
The format is (Key % string) for nodes with no parents, and (Key | Key, Key = string) for nodes with parents.
The string specifies a conditional probability table in 00 01 10 11 order. For three-valued, it would be 00 01 02 10 11 12 20 21 22, etc...
For example, given the following keys
Key A("Asia"), S("Smoking"), T("Tuberculosis"), L("LungCancer"), B("Bronchitis"), E("Either"), X("XRay"), D("Dyspnoea");
These are all valid signatures (Asia network example):
A % "99/1" S % "50/50" T|A = "99/1 95/5" L|S = "99/1 90/10" B|S = "70/30 40/60" (E|T,L) = "F F F 1" X|E = "95/5 2/98" (D|E,B) = "9/1 2/8 3/7 1/9"
Definition at line 54 of file Signature.h.
typedef std::vector<double> gtsam::Signature::Row |
Data type for the CPT
Definition at line 59 of file Signature.h.
typedef std::vector<Row> gtsam::Signature::Table |
Definition at line 60 of file Signature.h.
gtsam::Signature::Signature | ( | const DiscreteKey & | key, |
const DiscreteKeys & | parents, | ||
const Table & | table | ||
) |
Construct from key, parents, and a Signature::Table specifying the conditional probability table (CPT) in 00 01 10 11 order. For three-valued, it would be 00 01 02 10 11 12 20 21 22, etc....
The first string is parsed to add a key and parents.
Example: Signature::Table table{{0.9, 0.1}, {0.2, 0.8}, {0.3, 0.7}, {0.1, 0.9}}; Signature sig(D, {E, B}, table);
Definition at line 41 of file Signature.cpp.
gtsam::Signature::Signature | ( | const DiscreteKey & | key, |
const DiscreteKeys & | parents, | ||
const std::string & | spec | ||
) |
Construct from key, parents, and a string specifying the conditional probability table (CPT) in 00 01 10 11 order. For three-valued, it would be 00 01 02 10 11 12 20 21 22, etc....
The first string is parsed to add a key and parents. The second string parses into a table.
Example (same CPT as above): Signature sig(D, {B,E}, "9/1 2/8 3/7 1/9");
Definition at line 47 of file Signature.cpp.
gtsam::Signature::Signature | ( | const DiscreteKey & | key | ) |
Construct from a single DiscreteKey.
The resulting signature has no parents or CPT table. Typical use then either adds parents with | and , operators below, or assigns a table with operator=().
Definition at line 53 of file Signature.cpp.
vector< double > gtsam::Signature::cpt | ( | ) | const |
Definition at line 69 of file Signature.cpp.
DiscreteKeys gtsam::Signature::discreteKeys | ( | ) | const |
All keys, with variable key first
Definition at line 55 of file Signature.cpp.
KeyVector gtsam::Signature::indices | ( | ) | const |
All key indices, with variable key first
Definition at line 62 of file Signature.cpp.
|
inline |
the variable key
Definition at line 115 of file Signature.h.
Signature & gtsam::Signature::operator, | ( | const DiscreteKey & | parent | ) |
Add a parent
Definition at line 83 of file Signature.cpp.
Signature & gtsam::Signature::operator= | ( | const std::string & | spec | ) |
Add the CPT spec
Definition at line 94 of file Signature.cpp.
Add the CPT spec directly as a table
Definition at line 104 of file Signature.cpp.
|
inline |
the parent keys
Definition at line 118 of file Signature.h.
|
inline |
Definition at line 127 of file Signature.h.
|
friend |
provide streaming
|
private |
the variable key
Definition at line 65 of file Signature.h.
|
private |
the parent keys
Definition at line 68 of file Signature.h.
|
private |
Definition at line 71 of file Signature.h.
|
private |
Definition at line 74 of file Signature.h.