forked from lvdmaaten/bhtsne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsne_main.cpp
44 lines (37 loc) · 1.32 KB
/
tsne_main.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <ctime>
#include "tsne.h"
// Function that runs the Barnes-Hut implementation of t-SNE
int main() {
// Define some variables
int origN, N, D, no_dims, max_iter, *landmarks;
double perc_landmarks;
double perplexity, theta, *data;
int rand_seed = -1;
TSNE* tsne = new TSNE();
// Read the parameters and the dataset
if(tsne->load_data(&data, &origN, &D, &no_dims, &theta, &perplexity, &rand_seed, &max_iter)) {
// Make dummy landmarks
N = origN;
int* landmarks = (int*) malloc(N * sizeof(int));
if(landmarks == NULL) { printf("Memory allocation failed!\n"); exit(1); }
for(int n = 0; n < N; n++) landmarks[n] = n;
// Now fire up the SNE implementation
double* Y = (double*) malloc(N * no_dims * sizeof(double));
double* costs = (double*) calloc(N, sizeof(double));
if(Y == NULL || costs == NULL) { printf("Memory allocation failed!\n"); exit(1); }
tsne->run(data, N, D, Y, no_dims, perplexity, theta, rand_seed, false, max_iter);
// Save the results
tsne->save_data(Y, landmarks, costs, N, no_dims);
// Clean up the memory
free(data); data = NULL;
free(Y); Y = NULL;
free(costs); costs = NULL;
free(landmarks); landmarks = NULL;
}
delete(tsne);
}