1 /* This file is part of libDAI - http://www.libdai.org/
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
7 * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org]
8 * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
14 #include <dai/matlab/matlab.h>
15 #include <dai/factor.h>
24 #define PSI_IN prhs[0]
30 /* Output Arguments */
36 void mexFunction( int nlhs
, mxArray
*plhs
[], int nrhs
, const mxArray
*prhs
[] ) {
39 // Check for proper number of arguments
40 if ((nrhs
!= NR_IN
) || (nlhs
!= NR_OUT
)) {
41 mexErrMsgTxt("Usage: N = dai_potstrength(psi,i,j);\n\n"
43 "INPUT: psi = structure with a Member field and a P field, like a CPTAB.\n"
44 " i = label of a variable in psi.\n"
45 " j = label of another variable in psi.\n"
47 "OUTPUT: N = strength of psi in direction i->j.\n");
50 // Get input parameters
51 Factor psi
= mx2Factor(PSI_IN
);
52 ilabel
= (long)*mxGetPr(I_IN
);
53 jlabel
= (long)*mxGetPr(J_IN
);
55 // Find variable in psi with label ilabel
57 for( VarSet::const_iterator n
= psi
.vars().begin(); n
!= psi
.vars().end(); n
++ )
58 if( n
->label() == ilabel
) {
62 DAI_ASSERT( i
.label() == ilabel
);
64 // Find variable in psi with label jlabel
66 for( VarSet::const_iterator n
= psi
.vars().begin(); n
!= psi
.vars().end(); n
++ )
67 if( n
->label() == jlabel
) {
71 DAI_ASSERT( j
.label() == jlabel
);
73 // Calculate N(psi,i,j);
74 double N
= psi
.strength( i
, j
);
76 // Hand over result to MATLAB
77 N_OUT
= mxCreateDoubleMatrix(1,1,mxREAL
);
78 *(mxGetPr(N_OUT
)) = N
;