-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelperFunc.cpp
More file actions
46 lines (37 loc) · 1.21 KB
/
Copy pathHelperFunc.cpp
File metadata and controls
46 lines (37 loc) · 1.21 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
#include <iostream>
#include <vector>
#include <cmath>
#include "HelperFunc.h"
using namespace std;
bool HelperFunc::textContainsOnlySmallLetters(const string& text)
{
for (char ch : text) {
if (!islower(ch)) {
return false;
}
}
return true;
}
void HelperFunc::printDashLine()
{
cout << "----------------------------------------------------------------------------------------------------------" << endl;
}
vector<double> HelperFunc::generateNormalSizeDistribution(int maxSize, double mean, double stddev)
{
if (mean < 0) mean = maxSize / 2.0; // implicitní støed uprostøed
if (stddev < 0) stddev = maxSize / 6.0; // implicitní rozptyl (vìtšina hodnot v rozsahu)
std::vector<double> distribution(maxSize);
double sum = 0.0;
for (int i = 0; i < maxSize; ++i) {
// Gaussova køivka: f(x) = exp(-0.5 * ((x - mean)/stddev)^2)
double x = i + 1; // velikosti od 1 do maxSize
double prob = std::exp(-0.5 * std::pow((x - mean) / stddev, 2));
distribution[i] = prob;
sum += prob;
}
// Normalizace na souèet 1
for (int i = 0; i < maxSize; ++i) {
distribution[i] /= sum;
}
return distribution;
}