-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_clusters.cpp
89 lines (60 loc) · 1.57 KB
/
find_clusters.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <fstream>
using namespace std;
double** find_clusters(vector<vector<double> > sols, int NT, int num_osc, string dir){
/* Finds c_i(t) := N_i / N,
N_i = num of groups of sync'd oscillators of size i. I.e. if
there are 7 pairs of oscillators synchronised, then
N_2 = 7
*/
//Open file
ofstream fout;
if(dir == "default")
fout.open("cluster_results.csv");
else
fout.open("./" + dir + "/cluster_results.csv");
//Instantiate
double** clusters;
clusters = new double*[NT];
for(int t=0;t<NT;t++){
clusters[t] = new double[num_osc];
for(int osc=0;osc<num_osc;osc++)
clusters[t][osc] = 0;
};
//Find Clusters -- c_j(t) as defined in paper
for(int t=0;t<NT;t++){
//Find osc(t)
double osc[num_osc];
for(int i=0;i<num_osc;i++)
osc[i] = sols[t][i];
//Tally data -- sort, then count duplicates, and record
sort(osc, osc+sizeof(osc)/sizeof(double));
int counter = 0;
for(int i=0;i<num_osc-1;i++){
if(osc[i] == osc[i+1])
counter++;
else{
counter++;
clusters[t][counter-1] += 1 / double(num_osc);
counter = 0;
}
}
//Boundary Case
counter += 1;
clusters[t][counter-1] += 1 / double(num_osc);
/* I'm changing writing to file slightly to
that it only writes the first 5
*/
//Write to file
//int max_cluster_to_print = 5;
fout << clusters[t][0];
for(int i=1;i<num_osc;i++)
fout << "," << clusters[t][i];
fout << endl;
}
fout.close();
return clusters;
}