Browse Source

Fix memory allocations

master
Apostolos Fanakis 7 years ago
parent
commit
79c9c5f826
  1. 12
      data/run_helper.txt
  2. 43
      mean_shift_serial/serial_declarations.c

12
data/run_helper.txt

@ -1,9 +1,9 @@
Dataset X {
int NUMBER_OF_POINTS = 600;
int DIMENSIONS = 2;
char* POINTS_FILENAME = "data/X.bin";
char* POINTS_FILENAME = "../data/X.bin";
A good h is 1
A good deviation is 1
For Processing script:
float maxX = 17.124000;
float minX = 3.402000;
@ -16,9 +16,9 @@ Dataset X {
Dataset s1 {
int NUMBER_OF_POINTS = 5000;
int DIMENSIONS = 2;
char* POINTS_FILENAME = "data/s1";
char* POINTS_FILENAME = "../data/s1";
A good h is 30000
A good deviation is 30000
For Processing script:
float maxX = 961951;
float minX = 19835;
@ -31,9 +31,9 @@ Dataset s1 {
Dataset s4 {
int NUMBER_OF_POINTS = 5000;
int DIMENSIONS = 2;
char* POINTS_FILENAME = "data/s4";
char* POINTS_FILENAME = "../data/s4";
A good h is 30000-35000
A good deviation is 30000-35000
For Processing script:
float maxX = 932954;
float minX = 89604;

43
mean_shift_serial/serial_declarations.c

@ -90,27 +90,26 @@ void init(double ***vectors, char **labels, parameters *params){
int meanshift(double **original_points, double ***shifted_points, int deviation
, parameters *opt){
static int iteration = 0;
static double **mean_shift_vector, **kernel_matrix, *denominator;
// allocates memory and copies original points on first iteration
if (iteration == 0 || (*shifted_points) == NULL){
iteration = 0;
(*shifted_points) = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS);
duplicate(original_points, NUMBER_OF_POINTS, DIMENSIONS, shifted_points);
}
// allocates memory for mean shift vector
double **mean_shift_vector;
mean_shift_vector = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS);
// initializes elements of mean_shift_vector to inf
for (int i=0;i<NUMBER_OF_POINTS;i++){
for (int j=0;j<DIMENSIONS;j++){
mean_shift_vector[i][j] = DBL_MAX;
// allocates memory for mean shift vector
mean_shift_vector = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS);
// initializes elements of mean_shift_vector to inf
for (int i=0;i<NUMBER_OF_POINTS;i++){
for (int j=0;j<DIMENSIONS;j++){
mean_shift_vector[i][j] = DBL_MAX;
}
}
}
// allocates memory for other arrays needed
double **kernel_matrix = alloc_2d_double(NUMBER_OF_POINTS, NUMBER_OF_POINTS);
double *denominator = malloc(NUMBER_OF_POINTS * sizeof(double));
// allocates memory for other arrays needed
kernel_matrix = alloc_2d_double(NUMBER_OF_POINTS, NUMBER_OF_POINTS);
denominator = malloc(NUMBER_OF_POINTS * sizeof(double));
}
// finds pairwise distance matrix (inside radius)
// [I, D] = rangesearch(x,y,h);
@ -160,17 +159,19 @@ int meanshift(double **original_points, double ***shifted_points, int deviation
double current_norm = norm(mean_shift_vector, NUMBER_OF_POINTS, DIMENSIONS);
printf("Iteration n. %d, error %f \n", iteration, current_norm);
// cleans up this iteration's allocations
free(mean_shift_vector[0]);
free(mean_shift_vector);
free(kernel_matrix[0]);
free(kernel_matrix);
free(denominator);
/** iterates until convergence **/
if (current_norm > opt->epsilon) {
++iteration;
return meanshift(original_points, shifted_points, deviation, opt);
meanshift(original_points, shifted_points, deviation, opt);
}
if (iteration == 0){
// cleans up this iteration's allocations
free(mean_shift_vector[0]);
free(mean_shift_vector);
free(kernel_matrix[0]);
free(kernel_matrix);
free(denominator);
}
return iteration;

Loading…
Cancel
Save