root/library/bdm/base/loggers.h @ 387

Revision 387, 3.4 kB (checked in by smidl, 15 years ago)

paths corrections

  • Property svn:eol-style set to native
Line 
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 "bdmbase.h"
17#include "user_info.h"
18
19namespace bdm{
20using std::string;
21
22/*!
23* \brief Logging into matrices in data format in memory
24
25* More?...
26*/
27
28class memlog : public logger {
29
30protected:
31        //! Maximum length of vectors stored in memory
32        int maxlen;
33        //! Currect record to be written
34        int ind;
35        //! Storage
36        Array<mat> vectors;
37        //! name of it file to save results
38        string itfilename;
39public:
40        //!Default constructor
41        memlog ( int maxlen0, string itf="" ) : maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ),itfilename(itf) {}
42
43        memlog(): ind ( 0 ),vectors ( 0 ) {}
44
45        //! Initialize storage
46        void init() {
47                int i; int n =entries.length();
48                vectors.set_size ( n ); 
49                for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i)._dsize() );}
50        }
51        void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );}
52        void logit ( int id, const vec &v ) {
53                it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
54                if(id>=0){ vectors ( id ).set_row ( ind,v );}
55        }
56        void logit ( int id, const double &d ) {
57                it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
58                it_assert_debug(vectors(id).cols()==1,"Vector expected");
59                if(id>=0){ vectors ( id ) ( ind )=d;}
60        }
61        //! Save values into an itfile named after \c fname.
62        void itsave(const char* fname);
63        //!
64        void finalize() {if (itfilename.length()>0) itsave(itfilename.c_str());};
65
66
67        /*! \brief UI for memlog
68
69        TODO dat tam kam patri, a to celej blok
70
71        \code
72        logger = {
73                type = "itpplog";
74                filename = "file_name.it"; // resulting filename with results in it format
75                maxlen = 100;          // size of memory buffer
76        }
77        \endcode
78         */
79        void from_setting( const Setting &set );
80
81        // TODO dodelat void to_setting( Setting &set ) const;
82};
83
84UIREGISTER(memlog);
85
86/*!
87* \brief Logging into dirfile with buffer in memory
88
89* Dirfile is a special format used by the kst program. See documentation of kst for description.
90*
91* This format is used to store scalars, hence multivariate RVs must be separated.
92*/
93class dirfilelog : public memlog {
94
95protected:
96        //!name of the directory
97        string dirname;
98        //! Automatically generated
99        Array<string> scalarnames;
100public:
101        /*!\brief Default constructor
102        @param dirname0 name of the directory in which to store the results
103        @param maxlen0 length of the memory buffers, when full the buffers will be dumped to HDD and returned to the beginning. */
104        dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
105
106        dirfilelog() {}
107
108        //! Initialize storage
109        void init();
110        void step();
111        void finalize();
112        /*! \brief Write memory storage to disk.
113        @param Len length of buffer to be written, if 0 the file is truncated at 0.
114        */
115        void write_buffers ( int Len );
116
117        // TODO dokumentace - aktualizovat
118        /*! \brief UI for dirfilelog (Kst file format)
119        \code
120        logger = {
121                type = "dirfilelog";
122                dirmane = "directory_for_files"; // resulting files will be stored there
123                maxlen = 100;                    // size of memory buffer, when full results are written to disk
124        }
125        \endcode
126        */
127        void from_setting( const Setting &set );
128
129        // TODO dodelat void to_setting( Setting &set ) const;
130};
131
132UIREGISTER(dirfilelog);
133
134};
135#endif // LGR_H
Note: See TracBrowser for help on using the browser.