-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
71 lines (56 loc) · 1.73 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "utils.h"
#include "measures/commons.h"
#include "measures/sswc.h"
#include "measures/dbcv.h"
/**
* Allocates an array with size values between hmin (inclusive) and hmax (exclusive)
*
* @param size Size of the array
* @param hmin Minimum value (inclusive)
* @param hmax Maximum value (exclusive)
* @return An array with size length
*/
int *randint(int size, int hmin, int hmax) {
int i;
int *my_array = (int*)malloc(sizeof(int) * size);
for (i = 0; i < size; i++) {
my_array[i] = (rand() % hmax) + hmin;
}
return my_array;
}
int calculate_sswc(int argc, char **argv) {
int n_objects, n_attributes;
float *dataset = read_dataset("../datasets/iris.csv", &n_objects, &n_attributes);
int *medoids = randint(n_objects, 0, 1);
medoids[49] = 1;
medoids[99] = 1;
medoids[149] = 1;
float val = sswc(medoids, dataset, n_objects, n_attributes);
printf("sswc: %f\n", val);
free(medoids);
free(dataset);
return 0;
}
int main(int argc, char **argv) {
int n_objects, n_attributes;
float *dataset = read_dataset("../datasets/iris.csv", &n_objects, &n_attributes);
float *dm = get_distance_matrix(dataset, n_objects, n_attributes, true);
// srand((unsigned int)time(NULL)); // seeds with the current time
// int *partition = randint(n_objects, 0, 2);
int *partition = randint(n_objects, 0, 1);
for(int i = 0; i < n_objects; i++) {
if(i < (2)) {
partition[i] = 1;
} else {
partition[i] = 0;
}
}
float dbcv_index = dbcv(partition, dm, n_objects, n_attributes);
printf("dbcv: %f\n", dbcv_index);
free(dataset);
free(dm);
return 0;
}