1 | /*! |
---|
2 | \file |
---|
3 | \brief Loggers for storing results of experiments |
---|
4 | \author Vaclav Smidl. |
---|
5 | |
---|
6 | ----------------------------------- |
---|
7 | BDM++ - C++ library for Bayesian Decision Making under Uncertainty |
---|
8 | |
---|
9 | Using IT++ for numerical operations |
---|
10 | ----------------------------------- |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef LGR_H |
---|
14 | #define LGR_H |
---|
15 | |
---|
16 | #include "libBM.h" |
---|
17 | |
---|
18 | namespace bdm{ |
---|
19 | using std::string; |
---|
20 | |
---|
21 | /*! |
---|
22 | * \brief Logging into matrices in data format in memory |
---|
23 | |
---|
24 | * More?... |
---|
25 | */ |
---|
26 | |
---|
27 | class memlog : public logger { |
---|
28 | |
---|
29 | protected: |
---|
30 | //! Maximum length of vectors stored in memory |
---|
31 | int maxlen; |
---|
32 | //! Currect record to be written |
---|
33 | int ind; |
---|
34 | //! Storage |
---|
35 | Array<mat> vectors; |
---|
36 | //! |
---|
37 | public: |
---|
38 | //!Default constructor |
---|
39 | memlog ( int maxlen0 ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ) {} |
---|
40 | //! Initialize storage |
---|
41 | void init() { |
---|
42 | int i; int n =entries.length(); |
---|
43 | vectors.set_size ( n ); |
---|
44 | for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i).count() );} |
---|
45 | ; |
---|
46 | } |
---|
47 | void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );} |
---|
48 | void logit ( int id, const vec &v ) { |
---|
49 | it_assert_debug(id<vectors.length(),"Logger was not initialized, run init()."); |
---|
50 | vectors ( id ).set_row ( ind,v );} |
---|
51 | //! Save values into an itfile named after \c fname. |
---|
52 | void itsave(const char* fname); |
---|
53 | }; |
---|
54 | |
---|
55 | /*! |
---|
56 | * \brief Logging into dirfile with buffer in memory |
---|
57 | |
---|
58 | * Dirfile is a special format used by the kst program. See documentation of kst for description. |
---|
59 | * |
---|
60 | * This format is used to store scalars, hence multivariate RVs must be separated. |
---|
61 | */ |
---|
62 | |
---|
63 | class dirfilelog : public memlog { |
---|
64 | |
---|
65 | protected: |
---|
66 | //!name of the directory |
---|
67 | string dirname; |
---|
68 | //! Automatically generated |
---|
69 | Array<string> scalarnames; |
---|
70 | public: |
---|
71 | /*!\brief Default constructor |
---|
72 | @param dirname0 name of the directory in which to store the results |
---|
73 | @param maxlen0 length of the memory buffers, when full the buffers will be dumped to HDD and returned to the beginning. */ |
---|
74 | dirfilelog ( std::string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {} |
---|
75 | //! Initialize storage |
---|
76 | void init(); |
---|
77 | void step(); |
---|
78 | void finalize(); |
---|
79 | /*! \brief Write memory storage to disk. |
---|
80 | @param Len length of buffer to be written, if 0 the file is truncated at 0. |
---|
81 | */ |
---|
82 | void write_buffers ( int Len ); |
---|
83 | }; |
---|
84 | |
---|
85 | }; |
---|
86 | #endif // LGR_H |
---|