Changeset 943
- Timestamp:
- 05/16/10 23:13:02 (15 years ago)
- Files:
-
- 1 removed
- 13 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/epdf_covariance.cpp
r937 r943 12 12 #ifdef MEX 13 13 #include <mex/mex_parser.h> 14 #include "mexPdf.h"14 #include <mex/mex_pdf.h> 15 15 16 16 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { -
applications/bdmtoolbox/mex/epdf_evallog_mat.cpp
r937 r943 12 12 #ifdef MEX 13 13 #include <mex/mex_parser.h> 14 #include "mexPdf.h"14 #include <mex/mex_pdf.h> 15 15 16 16 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { -
applications/bdmtoolbox/mex/epdf_marginal.cpp
r937 r943 12 12 #ifdef MEX 13 13 #include <mex/mex_parser.h> 14 #include "mexPdf.h"14 #include <mex/mex_pdf.h> 15 15 16 16 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { -
applications/bdmtoolbox/mex/epdf_mean.cpp
r925 r943 12 12 #ifdef MEX 13 13 #include <mex/mex_parser.h> 14 #include "mexPdf.h"14 #include <mex/mex_pdf.h> 15 15 16 16 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { -
applications/bdmtoolbox/mex/epdf_sample_mat.cpp
r937 r943 12 12 #ifdef MEX 13 13 #include <mex/mex_parser.h> 14 #include "mexPdf.h"14 #include <mex/mex_pdf.h> 15 15 16 16 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { -
applications/bdmtoolbox/mex/epdf_variance.cpp
r937 r943 12 12 #ifdef MEX 13 13 #include <mex/mex_parser.h> 14 #include "mexPdf.h"14 #include <mex/mex_pdf.h> 15 15 16 16 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { -
applications/bdmtoolbox/mex/mex_classes/mexBM.m
r937 r943 8 8 methods 9 9 function validate(p) 10 if size(p.mu)<1 & (size(p.b)<1) 11 error('incompatible mu and b'); 12 end 10 % checks if all paramateres match 13 11 end 14 12 function dims=dimensions(p) 15 13 %please fill 16 [size_of_posterior size_of_data size_of_condition] 14 %dims = [size_of_posterior size_of_data size_of_condition] 15 dims = [0,0,0] % 17 16 end 18 17 function obj=bayes(obj,dt,cond) 19 18 % transform old estimate into new estimate 20 19 end 21 function p= posterior(obj)20 function p=epredictor(obj,cond) 22 21 % return posterior density 23 22 end -
applications/bdmtoolbox/mex/mex_classes/mexEpdf.m
r937 r943 1 1 classdef mexEpdf 2 2 properties 3 rv =RV; %empty description add some valid RV when needed3 rv=RV; %empty description add some valid RV when needed 4 4 end 5 5 methods … … 19 19 error('define how to evaluate log of this density at point x') 20 20 end 21 22 %%% default function %%% 23 21 24 function l=evallog_nn(p,x) 22 25 % define how to evaluate non-normalized log of this density at point x … … 24 27 evallog(p,x); 25 28 end 26 29 function r=get_rv(p) 30 r=p.rv; 31 end 27 32 end 28 33 end -
applications/bdmtoolbox/tutorial/userguide/epdfds_example.m
r934 r943 4 4 U.high = 1; 5 5 U.low = -1; 6 U.rv.class='RV'; 7 U.rv.names={'a'}; 6 U.rv = RV('a',1); 7 8 f.class = 'mexEpdf'; 9 f.object = mexLaplace; 10 f.object.mu =12; 11 f.object.b = 1; 12 f.object.rv = RV('b',1); 13 8 14 9 15 DS.class='EpdfDS'; 10 DS.epdf = U;16 DS.epdf =f; %U 11 17 12 18 experiment.ndat=10; … … 14 20 M=simulator(DS,experiment); 15 21 16 M.DS_dt_ a22 M.DS_dt_b -
library/bdm/base/bdmbase.h
r942 r943 1176 1176 1177 1177 //!Constructs a predictive density \f$ f(d_{t+1} |d_{t}, \ldots d_{0}) \f$ 1178 virtual epdf* epredictor( ) const NOT_IMPLEMENTED(NULL);1178 virtual epdf* epredictor(const vec &cond=vec()) const NOT_IMPLEMENTED(NULL); 1179 1179 1180 1180 //!Constructs conditional density of 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t}) \f$ -
library/bdm/estim/mixtures.cpp
r886 r943 137 137 } 138 138 139 emix* MixEF::epredictor ( ) const {139 emix* MixEF::epredictor ( const vec &vec) const { 140 140 Array<shared_ptr<epdf> > pC ( n ); 141 141 for ( int i = 0; i < n; i++ ) { -
library/bdm/estim/mixtures.h
r897 r943 107 107 } 108 108 109 emix* epredictor( ) const;109 emix* epredictor(const vec &cond=vec()) const; 110 110 //! Flatten the density as if it was not estimated from the data 111 111 void flatten ( const BMEF* M2 ); -
library/bdm/mex/mex_BM.h
r863 r943 1 #include <estim/arx.h> 2 #include <itpp/itmex.h> 3 #include "mex_parser.h" 4 5 namespace bdm { 6 /*! 7 * \brief Wrapper of BM mapping BM's methods to matlab functions 8 9 The data are stored in an internal matrix \c Data . Each column of Data corresponds to one discrete time observation \f$t\f$. Access to this matrix is via indices \c rowid and \c delays. 10 11 The data can be loaded from a file. 12 */ 13 14 using namespace bdm; 15 16 //! epdf with functions implemented in matlab 17 class mexEpdf: public epdf { 18 protected: 19 //! prefix of matlab functions 20 string name; 21 //! pointer to storage structure 22 mxArray *data; 23 public: 24 mexEpdf() {}; 25 void from_setting ( const Setting &S ) { 26 UIFile conf( ( const char * ) S["name"] ); 27 data = UImxArray::create_mxArray( conf ); 28 //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 29 //TODO (future...): 30 //mxArray * init_data = setting2mxarray S["init_data"]; 31 //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting"); 32 //delete init_data; 33 } 34 vec mean() const { 35 mxArray *tmp; 36 string fname = name + "_mean"; 37 mexCallMATLAB ( 1, &tmp, 1, ( mxArray ** ) &data, fname.c_str() ); 38 return mxArray2vec ( tmp ); 39 } 40 41 virtual vec sample() const NOT_IMPLEMENTED(0); 42 43 virtual double evallog ( const vec &val ) const NOT_IMPLEMENTED(0); 44 45 virtual vec variance() const NOT_IMPLEMENTED(0); 1 #include <mex/mex_parser.h> 2 #include <mex/mex_pdf.h> 3 class mexBM: public BM{ 4 protected: 5 mxArray *data; 6 mexEpdf est; 7 public: 8 mexBM() {}; 9 void from_setting(const Setting &S) { 10 Setting &So=S["object"]; 11 data = (mxArray*)long(So); 12 } 13 void validate() { 14 mexCallMATLAB(0, 0, 1, &data, "validate"); 15 mxArray *tmp; 16 mexCallMATLAB(1, &tmp, 1, &data, "dimensions"); 17 vec v=mxArray2vec(tmp); 18 if (v.length()<3) {bdm_error("Three dimensions are expected in mexBM.dimensions");} 19 set_dim(v(0)); 20 dimy = v(1); 21 dimc = v(2); 22 } 23 void bayes(const vec &dt, const vec &cond) { 24 mxArray *tmp; 25 mxArray *in[3]; 26 in[0]=data; 27 in[1]=mxCreateDoubleMatrix(dt.length(),1,mxREAL); 28 vec2mxArray(dt,in[1]); 29 in[2]=mxCreateDoubleMatrix(cond.length(),1,mxREAL); 30 vec2mxArray(cond,in[2]); 31 32 mexCallMATLAB(1, &tmp, 3, in, "bayes"); 33 if (data!=tmp){ 34 mxDestroyArray ( data ); 35 data = mxDuplicateArray ( tmp ); 36 } // 37 } 38 epdf* predictor(const vec &cond) const { 39 mxArray *tmp; 40 mxArray *in[3]; 41 in[0]=data; 42 in[1]=mxCreateDoubleMatrix(cond.length(),1,mxREAL); 43 vec2mxArray(cond,in[1]); 44 45 mexCallMATLAB(1, &tmp, 3, in, "predictor"); 46 47 UImxArray uitmp(tmp); 48 shared_ptr<epdf> pred = UI::build<epdf>(uitmp); 49 return pred.get(); 50 // 51 } 52 const epdf& posterior() const { 53 return est; 54 } 46 55 }; 47 UIREGISTER ( mexEpdf ); 48 49 //! BM with functions implemented in matlab 50 class mexBM: public BM { 51 protected : 52 //! prefix of matlab functions 53 string name; 54 //! internal estimator 55 mexEpdf est; 56 //! mxArray with attributes of this object 57 mxArray *data; 58 public: 59 mexBM() {} 60 61 //! duplicate internal data pointer? 62 mxArray *get_data() { 63 //mexCallMATLAB(0, NULL, 1, &data, "dump"); 64 return mxDuplicateArray ( data ); 65 } 66 67 void from_setting ( const Setting &S ) { 68 BM::from_setting ( S ); 69 70 UIFile conf( ( const char * ) S["name"] ); 71 data = UImxArray::create_mxArray( conf ); 72 73 //string fname = name+"_new"; 74 //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); 75 //the following works as long as the posterior is the 76 //only member object there could be a structure of 77 //member objects in the setting and a for cycle over 78 //all of them right here in the code 79 Setting &posterior = S["posterior"]; 80 est.from_setting ( posterior ); 81 } 82 void bayes ( const vec &yt, const vec &cond ) { 83 //void bayes() { 84 mxArray *tmp, *old; 85 mxArray *in[2]; 86 in[0] = data; 87 in[1] = mxCreateDoubleMatrix ( yt.size(), 1, mxREAL ); 88 vec2mxArray ( yt, in[1] ); 89 mexCallMATLAB ( 1, &tmp, 2, in, ( name + "_bayes" ).c_str() ); 90 old = data; 91 data = mxDuplicateArray ( tmp ); 92 if ( old ) mxDestroyArray ( old ); 93 if ( tmp ) mxDestroyArray ( tmp ); 94 //mexCallMATLAB(0, NULL, 1, &data, "dump"); 95 } 96 //! return correctly typed posterior (covariant return) 97 const mexEpdf& posterior() const { 98 return est; 99 } //tohle by melo zustat!! 100 101 }; 102 UIREGISTER ( mexBM ); 103 104 } 56 UIREGISTER(mexBM);