2 Copyright 2009 Charles Vaske <cvaske@soe.ucsc.edu>
3 University of California Santa Cruz
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef __defined_libdai_evidence_h
20 #define __defined_libdai_evidence_h
24 #include <dai/daialg.h>
28 /// Store joint observations on a graphical model.
32 std::map
<Var
, size_t> _obs
;
34 /// Construct an empty object
35 SampleData() : _name(), _obs() {}
36 /// Set the name of the sample
37 void name(const std::string
& name
) { _name
= name
; }
38 /// Get the name of the sample
39 const std::string
& name() const { return _name
; }
40 /// Read from the observation map
41 const std::map
<Var
, size_t>& observations() const { return _obs
; }
42 /// Add an observation
43 void addObservation(Var node
, size_t setting
);
44 /// Add evidence by clamping variables to observed values.
45 void applyEvidence(InfAlg
& alg
) const;
48 /// Store observations from a graphical model.
51 std::map
< std::string
, SampleData
> _samples
;
53 /// Start with empty obects, then fill with calls to addEvidenceTabFile()
54 Evidence() : _samples() {}
56 /** Read in tab-data from a stream. Each line contains one sample, and
57 * the first line is a header line with names. The first column contains
58 * names for each of the samples.
60 void addEvidenceTabFile(std::istream
& is
,
61 std::map
< std::string
, Var
>& varMap
);
63 /** Read in tab-data from a stream. Each line contains one sample,
64 * and the first line is a header line with variable IDs. The first
65 * column contains names for each of the samples.
67 void addEvidenceTabFile(std::istream
& is
, FactorGraph
& fg
);
69 /// Total number of samples in this evidence file
70 size_t nrSamples() const { return _samples
.size(); }
72 /// @name iterator interface
74 typedef std::map
< std::string
, SampleData
>::iterator iterator
;
75 typedef std::map
< std::string
, SampleData
>::const_iterator const_iterator
;
76 iterator
begin() { return _samples
.begin(); }
77 const_iterator
begin() const { return _samples
.begin(); }
78 iterator
end() { return _samples
.end(); }
79 const_iterator
end() const { return _samples
.end(); }