From a456e6397552f872ccb56793b6b9b992958c087f Mon Sep 17 00:00:00 2001 From: anapt Date: Sun, 21 Jan 2018 16:04:29 +0200 Subject: [PATCH] iteration refactor --- testers/iteration.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 testers/iteration.c diff --git a/testers/iteration.c b/testers/iteration.c new file mode 100644 index 0000000..ca61cc1 --- /dev/null +++ b/testers/iteration.c @@ -0,0 +1,51 @@ +void iteration (int number_of_iterations, int NUMBER_OF_POINTS, int DIMENSIONS, int h){ + + for (int iter=0; iter < number_of_iterations; iter++){ + double accum =0; + for (int i =0; i< NUMBER_OF_POINTS; i++){ + for (int j=0; j< NUMBER_OF_POINTS; j++){ + //calculate distance between vectors x, y + double sum=0; + double dif; + for (int k=0; k < DIMENSIONS; k++){ + // TODO CHANGE NAMES + dif = y[k]-x[k]; + sum += dif*dif; + } + double distance = sqrt(sum); + // 2 sparse array + if (distance < h){ + kernel_matrix[i][j] = dist; + }else{ + kernel_matrix[i][j] = 0; + } + if (kernel_matrix[i][j]!=0){ + kernel_matrix[i][j] = kernel_matrix[i][j]*kernel_matrix[i][j]; + double pow = ((-1)*(kernel_matrix[i][j]))/(2*(h*h)); + kernel_matrix[i][j] = exp(pow); + } + if (i==j){ + kernel_matrix[i][j] = kernel_matrix[i][j] +1; + } + accum = accum + kernel_matrix[i][j]; + } + denominator[i] = accum; + + for (int j =0; j < DIMENSIONS;j++){ + new_shift[i][j]=0; + for (int k=0; k