1 /* Copyright (C) 2009 Charles Vaske [cvaske at soe dot ucsc dot edu]
2 University of California Santa Cruz
4 This file is part of libDAI.
6 libDAI is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libDAI is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libDAI; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 /// \brief Defines classes Evidence and SampleData
24 /// \todo Improve documentation
27 #ifndef __defined_libdai_evidence_h
28 #define __defined_libdai_evidence_h
32 #include <dai/daialg.h>
38 /// Stores a set of observations on a graphical model.
42 std::map
<Var
, size_t> _obs
;
44 /// Construct an empty object
45 SampleData() : _name(), _obs() {}
46 /// Set the name of the sample
47 void name(const std::string
& name
) { _name
= name
; }
48 /// Get the name of the sample
49 const std::string
& name() const { return _name
; }
50 /// Read from the observation map
51 const std::map
<Var
, size_t>& observations() const { return _obs
; }
52 /// Add an observation
53 void addObservation(Var node
, size_t setting
);
54 /// Add evidence by clamping variables to observed values.
55 void applyEvidence(InfAlg
& alg
) const;
59 /// Store observations from a graphical model.
62 std::map
<std::string
, SampleData
> _samples
;
64 /// Start with empty obects, then fill with calls to addEvidenceTabFile()
65 Evidence() : _samples() {}
67 /** Read in tab-data from a stream. Each line contains one sample, and
68 * the first line is a header line with names. The first column contains
69 * names for each of the samples.
71 void addEvidenceTabFile(std::istream
& is
, std::map
< std::string
, Var
>& varMap
);
73 /** Read in tab-data from a stream. Each line contains one sample,
74 * and the first line is a header line with variable IDs. The first
75 * column contains names for each of the samples.
77 void addEvidenceTabFile(std::istream
& is
, FactorGraph
& fg
);
79 /// Total number of samples in this evidence file
80 size_t nrSamples() const { return _samples
.size(); }
82 /// @name iterator interface
84 typedef std::map
< std::string
, SampleData
>::iterator iterator
;
85 typedef std::map
< std::string
, SampleData
>::const_iterator const_iterator
;
86 iterator
begin() { return _samples
.begin(); }
87 const_iterator
begin() const { return _samples
.begin(); }
88 iterator
end() { return _samples
.end(); }
89 const_iterator
end() const { return _samples
.end(); }
94 } // end of namespace dai