diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/potentials/Tables/mult_by_table.c | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/BNT/potentials/Tables/mult_by_table.c')
| -rw-r--r-- | sourcecodes/bnt-master/BNT/potentials/Tables/mult_by_table.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/potentials/Tables/mult_by_table.c b/sourcecodes/bnt-master/BNT/potentials/Tables/mult_by_table.c new file mode 100644 index 00000000..3f67983d --- /dev/null +++ b/sourcecodes/bnt-master/BNT/potentials/Tables/mult_by_table.c @@ -0,0 +1,114 @@ +/* mult_by_table.c ../potential/tables */ + + +/******************************************/ +/* 6 input & 1 output */ +/* Big table [0] */ +/* Big domain [1] */ +/* big sizes [2] */ +/* Small table [3] */ +/* small domain [4] */ +/* small sizes [5] */ +/* */ +/* New big table[0] */ +/******************************************/ + +#include "mex.h" + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ + int i, j, count, NB, NS, siz_b, siz_s, ndim, temp; + int *mask, *sx, *sy, *cpsy, *subs, *s, *cpsy2; + double *pbDomain, *psDomain, *sp, *zp, *bs; + + plhs[0] = mxDuplicateArray(prhs[0]); + zp = mxGetPr(plhs[0]); + + siz_b = mxGetNumberOfElements(prhs[1]); + siz_s = mxGetNumberOfElements(prhs[4]); + pbDomain = mxGetPr(prhs[1]); + psDomain = mxGetPr(prhs[4]); + + NB = mxGetNumberOfElements(prhs[0]); + NS = mxGetNumberOfElements(prhs[3]); + sp = mxGetPr(prhs[3]); + + bs = mxGetPr(prhs[2]); + + if(NS == 1){ + for(i=0; i<NB; i++){ + zp[i] *= *sp; + } + return; + } + + if(NS == NB){ + for(i=0; i<NB; i++){ + zp[i] *= sp[i]; + } + return; + } + + mask = malloc(siz_s * sizeof(int)); + count = 0; + for(i=0; i<siz_s; i++){ + for(j=0; j<siz_b; j++){ + if(psDomain[i] == pbDomain[j]){ + mask[count] = j; + count++; + break; + } + } + } + + ndim = siz_b; + sx = (int *)malloc(sizeof(int)*ndim); + sy = (int *)malloc(sizeof(int)*ndim); + for(i=0; i<ndim; i++){ + sx[i] = (int)bs[i]; + sy[i] = 1; + } + for(i=0; i<count; i++){ + temp = mask[i]; + sy[temp] = sx[temp]; + } + + s = (int *)malloc(sizeof(int)*ndim); + *(cpsy = (int *)malloc(sizeof(int)*ndim)) = 1; + subs = (int *)malloc(sizeof(int)*ndim); + cpsy2 = (int *)malloc(sizeof(int)*ndim); + for(i = 0; i < ndim; i++){ + subs[i] = 0; + s[i] = sx[i] - 1; + } + + for(i = 0; i < ndim-1; i++){ + cpsy[i+1] = cpsy[i]*sy[i]--; + cpsy2[i] = cpsy[i]*sy[i]; + } + cpsy2[ndim-1] = cpsy[ndim-1]*(--sy[ndim-1]); + + for(j=0; j<NB; j++){ + *zp++ *= *sp; + for(i = 0; i < ndim; i++){ + if(subs[i] == s[i]){ + subs[i] = 0; + if(sy[i]) + sp -= cpsy2[i]; + } + else{ + subs[i]++; + if(sy[i]) + sp += cpsy[i]; + break; + } + } + } + free(sx); + free(sy); + free(s); + free(cpsy); + free(subs); + free(cpsy2); + free(mask); +} + |
