versatile-mcmc
0.1.7
Main Page
Classes
Files
File List
File Members
vmcmc
io.hpp
Go to the documentation of this file.
1
14
#ifndef VMCMC_IO_H_
15
#define VMCMC_IO_H_
16
17
#include <
vmcmc/chain.hpp
>
18
#include <
vmcmc/parameter.hpp
>
19
20
#include <string>
21
#include <fstream>
22
#include <memory>
23
#include <vector>
24
#include <deque>
25
#include <chrono>
26
27
class
Gnuplot;
28
29
namespace
vmcmc
30
{
31
38
class
Writer
39
{
40
protected
:
41
Writer
() { };
42
virtual
~
Writer
() { };
43
44
public
:
45
virtual
void
Initialize(
size_t
/*numberOfChains*/
,
const
ParameterConfig
&
/*paramConfig*/
) { }
46
virtual
void
Write(
size_t
chainIndex,
const
Chain& chain,
size_t
startIndex) = 0;
47
virtual
void
Finalize() { }
48
49
void
Write(
size_t
chainIndex,
const
Sample
& sample);
50
};
51
55
class
TextFileWriter
:
public
Writer
56
{
57
public
:
58
TextFileWriter
(
const
std::string& directory =
""
,
const
std::string& stem =
"vmcmc"
,
59
const
std::string& nameSeparator =
"-"
,
const
std::string& extension =
".txt"
);
60
virtual
~
TextFileWriter
();
61
62
TextFileWriter
(
const
TextFileWriter
& other);
63
64
void
SetFileNameScheme(
const
std::string& directory,
const
std::string& stem,
65
const
std::string& nameSeparator =
"-"
,
const
std::string& extension =
".txt"
);
66
void
SetPrecision(
int
prec) { fPrecision = prec; }
67
void
SetCombineChains(
bool
combine) { fCombineChains = combine; }
68
void
SetColumnSeparator(
const
std::string& sep) { fColumnSep = sep; }
69
70
std::string GetFilePath(
int
chainIndex = -1)
const
;
71
72
virtual
void
Initialize(
size_t
numberOfChains,
const
ParameterConfig
& paramConfig)
override
;
73
virtual
void
Write(
size_t
chainIndex,
const
Chain& chain,
size_t
startIndex)
override
;
74
75
using
Writer::Write;
76
77
std::string fFileDirectory;
78
std::string fFileStem;
79
std::string fFileSeparator;
80
std::string fFileExtension;
81
82
int
fPrecision = 12;
83
std::string fColumnSep =
"\t"
;
84
bool
fCombineChains =
false
;
85
std::vector<std::unique_ptr<std::ofstream>> fFileStreams;
86
};
87
89
// * Near-time graphic visualization of each chain's evolution.
90
// *
91
// * HIGHLY EXPERIMENTAL.
92
// */
93
//class GnuplotWriter: public Writer
94
//{
95
//public:
96
// GnuplotWriter();
97
// virtual ~GnuplotWriter();
98
//
99
// virtual void Initialize(size_t numberOfChains, const ParameterConfig& paramConfig) override;
100
// virtual void Write(size_t chainIndex, const Chain& chain, size_t startIndex) override;
101
// virtual void Finalize() override;
102
//
103
//protected:
104
// void Replot(bool force = false);
105
//
106
//private:
107
// ParameterConfig fParameterConfig;
108
// size_t fNumberOfChains = 0;
109
//
110
// std::vector<std::unique_ptr<Gnuplot>> fGnuplotWindows;
111
//
112
// std::vector<std::deque<double>> fGenerationBuffers;
113
// std::vector<std::vector<std::deque<double>>> fValueBuffers;
114
// size_t fMaxBufferSize = 300;
115
//
116
// int fRefreshRateInMs = 5000;
117
// std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> fLastPlotTime;
118
//};
119
120
}
/* namespace vmcmc */
121
122
#endif
/* VMCMC_IO_H_ */
vmcmc::Writer
Abstract base class for mechanisms writing output files or producing visual output.
Definition:
io.hpp:38
vmcmc
Definition:
algorithm.cpp:28
vmcmc::ParameterConfig
A list of parameters, describing the parameter space of the target function to be evaluated...
Definition:
parameter.hpp:109
chain.hpp
Utility classes for calculation statistical momenta and diagnostics.
vmcmc::TextFileWriter
A writer streaming incoming samples to textfiles.
Definition:
io.hpp:55
parameter.hpp
Class definitions representing input parameter configurations.
vmcmc::Sample
A 'sample' represents a node or data point in a Markov Chain.
Definition:
sample.hpp:31
Generated by
1.8.11