tsne_main.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <cfloat>
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <ctime>
  7. #include "tsne.h"
  8. // Function that runs the Barnes-Hut implementation of t-SNE
  9. int main2() {
  10. // Define some variables
  11. int origN, N, D, no_dims, max_iter;
  12. double perplexity, theta, *data;
  13. int rand_seed = -1;
  14. // Read the parameters and the dataset
  15. if(TSNE::load_data(&data, &origN, &D, &no_dims, &theta, &perplexity, &rand_seed, &max_iter)) {
  16. // Make dummy landmarks
  17. N = origN;
  18. int* landmarks = (int*) malloc(N * sizeof(int));
  19. if(landmarks == NULL) { printf("Memory allocation failed!\n"); exit(1); }
  20. for(int n = 0; n < N; n++) landmarks[n] = n;
  21. // Now fire up the SNE implementation
  22. double* Y = (double*) malloc(N * no_dims * sizeof(double));
  23. double* costs = (double*) calloc(N, sizeof(double));
  24. if(Y == NULL || costs == NULL) { printf("Memory allocation failed!\n"); exit(1); }
  25. TSNE::run(data, N, D, Y, no_dims, perplexity, theta, 200.0, rand_seed, false, max_iter, 250, 250);
  26. // Save the results
  27. TSNE::save_data(Y, landmarks, costs, N, no_dims);
  28. // Clean up the memory
  29. free(data); data = NULL;
  30. free(Y); Y = NULL;
  31. free(costs); costs = NULL;
  32. free(landmarks); landmarks = NULL;
  33. }
  34. }