Changeset 371 for library/mex
- Timestamp:
- 06/09/09 19:47:10 (16 years ago)
- Location:
- library/mex
- Files:
-
- 2 added
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/mex/mexBM.cpp
r336 r371 7 7 protected: 8 8 string name; 9 vec S; //bude struktura mxArray9 mxArray *data; 10 10 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 } 14 27 }; 28 15 29 class mexBM: public BM{ 16 30 protected : 17 31 string name; 18 32 mexEpdf est; 33 mxArray *data; 19 34 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!! 24 59 }; 25 60 … … 27 62 { 28 63 // 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'!"); 30 65 31 66 // ------------------ Start of routine --------------------------- 32 67 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 35 78 36 79 // ------------------ End of routine ----------------------------- … … 40 83 41 84 // Convert the IT++ format to Matlab format for output 42 vec2mxArray(mB.posterior().mean(), output[0]);85 //vec2mxArray(mB.posterior().mean(), output[0]); 43 86 } -
library/mex/mexparse.h
r348 r371 30 30 Setting &child = (key=="") ? setting.add(Setting::TypeList) 31 31 : setting.add(key, Setting::TypeList); 32 Setting &label = child.add(Setting::TypeString); 33 label = "matrix"; 32 34 Setting &cols = child.add( Setting::TypeInt ); 33 35 Setting &rows = child.add( Setting::TypeInt );