// Function that runs the Barnes-Hut implementation of t-SNE int main() { // Define some variables int origN, N, D, no_dims, *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)) { // 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); // 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); }
// Function that runs the Barnes-Hut implementation of t-SNE int main() { // Define some variables int origN, N, D, no_dims, iterations, *landmarks; double perc_landmarks; double perplexity, theta, eta, *data; float gpu_mem; int verbose; int rand_seed = -1; int seed = 0; TSNE* tsne = new TSNE(); time_t start = clock(); // Read the parameters and the dataset if (tsne->load_data(&data, &origN, &D, &no_dims, &theta, &perplexity, &eta, &iterations, &seed, &gpu_mem, &verbose, &rand_seed)) { // Set random seed if (rand_seed >= 0) { if (verbose > 0) printf("Using random seed: %d\n", rand_seed); srand((unsigned int)rand_seed); } else { if (verbose > 0) printf("Using current time as random seed...\n"); srand(time(NULL)); } // 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->zeroMean(data, N, D); tsne->normalize(data, N, D); if (seed == 0){ seed = origN; } tsne->runWithCenterOfMass(data, Y, origN, seed, D, no_dims, perplexity, theta, eta, iterations, gpu_mem, verbose); // Save the results tsne->save_data(Y, landmarks, costs, N, no_dims, verbose); // Clean up the memory free(data); data = NULL; free(Y); Y = NULL; free(costs); costs = NULL; free(landmarks); landmarks = NULL; } delete(tsne); time_t end = clock(); if (verbose > 0) printf("T-sne required %f seconds (%f minutes) to run\n", float(end - start) / CLOCKS_PER_SEC, float(end - start) / (60 * CLOCKS_PER_SEC)); }
// Function that runs the Barnes-Hut implementation of t-SNE int main(int argc, char** argv) { int metrics = 0; if (argc > 1) { if (!strcmp(argv[1], "1")) metrics = 1; } // Define some variables int origN, N, D, no_dims = 2, *landmarks; double perc_landmarks; double perplexity, theta, *data; TSNE* tsne = new TSNE(); // Read the parameters and the dataset if(tsne->load_data(&data, &origN, &D, &theta, &perplexity)) { // 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); } double (*metric_func) (const DataPoint&, const DataPoint&); switch (metrics) { case 1: metric_func = log_cosine_distance; printf("Using %s As Distance Metrics.\n", "Log-Cosine-Similarity"); break; default: metric_func = euclidean_distance; printf("Using %s As Distance Metrics.\n", "Euclidean-Distance"); break; } tsne->run(data, N, D, Y, no_dims, perplexity, theta, metric_func); // 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); }