1 /* This file is part of libDAI - http://www.libdai.org/
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
10 /// \brief Defines class Evidence, which stores multiple observations of joint states of variables
13 #ifndef __defined_libdai_evidence_h
14 #define __defined_libdai_evidence_h
18 #include <dai/daialg.h>
24 /// Stores a data set consisting of multiple samples, where each sample is the observed joint state of some variables.
25 /** \note Each sample can describe the joint state of a different set of variables,
26 * in order to be able to deal with missing data.
28 * \author Charles Vaske
32 /// Stores joint state of a set of variables
33 typedef std::map
<Var
, size_t> Observation
;
36 /// Each sample is an observed joint state of some variables
37 std::vector
<Observation
> _samples
;
40 /// Default constructor
41 Evidence() : _samples() {}
43 /// Construct from \a samples
44 Evidence( std::vector
<Observation
> &samples
) : _samples(samples
) {}
46 /// Read in tabular data from a stream and add the read samples to \c *this.
47 /** \param is Input stream in .tab file format, describing joint observations of variables in \a fg
48 * \param fg Factor graph describing the corresponding variables
49 * \see \ref fileformats-evidence
50 * \throw INVALID_EVIDENCE_FILE if the input stream is not valid
52 void addEvidenceTabFile( std::istream
& is
, FactorGraph
& fg
);
54 /// Returns number of stored samples
55 size_t nrSamples() const { return _samples
.size(); }
57 /// \name Iterator interface
59 /// Iterator over the samples
60 typedef std::vector
<Observation
>::iterator iterator
;
61 /// Constant iterator over the samples
62 typedef std::vector
<Observation
>::const_iterator const_iterator
;
64 /// Returns iterator that points to the first sample
65 iterator
begin() { return _samples
.begin(); }
66 /// Returns constant iterator that points to the first sample
67 const_iterator
begin() const { return _samples
.begin(); }
68 /// Returns iterator that points beyond the last sample
69 iterator
end() { return _samples
.end(); }
70 /// Returns constant iterator that points beyond the last sample
71 const_iterator
end() const { return _samples
.end(); }
75 /// Read in tabular data from a stream and add the read samples to \c *this.
76 void addEvidenceTabFile( std::istream
& is
, std::map
<std::string
, Var
> &varMap
);
80 } // end of namespace dai