1 #include "Util/types.h"
5 // compute L^p dissimilarities for a nxm matrix
6 Real
* get_dissimilarities_intra(Real
* samples
, uint32_t nbSamples
, uint32_t nbValues
, uint32_t p
)
8 Real
* dissimilarities
= (Real
*) malloc(nbSamples
*nbSamples
*sizeof(Real
));
9 for (uint32_t i
=0; i
<nbSamples
; i
++)
11 dissimilarities
[i
*nbSamples
+i
] = 0.0;
12 for (uint32_t j
=0; j
<i
; j
++)
14 // dissimilarities[i*nbSamples+j] = L^p distance between reduced rows i and j
16 for (uint32_t m
=0; m
<nbValues
; m
++)
18 double delta
= fabs(samples
[i
*nbValues
+m
] - samples
[j
*nbValues
+m
]);
19 dissim
+= pow(delta
, p
);
21 dissimilarities
[i
*nbSamples
+j
] = pow(dissim
, 1.0/p
);
22 dissimilarities
[j
*nbSamples
+i
] = dissimilarities
[i
*nbSamples
+j
];
25 return dissimilarities
;
28 // compute L^p dissimilarities between rows of 2 matrices
29 Real
* get_dissimilarities_inter(Real
* mat1
, uint32_t n1
, Real
* mat2
, uint32_t n2
,
30 uint32_t nbValues
, uint32_t p
)
32 Real
* dissimilarities
= (Real
*) malloc(n1
*n2
*sizeof(Real
));
33 for (uint32_t i
=0; i
<n1
; i
++)
35 for (uint32_t j
=0; j
<n2
; j
++)
38 for (uint32_t m
=0; m
<nbValues
; m
++)
40 double delta
= fabs(mat1
[i
*nbValues
+m
] - mat2
[j
*nbValues
+m
]);
41 dissim
+= pow(delta
, p
);
43 dissimilarities
[i
*n2
+j
] = pow(dissim
, 1.0/p
);
46 return dissimilarities
;