-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
341 lines (297 loc) · 8.39 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/*
Representação 1D de diferentes distribuições de probabilidade
*/
#include <bits/stdc++.h>
#include <boost/program_options.hpp>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include "gnuplot-iostream/gnuplot-iostream.h"
using namespace std;
/* Funções que definem as distribuições */
// Logistic Map, r = 4.0 (Fister, 2015)
double logisticMap(double randomNum, double r) {
randomNum = r * randomNum * (1 - randomNum);
return randomNum;
}
// Circle Map, a = 0.5, b = 0.2 (Gandomi, 2013)
double circleMap(double randomNum, double a, double b) {
randomNum = fmod(randomNum + b - a/(2*M_PI) * sin(2*M_PI*randomNum), 1.0);
return randomNum;
}
// Gauss Map
double gaussMap(double randomNum) {
if(randomNum == 0.0) {
return 0.0;
} else {
return fmod((1/randomNum), 1.0);
}
}
// Piecewise Map, p = 0.4 (Saxena, 2018)
double piecewiseMap(double randomNum, double p) {
if(randomNum >= 0 && randomNum < p) {
return randomNum/p;
} else if(randomNum >= p && randomNum < 0.5) {
return (randomNum-p)/(0.5-p);
} else if(randomNum >= 0.5 && randomNum <= 1-p) {
return (1-p-randomNum)/(0.5-p);
} else if(randomNum >= 1-p && randomNum < 1) {
return (1-randomNum)/p;
}
}
// Sine Map, a = 4.0 (Saxena, 2018)
double sineMap(double randomNum, double a) {
return (a/4.0) * sin(M_PI * randomNum);
}
// Singer Map, u = 1.07 (Kaveh, 2018)
double singerMap(double randomNum, double u) {
return u*(7.86*randomNum - 23.31*pow(randomNum, 2) + 28.75*pow(randomNum, 3) - 13.302875*pow(randomNum, 4));
}
// Sinusoidal Map, a = 2.3 (Saxena, 2018)
double sinusoidalMap(double randomNum, double a) {
return a*pow(randomNum, 2)*sin(M_PI*randomNum);
}
// Tent Map
double tentMap(double randomNum) {
if(randomNum < 0.7) {
return randomNum/0.7;
} else if(randomNum >= 0.7) {
return (10/3.0) * (1-randomNum);
}
}
// Chebyshev Map, i = iteration number (Kaveh, 2018)
double chebyshevMap(double randomNum, int i) {
return cos(i*acos(randomNum));
}
// Iteractive Map, a = 0.7 (Saxena, 2018)
double iteractiveMap(double randomNum, double a) {
return sin((a*M_PI)/randomNum);
}
int main() {
Gnuplot gp;
gsl_rng *r;
gsl_rng_env_setup();
const gsl_rng_type * ti = gsl_rng_default;
r = gsl_rng_alloc (ti);
vector< pair<int, int> > graph;
mt19937 rng;
rng.seed(chrono::high_resolution_clock::now().time_since_epoch().count());
uniform_real_distribution<double> random2(0, 1);
double last = random2(rng);
int contador = 1;
cout << "Which distribution you want to display?" << endl;
cout << "1 - Uniform\n2 - Gaussian\n3 - Cauchy\n4 - Logistic\n5 - Circle\n6 - Gauss\n7 - Piecewise\n8 - Sine\n9 - Singer\n10 - Sinusoidal\n11 - Tent\n12 - Chebyshev\n13 - Iteractive\n";
int distribution;
cin >> distribution;
gp << "set yrange [" << 0 << ":" << 100 << "]\nset xrange [0:100]\n";
switch(distribution) {
// Uniform distribution
case 1:
{
int count[101] = {0};
uniform_int_distribution<int> random(0, 100);
for(int i = 0; i < 2000; i++) {
int y = random(rng);
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Uniform Distribution'\n";
break;
}
// Gaussian distribution
case 2:
{
int count[101] = {0};
int y;
for(int i = 0; i < 2000; i++) {
// Média 50, desvio-padrão 15
while(true) {
y = gsl_ran_gaussian(r, 15.0) + 50;
if(y >= 0 && y <= 100) {
break;
}
}
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Gaussian Distribution'\n";
break;
}
// Cauchy distribution
case 3:
{
int count[101] = {0};
int y;
for(int i = 0; i < 2000; i++) {
while(true) {
y = gsl_ran_cauchy(r, 10.0) + 50;
if(y >= 0 && y <= 100) {
break;
}
}
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Cauchy Distribution'\n";
break;
}
// Logistic map
case 4:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = logisticMap(last, 4.0);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Logistic Distribution'\n";
break;
}
// Circle map
case 5:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = circleMap(last, 0.5, 0.2);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Circle Distribution'\n";
break;
}
// Gauss map
case 6:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = gaussMap(last);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Gauss Distribution'\n";
break;
}
// Piecewise map
case 7:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = piecewiseMap(last, 0.4);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Piecewise Distribution'\n";
break;
}
// Sine map
case 8:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = sineMap(last, 4.0);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Sine Distribution'\n";
break;
}
// Singer map
case 9:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = singerMap(last, 1.07);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Singer Distribution'\n";
break;
}
// Sinusoidal map
case 10:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = sinusoidalMap(last, 2.3);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Sinusoidal Distribution'\n";
break;
}
// Tent map
case 11:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = tentMap(last);
int y = 100 * last;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Tent Distribution'\n";
break;
}
// Chebyshev map
case 12:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = chebyshevMap(last, i+1);
int y = (100 * (last+1))/2;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Chebyshev Distribution'\n";
break;
}
// Iteractive map
case 13:
{
int count[101] = {0};
for(int i = 0; i < 2000; i++) {
last = iteractiveMap(last, 0.7);
int y = (100 * (last+1))/2;
count[y]++;
}
for(int i = 0; i < 101; i++){
graph.push_back(make_pair(i, count[i]));
}
gp << "plot '-' with lines pt 7 ps 1 lt rgb 'red' title 'Iteractive Distribution'\n";
break;
}
}
gp.send1d(graph);
gsl_rng_free (r);
return 0;
}