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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/********************************
Author: Sravanthi Kota Venkata
********************************/
#include "stitch.h"
F2D* dist2(I2D* x, F2D* c)
{
int ndata, dimx, ncentres, dimc, i, j, k;
F2D *n2, *t1, *t2;
float temp;
F2D *s1, *s2, *ctrans;
F2D *mult1, *mult2, *mult3;
ndata = x->height;
dimx = x->width;
ncentres = c->height;
dimc = c->width;
if(dimx != dimc)
return NULL;
s1 = fSetArray(ncentres, 1, 1);
s2 = fSetArray(ndata, 1, 1);
t1 = fMallocHandle(1, x->height);
for(j=0; j<t1->width; j++)
{
temp = 0;
for(i=0; i<t1->height; i++)
{
temp += subsref(x,j,i) * subsref(x,j,i);
}
asubsref(t1,j) = temp;
}
mult1 = fMtimes(s1, t1);
t2 = fMallocHandle(1, c->height);
for(j=0; j<t2->width; j++)
{
temp = 0;
for(i=0; i<t2->height; i++)
{
temp += subsref(c,j,i) * subsref(c,j,i);
}
asubsref(t2,j) = temp;
}
mult2 = fMtimes(s2, t2);
ctrans = fTranspose(c);
mult3 = ifMtimes(x, ctrans);
for(i=0; i<(mult3->height * mult3->width); i++)
asubsref(mult3,i) = asubsref(mult3,i) * 2;
free(t1);
free(t2);
free(s1);
free(s2);
free(ctrans);
n2 = fMallocHandle(ndata, ncentres);
for(i=0; i<(ndata*ncentres); i++)
asubsref(n2,i) = asubsref(mult1,i) + asubsref(mult2,i) - asubsref(mult3,i);
free(mult1);
free(mult2);
free(mult3);
return n2;
}
|