forked from hanwangzhang/Discrete-Collaborative-Filtering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCDmex.c
55 lines (48 loc) · 1.35 KB
/
DCDmex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string.h>
#include <math.h>
#include <mex.h>
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
double *b;/*nframes(N) x D*/
double *MM;/*nframes(N) x knn*/
double *Ms;/*ncodebook(K) x nfeatures(D)*/
double *x;
double maxItr;
mwSize r;
mwSize i,k,it,no_change_count;
double ss;
bool converge = false;
b = mxGetPr(prhs[0]);
MM = mxGetPr(prhs[1]);
Ms = mxGetPr(prhs[2]);
x = mxGetPr(prhs[3]);
maxItr = *(mxGetPr(prhs[4]));
r = mxGetN(prhs[1]);
it = 0;
while (!converge){
no_change_count = 0;
for (k = 0; k < r; k ++){
ss = 0;
for (i = 0; i < r; i ++)
if (i != k)
ss += MM[k+i*r]*b[i];
ss -= Ms[k]+x[k];
if (ss > 0){
if (b[k] == -1)
no_change_count ++;
else
b[k] = -1;
}
else if (ss < 0){
if (b[k] == 1)
no_change_count ++;
else
b[k] = 1;
}
else
no_change_count ++;
}
if ((it >= (int)maxItr-1) || (no_change_count == r))
converge = true;
it ++;
}
}