1 /* This file is part of libDAI - http://www.libdai.org/
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
7 * Copyright (C) 2009 Charles Vaske [cvaske at soe dot ucsc dot edu]
8 * Copyright (C) 2009 University of California, Santa Cruz
13 /// \brief Defines class Evidence, which stores multiple observations of joint states of variables
16 #ifndef __defined_libdai_evidence_h
17 #define __defined_libdai_evidence_h
21 #include <dai/daialg.h>
27 /// Stores a data set consisting of multiple samples, where each sample is the observed joint state of some variables.
28 /** \note Each sample can describe the joint state of a different set of variables,
29 * in order to be able to deal with missing data.
31 * \author Charles Vaske
35 /// Stores joint state of a set of variables
36 typedef std::map
<Var
, size_t> Observation
;
39 /// Each sample is an observed joint state of some variables
40 std::vector
<Observation
> _samples
;
43 /// Default constructor
44 Evidence() : _samples() {}
46 /// Construct from \a samples
47 Evidence( std::vector
<Observation
> &samples
) : _samples(samples
) {}
49 /// Read in tabular data from a stream and add the read samples to \c *this.
50 /** \param is Input stream in .tab file format, describing joint observations of variables in \a fg
51 * \param fg Factor graph describing the corresponding variables
52 * \see \ref fileformats-evidence
53 * \throw INVALID_EVIDENCE_FILE if the input stream is not valid
55 void addEvidenceTabFile( std::istream
& is
, FactorGraph
& fg
);
57 /// Returns number of stored samples
58 size_t nrSamples() const { return _samples
.size(); }
60 /// \name Iterator interface
62 /// Iterator over the samples
63 typedef std::vector
<Observation
>::iterator iterator
;
64 /// Constant iterator over the samples
65 typedef std::vector
<Observation
>::const_iterator const_iterator
;
67 /// Returns iterator that points to the first sample
68 iterator
begin() { return _samples
.begin(); }
69 /// Returns constant iterator that points to the first sample
70 const_iterator
begin() const { return _samples
.begin(); }
71 /// Returns iterator that points beyond the last sample
72 iterator
end() { return _samples
.end(); }
73 /// Returns constant iterator that points beyond the last sample
74 const_iterator
end() const { return _samples
.end(); }
78 /// Read in tabular data from a stream and add the read samples to \c *this.
79 void addEvidenceTabFile( std::istream
& is
, std::map
<std::string
, Var
> &varMap
);
83 } // end of namespace dai