libDAI-0.2.7 (2010-08-19)
-------------------------
+* Improved code in matlab/dai.cpp that tests whether findMaximum is supported
+ (this fixes a bug in matlab/dai.cpp reported by Deepak Roy)
* Replaced all Name members by name() virtual functions and removed global variable DAINames
(this fixes a bug in matlab/dai.cpp reported by Thomas Mensink)
* Removed interfaces deprecated in 0.2.6.
obj->init();
obj->run();
-
// Save logZ
double logZ = obj->logZ();
// Save maxdiff
double maxdiff = obj->maxDiff();
-
// Hand over results to MATLAB
LOGZ_OUT = mxCreateDoubleMatrix(1,1,mxREAL);
*(mxGetPr(LOGZ_OUT)) = logZ;
if( nlhs >= 6 ) {
std::vector<std::size_t> map_state;
- if( obj->name() == "BP" ) {
- BP* obj_bp = dynamic_cast<BP *>(obj);
- DAI_ASSERT( obj_bp != 0 );
- map_state = obj_bp->findMaximum();
- } else if( obj->name() == "JTree" ) {
- JTree* obj_jtree = dynamic_cast<JTree *>(obj);
- DAI_ASSERT( obj_jtree != 0 );
- map_state = obj_jtree->findMaximum();
+ bool supported = true;
+ try {
+ map_state = obj->findMaximum();
+ } catch( Exception &e ) {
+ if( e.code() == Exception::NOT_IMPLEMENTED )
+ supported = false;
+ else
+ throw;
+ }
+ if( supported ) {
+ QMAP_OUT = mxCreateNumericMatrix(map_state.size(), 1, mxUINT32_CLASS, mxREAL);
+ uint32_T* qmap_p = reinterpret_cast<uint32_T *>(mxGetPr(QMAP_OUT));
+ for (size_t n = 0; n < map_state.size(); ++n)
+ qmap_p[n] = map_state[n];
} else {
- mexErrMsgTxt("MAP state assignment works only for BP, JTree.\n");
delete obj;
- return;
+ mexErrMsgTxt("Calculating a MAP state is not supported by this inference algorithm");
}
- QMAP_OUT = mxCreateNumericMatrix(map_state.size(), 1, mxUINT32_CLASS, mxREAL);
- uint32_T* qmap_p = reinterpret_cast<uint32_T *>(mxGetPr(QMAP_OUT));
- for (size_t n = 0; n < map_state.size(); ++n)
- qmap_p[n] = map_state[n];
}
- delete obj;
+ delete obj;
return;
}