-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateCent.c
More file actions
27 lines (21 loc) · 709 Bytes
/
updateCent.c
File metadata and controls
27 lines (21 loc) · 709 Bytes
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
/*
*208539270 yardenbakish
*208983700 tamircohen1
* updateCent.c
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "kmeans.h"
/*each time we assign an observation to a cluster - we immediately calculate the NEW CURRENT
centroid location according to the observation's coordinates. the sizes array helps us
to know how many observations chose this cluster thus far and calculate accordingly so that at the end
of an iteration we get the new centroids location properly. we change a 'new centroids' array
and keep a copy of the old ones*/
void updateCentroids(double *p1, double * p2, int size, int d) {
int i = 0;
for (i = 0; i < d; i++) {
p1[i] = p1[i] + ((p2[i] - p1[i]) / size);
}
}