Browse Source

Fixed memory management, Add more datasets, Fixed Processing script

master
Apostolos Fanakis 7 years ago
parent
commit
b161f2fc1d
  1. 46
      data/run_helper.txt
  2. BIN
      data/s1
  3. BIN
      data/s4
  4. 15
      output/visualization/visualization.pde
  5. 2
      serial.c
  6. 25
      serial_declarations.c

46
data/run_helper.txt

@ -0,0 +1,46 @@
Dataset X {
int NUMBER_OF_POINTS = 600;
int DIMENSIONS = 2;
char* POINTS_FILENAME = "data/X.bin";
A good h is 1
For Processing script:
float maxX = 17.124000;
float minX = 3.402000;
float maxY = 14.996000;
float minY = 3.178000;
12 iterations
}
Dataset s1 {
int NUMBER_OF_POINTS = 5000;
int DIMENSIONS = 2;
char* POINTS_FILENAME = "data/s1";
A good h is 30000
For Processing script:
float maxX = 961951;
float minX = 19835;
float maxY = 970756;
float minY = 51121;
~28 iterations
}
Dataset s4 {
int NUMBER_OF_POINTS = 5000;
int DIMENSIONS = 2;
char* POINTS_FILENAME = "data/s4";
A good h is 30000-35000
For Processing script:
float maxX = 932954;
float minX = 89604;
float maxY = 977215;
float minY = 35412;
122 iterations with epsilon = 0.0001 and h = 30000
110 iterations with epsilon = 0.01 and h = 30000
108 iterations with epsilon = 1 and h = 31000
}

BIN
data/s1

Binary file not shown.

BIN
data/s4

Binary file not shown.

15
output/visualization/visualization.pde

@ -2,20 +2,24 @@ int frame = 1;
PShape frameS;
void setup() {
size(1280, 720);
size(720, 720);
frameRate(12);
}
int scale = 40;
int scale = 1;
float radius = 2;
float maxX = 17.124000;
float minX = 3.402000;
float maxY = 14.996000;
float minY = 3.178000;
void draw() {
background(255);
stroke(0);
translate(220, 0);
//scale(scale);
fill(0);
System.out.println("frame = " + frame);
String[] lines;
lines = loadStrings("../output_" + frame);
if (lines == null){
@ -24,11 +28,14 @@ void draw() {
} else {
for (int i = 0; i < lines.length; i++) {
String[] pieces = split(lines[i], ",");
frameS = createShape(ELLIPSE, Float.parseFloat(pieces[0])*scale,Float.parseFloat(pieces[1])*scale, radius, radius);
float mapedX = map(Float.parseFloat(pieces[0]), minX, maxX, 0, 720);
float mapedY = map(Float.parseFloat(pieces[1]), minY, maxY, 0, 720);
frameS = createShape(ELLIPSE, mapedX*scale, mapedY*scale, radius, radius);
shape(frameS, 0, 0);
}
}
frame++;
//Uncomment to save each frame to a jpg file
//saveFrame("out-######.jpg");
delay(600);

2
serial.c

@ -68,5 +68,5 @@ int main(int argc, char **argv){
printf("%s wall clock time = %f\n","Mean Shift", seq_time);
//TODO write output points to file -> plot later
//save_matrix(vectors, iterations);
//save_matrix(shifted_points, iterations);
}

25
serial_declarations.c

@ -70,24 +70,35 @@ int meanshift(double **original_points, double ***shifted_points, int h
}
// create new y vector
double **y_new = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS);
multiply(kernel_matrix, original_points, y_new);
double **new_shift = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS);
// build nominator
multiply(kernel_matrix, original_points, new_shift);
// divide element-wise
for (int i=0; i<NUMBER_OF_POINTS; i++){
for (int j=0; j<DIMENSIONS; j++){
y_new[i][j] = y_new[i][j] / denominator[i];
// calculate mean-shift vector
mean_shift_vector[i][j] = y_new[i][j] - (*shifted_points)[i][j];
new_shift[i][j] = new_shift[i][j] / denominator[i];
// calculate mean-shift vector at the same time
mean_shift_vector[i][j] = new_shift[i][j] - (*shifted_points)[i][j];
}
}
shifted_points = &y_new;
// frees previously shifted points, they're now garbage
free((*shifted_points)[0]);
// updates shifted points pointer to the new array address
shifted_points = &new_shift;
save_matrix((*shifted_points), iteration);
double current_norm = norm(mean_shift_vector, NUMBER_OF_POINTS, DIMENSIONS);
printf("Iteration n. %d, error %f \n", iteration, current_norm);
// clean up this iteration's allocates
free(mean_shift_vector[0]);
free(mean_shift_vector);
free(kernel_matrix[0]);
free(kernel_matrix);
free(denominator);
/** iterate until convergence **/
if (current_norm > opt->epsilon) {
return meanshift(original_points, shifted_points, h, opt, ++iteration);

Loading…
Cancel
Save