Changeset 371

Show
Ignore:
Timestamp:
06/09/09 19:47:10 (15 years ago)
Author:
miro
Message:

conversion from config to matlab structure
changed expected interpretation of matrix in mexparse.h

Location:
library/mex
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • library/mex/mexBM.cpp

    r336 r371  
    77        protected: 
    88                string name; 
    9                 vec S; //bude struktura mxArray 
     9                mxArray *data; 
    1010        public: 
    11                 mexEpdf(){}; 
    12                 void set(const string name0, const vec &S0){name=name0; S=S0;} // vola fci name+"new" a preda ji mxArray misto S 
    13                 vec mean() const {return S;} //bude vysledek volani fce matlabu 
     11                mexEpdf() {}; 
     12                void from_setting(const Setting &S)  { 
     13                        name = (const char *) S["name"]; 
     14                        string fname = name+"_new"; 
     15                        mexCallMATLAB(1, &data, 0, 0, fname.c_str()); 
     16                        //TODO (future...): 
     17                        //mxArray * init_data = setting2mxarray S["init_data"]; 
     18                        //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting"); 
     19                        //delete init_data; 
     20                }  
     21                vec mean() const { 
     22                        mxArray *tmp; 
     23                        string fname = name+"_mean"; 
     24                        mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, fname.c_str()); 
     25                        return mxArray2vec(tmp); 
     26                }  
    1427}; 
     28 
    1529class mexBM: public BM{ 
    1630        protected : 
    1731                string name; 
    1832                mexEpdf est; 
     33                mxArray *data; 
    1934        public: 
    20                 mexBM(string name0){name=name0;est.set("mexEpdf",vec_1(1.2));} 
    21                 void bayes(const vec &dt){/* volej matlab name+"_bayes" */}  
    22                 const mexEpdf& posterior()const{return est;} //tohle by melo zustat!! 
    23                 const mexEpdf* _e()const{return &est;} //tohle by melo zustat!! 
     35                mexBM() {} 
     36 
     37                void from_setting(const Setting &S)  { 
     38                        name = (const char *) S["name"]; 
     39                        string fname = name+"_new"; 
     40                        mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
     41                        //the following works as long as the posterior is the 
     42                        //only member object there could be a structure of  
     43                        //member objects in the setting and a for cycle over 
     44                        //all of them right here in the code 
     45                        Setting &posterior = S["posterior"];  
     46                        est.from_setting(posterior); 
     47                } 
     48                void bayes(const vec &dt)  { 
     49                //void bayes()  { 
     50                        string fname = name+"_bayes"; 
     51                        mexCallMATLAB(1, &data, 1, &data, fname.c_str()); 
     52                }  
     53                const mexEpdf& posterior() const  { 
     54                        return est; 
     55                } //tohle by melo zustat!! 
     56                const mexEpdf* _e() const  { 
     57                        return &est; 
     58                } //tohle by melo zustat!! 
    2459}; 
    2560 
     
    2762{ 
    2863    // Check the number of inputs and output arguments 
    29         if(n_input!=1) mexErrMsgTxt("Wrong number of input variables - expected parameter 'name'!"); 
     64        if(n_input!=1) mexErrMsgTxt("Wrong number of input variables - expected parameter 'filename'!"); 
    3065 
    3166        // ------------------ Start of routine --------------------------- 
    3267 
    33         mexBM mB(mxArray2string(input[0])); // naplni 
    34         mB.bayes(vec_1(1.3)); 
     68        //mexBM mB(mxArray2string(input[0])); // naplni 
     69        //mB.bayes(vec_1(1.3)); 
     70        string filename = mxArray2string(input[0]); 
     71        Config config; 
     72        config.readFile(filename.c_str()); 
     73        mexBM mb; 
     74        mb.from_setting(config.getRoot()); 
     75        vec a = "1.0 2.0 3.0"; 
     76        mb.bayes(a); 
     77         
    3578 
    3679        // ------------------ End of routine ----------------------------- 
     
    4083 
    4184    // Convert the IT++ format to Matlab format for output 
    42         vec2mxArray(mB.posterior().mean(), output[0]); 
     85        //vec2mxArray(mB.posterior().mean(), output[0]); 
    4386} 
  • library/mex/mexparse.h

    r348 r371  
    3030                        Setting &child = (key=="") ? setting.add(Setting::TypeList) 
    3131                                                   : setting.add(key, Setting::TypeList); 
     32                        Setting &label = child.add(Setting::TypeString); 
     33                        label = "matrix"; 
    3234                        Setting &cols = child.add( Setting::TypeInt ); 
    3335                        Setting &rows = child.add( Setting::TypeInt );