Changeset 347

Show
Ignore:
Timestamp:
05/27/09 21:37:49 (15 years ago)
Author:
smidl
Message:

change in loggers! old experiments may stop working

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libBM.h

    r345 r347  
    522522        //! returns an identifier which will be later needed for calling the \c logit() function 
    523523        //! For empty RV it returns -1, this entry will be ignored by \c logit(). 
    524         virtual int add ( const RV &rv, string name="" ) { 
     524        virtual int add ( const RV &rv, string prefix="" ) { 
    525525                int id; 
    526526                if ( rv._dsize() >0 ) { 
    527527                        id=entries.length(); 
    528                         names=concat ( names, name ); // diff 
     528                        names=concat ( names, prefix); // diff 
    529529                        entries.set_length ( id+1,true ); 
    530530                        entries ( id ) = rv; 
     
    746746 
    747747                // Add mean value 
    748                 if (LFlags(0)) LIDs ( 0 ) =L.add ( r,name ); 
    749                 if (LFlags(1)) LIDs ( 1 ) =L.add ( r,name+"_lb" ); 
    750                 if (LFlags(2)) LIDs ( 2 ) =L.add ( r,name+"_ub" ); 
    751                 if (LFlags(3)) LIDs ( 3 ) =L.add ( RV("ll",1,0),r.name(0)+name ); //TODO: "local" RV  
     748                if (LFlags(0)) LIDs ( 0 ) =L.add ( r,name+"mean_" ); 
     749                if (LFlags(1)) LIDs ( 1 ) =L.add ( r,name+"lb_" ); 
     750                if (LFlags(2)) LIDs ( 2 ) =L.add ( r,name+"ub_" ); 
     751                if (LFlags(3)) LIDs ( 3 ) =L.add ( RV("ll",1),name ); //TODO: "local" RV  
    752752        } 
    753753        virtual void logit ( logger &L ) { 
  • bdm/stat/loggers.cpp

    r270 r347  
    1212        it_file itf ( fname ); 
    1313        int i; 
     14        string vec_name=""; 
     15        int istart, iend; 
    1416        for ( i=0; i<entries.length();i++ ) { 
    15                 if ( names ( i ).length() <1 ) { 
    16                         std::ostringstream o; 
    17                         o<<"Variable"<<i; 
    18                         itf << Name ( o.str() ) << vectors ( i ); 
     17                istart=0; 
     18                for (int j=0; j<entries(i).length(); j++){ // same for as in add!!! 
     19                        vec_name = names(i) + entries(i).name(j); 
     20                        iend=istart+entries(i).size(j)-1; 
     21                        itf << Name ( vec_name ) << vectors ( i ).get_cols(istart,iend); 
     22                        // move start after current end... 
     23                        istart=iend+1; 
    1924                } 
    20                 else { 
    21                         itf << Name ( names ( i ) ) << vectors ( i ); 
    22                 } 
     25                 
    2326        } 
    2427} 
  • bdm/stat/loggers.h

    r338 r347  
    3434        //! Storage 
    3535        Array<mat> vectors; 
    36         //! 
     36        //! name of it file to save results 
     37        string itfilename; 
    3738public: 
    3839        //!Default constructor 
    39         memlog ( int maxlen0 ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ) {} 
     40        memlog ( int maxlen0, string itf="" ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ),itfilename(itf) {} 
    4041        //! Initialize storage 
    4142        void init() { 
     
    4344                vectors.set_size ( n );  
    4445                for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i)._dsize() );} 
    45                 ; 
    4646        } 
    4747        void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );} 
     
    5757        //! Save values into an itfile named after \c fname. 
    5858        void itsave(const char* fname); 
     59        //!  
     60        void finalize() {if (itfilename.length()>0) itsave(itfilename.c_str());}; 
     61 
    5962}; 
    6063 
  • bdm/stat/loggers_ui.h

    r278 r347  
    7575 
    7676UIREGISTER(UIdirfilelog); 
     77 
     78 
     79/*! \brief UI for memlog  
     80\code 
     81logger = { 
     82        type = "itpplog"; 
     83        filename = "file_name.it"; // resulting filename with results in it format 
     84        maxlen = 100;          // size of memory buffer 
     85} 
     86\endcode 
     87 */ 
     88class UIitpplog : public UIbuilder { 
     89        public: 
     90                UIitpplog():UIbuilder("itpplog"){}; 
     91                bdmroot* build(Setting &S) const{ 
     92                        return new memlog(S["maxlen"],S["filename"]); 
     93                }; 
     94}; 
     95 
     96UIREGISTER(UIitpplog); 
    7797#endif // LGR_H 
  • library/mex/mexlog.h

    r342 r347  
    2222        public: 
    2323        //! constructor 
    24         mexlog(int maxlen): memlog(maxlen){}; 
     24        mexlog(int maxlen): memlog(maxlen,"mx"){}; 
    2525        //! 
    2626        mxArray* toCell(){ 
    2727                mxArray* tmp = mxCreateStructMatrix(1,1,0,NULL); 
    2828 
    29                 //copy vectors to mxStruct 
    30                 for (int i=0; i<names.length();i++){ 
    31                         mat& M=vectors(i); 
    32                         mxArray* fld=mxCreateDoubleMatrix(M.rows(), M.cols(), mxREAL); 
    33                         mat2mxArray(M,fld); 
    34                         mxReplaceFieldNM(tmp, names(i).c_str(), fld); 
     29                //copied from itsave 
     30                int i; 
     31                string vec_name=""; 
     32                int istart, iend; 
     33                 
     34                mat M; //temporary matrix 
     35                for ( i=0; i<entries.length();i++ ) { 
     36                        istart=0; 
     37                        for (int j=0; j<entries(i).length(); j++){ // same for as in add!!! 
     38                                vec_name = names(i) + entries(i).name(j); 
     39                                iend=istart+entries(i).size(j)-1; 
     40                                M=vectors(i).get_cols(istart,iend); 
     41                                istart=iend+1; 
     42                                // copy the selection to mx 
     43                                mxArray* fld=mxCreateDoubleMatrix(M.rows(), M.cols(), mxREAL); 
     44                                mat2mxArray(M,fld); 
     45                                mxReplaceFieldNM(tmp, vec_name.c_str(), fld); 
     46                        } 
    3547                } 
    3648                return tmp;