-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistance_functions.h
More file actions
66 lines (39 loc) · 1.43 KB
/
distance_functions.h
File metadata and controls
66 lines (39 loc) · 1.43 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Created by ted on 10/19/18.
//
#ifndef PRJ_SUPPORT_FUNCTIONS_H
#define PRJ_SUPPORT_FUNCTIONS_H
#include <stdlib.h>
#include <algorithm>
#include <random>
#include <iostream>
#include <fstream>
#include "Datapoint.h"
using namespace std;
pair<int, double> find_nearest(Datapoint &x, vector<vector<double>> &candidates, bool slow_exact_distance , bool verbose=false);
double calculate_min_dist_betweeen_clusters(vector<vector<double>> &clusters);
int find_2nd_best_cluster(Datapoint &x, vector<vector<double>> &clusters, int current_cluster);
template<typename T>
T random_gen(char distrib, T u_min, T u_max) {
// returns "u"niformly random int/float between min-max
// or "g"aussian random int/float with m = 0 , s =1
T number;
std::random_device rd;
std::mt19937 gen(rd());
if (distrib == 'n' || distrib == 'g') {
std::normal_distribution<float> d(0, 1);
number = (T) d(gen);
} else if (distrib == 'u') {
std::uniform_real_distribution<> dist(u_min, u_max);
number = (T) dist(gen);
//number = static_cast<T>((rand()) % (int)max + min);
} else {
number = rand();
}
//cout << number << endl;
return number;
}
vector<float> random_gen_vec(int dimension);
double euclDistanceNN(Datapoint &q, vector <Datapoint> &dataset, double R);
double cosDistanceNN(Datapoint &datapoint, vector <Datapoint> list);
#endif //PRJ_SUPPORT_FUNCTIONS_H