1 #include "Algorithm/get_dissimilarities.h"
2 #include "TimeSeries/deserialize.h"
4 #include "Algorithm/compute_coefficients.h"
6 #include "Util/utils.h"
8 uint32_t* get_class(PowerCurve
* data
, uint32_t nbSeries
, PowerCurve
* medoids
,
9 uint32_t nbClusters
, uint32_t nbValues
, uint32_t p_for_dissims
, double* DISTOR
)
11 // nbReducedCoordinates = smallest power of 2 which is above nbValues
12 uint32_t nbReducedCoordinates
= (uint32_t)ceil(log2(nbValues
));
14 // Preprocessing to reduce dimension of both data and medoids
15 Real
* reducedCoordinates_data
= (Real
*) malloc(nbSeries
* nbReducedCoordinates
* sizeof(Real
));
16 compute_coefficients(data
, nbSeries
, nbValues
,
17 reducedCoordinates_data
, 0, nbReducedCoordinates
);
18 Real
* reducedCoordinates_medoids
= (Real
*) malloc(nbClusters
* nbReducedCoordinates
* sizeof(Real
));
19 compute_coefficients(medoids
, nbClusters
, nbValues
,
20 reducedCoordinates_medoids
, 0, nbReducedCoordinates
);
22 Real
* dissimilarities
= get_dissimilarities_inter(reducedCoordinates_data
, nbSeries
,
23 reducedCoordinates_medoids
, nbClusters
, nbReducedCoordinates
, p_for_dissims
);
24 free(reducedCoordinates_data
);
25 free(reducedCoordinates_medoids
);
27 // 3] Finally, assign each row to the least dissimilar center
28 uint32_t* result
= (uint32_t*) malloc(nbSeries
*sizeof(uint32_t));
29 for (uint32_t i
=0; i
<nbSeries
; i
++)
31 uint32_t minIndex
= 0;
32 Real minDissim
= dissimilarities
[i
*nbClusters
+ 0];
33 for (uint32_t j
=1; j
<nbClusters
; j
++)
35 if (dissimilarities
[i
*nbClusters
+ j
] < minDissim
)
37 minDissim
= dissimilarities
[i
*nbClusters
+ j
];
41 result
[i
] = minIndex
+ 1;
42 (*DISTOR
) += minDissim
;
44 free(dissimilarities
);