-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
73 lines (54 loc) · 1.86 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Code to produce random double precision numbers from a gaussian distribution.
The produced nrows of ncols will be written to a file on disk.
This code is an attempt to write a library that will compare two different
sets of arrays where those arrays represent some particular observation. We will
then calculate the (euclidean)-distance between them and extract the 5 closest ones.
Example:
- Array 'A' has 4 million rows with 5-columns dimensionality.
- Array 'B' has 2 million rows with same dimensionality as 'A'.
For every row in array 'A' we want to find the 5 closest (similar) rows
in array 'B' and do the same for every single row in 'A'.
array 'A' will always be considered the 'principal' array.
array 'B' will always be considered the 'secondary' array. In the future,
we can replace rows in array 'B' with another set and perform
the same type of comparison.
In essence, we want to find the 5-similar rows in array 'B' corresponding
or closely similar (in distance) to array 'A'.
*/
#include <iostream>
#include <fstream>
#include <ctime>
#include <random>
using namespace std;
int main() {
int loops = 2;
int nrows = 1;
int ncols = 6;
// variable storing the random generated number
// from the gaussian distribution
double num;
// open file to write row-columns
ofstream ofs;
ofs.open("C:/temp/matrix_xxx.csv", ios::out);
std::random_device rd;
double mu = 0.0, sigma = 1.0;
// loop to write nloops-times random numbers
time_t now = time(0);
for (int i = 0; i < loops; i++) {
std::mt19937 eng(rd());
std::normal_distribution<double> normal(mu, sigma);
for (int j = 0; j < ncols; j++) {
num = (double)normal(eng);
ofs << abs(num);
if (j < (ncols - 1)) {
ofs << ",";
}
}
ofs << endl;
}
ofs.close();
time_t after = time(0);
cout << "Elapsed: " << (after - now) << endl;
return 0;
}