Changeset 374 for library/mex/mexBM.cpp

Show
Ignore:
Timestamp:
06/11/09 17:15:06 (15 years ago)
Author:
miro
Message:

mexBM works. An example added (it ignores any underlying theory).
config2mxstruct probably doesn't handle vectors and matrices, to be fixed

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/mex/mexBM.cpp

    r371 r374  
    11#include <itpp/itmex.h> 
    22#include <estim/arx.h> 
     3#include "config2mxstruct.h" 
    34 
    45using namespace bdm; 
     
    1213                void from_setting(const Setting &S)  { 
    1314                        name = (const char *) S["name"]; 
    14                         string fname = name+"_new"; 
    15                         mexCallMATLAB(1, &data, 0, 0, fname.c_str()); 
     15                        UImxConfig conf(S); 
     16                        data = mxDuplicateArray(conf.mxconfig); 
     17                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
    1618                        //TODO (future...): 
    1719                        //mxArray * init_data = setting2mxarray S["init_data"]; 
     
    3537                mexBM() {} 
    3638 
     39                mxArray *get_data() { 
     40                        //mexCallMATLAB(0, NULL, 1, &data, "dump"); 
     41                        return mxDuplicateArray(data); 
     42                } 
     43 
    3744                void from_setting(const Setting &S)  { 
    3845                        name = (const char *) S["name"]; 
    39                         string fname = name+"_new"; 
    40                         mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
     46                        UImxConfig conf(S); 
     47                        data = mxDuplicateArray(conf.mxconfig); 
     48                        //string fname = name+"_new"; 
     49                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 
    4150                        //the following works as long as the posterior is the 
    4251                        //only member object there could be a structure of  
     
    4857                void bayes(const vec &dt)  { 
    4958                //void bayes()  { 
    50                         string fname = name+"_bayes"; 
    51                         mexCallMATLAB(1, &data, 1, &data, fname.c_str()); 
     59                        mxArray *tmp, *old; 
     60                        mxArray *in[2]; 
     61                        in[0] = data; 
     62                        in[1] = mxCreateDoubleMatrix(dt.size(), 1, mxREAL); 
     63                        vec2mxArray(dt, in[1]); 
     64                        mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str()); 
     65                        old = data; 
     66                        data = mxDuplicateArray(tmp); 
     67                        if (old) mxDestroyArray(old); 
     68                        if (tmp) mxDestroyArray(tmp); 
     69                        //mexCallMATLAB(0, NULL, 1, &data, "dump"); 
    5270                }  
    5371                const mexEpdf& posterior() const  { 
     
    7290        config.readFile(filename.c_str()); 
    7391        mexBM mb; 
    74         mb.from_setting(config.getRoot()); 
    75         vec a = "1.0 2.0 3.0"; 
    76         mb.bayes(a); 
     92        Setting &root = config.getRoot(); 
     93        mb.from_setting(root); 
     94        vec dt = "18.0"; 
     95        mb.bayes(dt); 
     96        if(n_output>0) output[0] = mb.get_data(); 
    7797         
    7898 
     
    80100 
    81101    // Create output vectors 
    82         output[0] = mxCreateDoubleMatrix(1,1, mxREAL); 
     102        //output[0] = mxCreateDoubleMatrix(1,1, mxREAL); 
    83103 
    84104    // Convert the IT++ format to Matlab format for output