Fixed three minor issues
[libdai.git] / include / dai / evidence.h
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
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.
6 *
7 * Copyright (C) 2009 Charles Vaske [cvaske at soe dot ucsc dot edu]
8 * Copyright (C) 2009 University of California, Santa Cruz
9 */
10
11
12 /// \file
13 /// \brief Defines class Evidence, which stores multiple observations of joint states of variables
14
15
16 #ifndef __defined_libdai_evidence_h
17 #define __defined_libdai_evidence_h
18
19
20 #include <istream>
21 #include <dai/daialg.h>
22
23
24 namespace dai {
25
26
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.
30 *
31 * \author Charles Vaske
32 */
33 class Evidence {
34 public:
35 /// Stores joint state of a set of variables
36 typedef std::map<Var, size_t> Observation;
37
38 private:
39 /// Each sample is an observed joint state of some variables
40 std::vector<Observation> _samples;
41
42 public:
43 /// Default constructor
44 Evidence() : _samples() {}
45
46 /// Construct from \a samples
47 Evidence( std::vector<Observation> &samples ) : _samples(samples) {}
48
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
54 */
55 void addEvidenceTabFile( std::istream& is, FactorGraph& fg );
56
57 /// Returns number of stored samples
58 size_t nrSamples() const { return _samples.size(); }
59
60 /// \name Iterator interface
61 //@{
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;
66
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(); }
75 //@}
76
77 private:
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 );
80 };
81
82
83 } // end of namespace dai
84
85
86 #endif