-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMisc.cpp
More file actions
84 lines (69 loc) · 1.29 KB
/
Misc.cpp
File metadata and controls
84 lines (69 loc) · 1.29 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**************************Preprocessor Directives****************/
#include "pch.h"
#include <random>
#include <time.h>
#include <exception>
#include "Misc.h"
/*************************Functions****************/
int Misc::Random(int min, int max)
{
int numOfPossibleVals = (max - min) - 1;
int a = 0;
while (a == 0)
{
a = rand() % numOfPossibleVals;
}
return (min + a);
}
signed char Misc::Signum(double x)
{
if (x < 0)
return -1;
else if (x > 0)
return 1;
else
return 0;
}
double Misc::Sigmoid(double x)
{
return (1.0 / (1.0 + exp(-x)));
}
double Misc::DeSigmoid(double y)
{
return (log(y) - log(1.0 - y));
}
double Misc::Tanh(double x)
{
return tanh(x);
}
double Misc::TanhInverse(double y)
{
return atanh(y);
}
double Misc::ReLu(double x)
{
if (x > 0)
return x;
else
return 0;
}
double Misc::DeReLu(double y)
{
return y;
}
double Misc::Average(double* vals, int n)
{
double sum = 0.0;
for (int a = 0; a < n; ++a)
{
sum += vals[a];
}
return (sum / n);
}
int Misc::PowWrt10(double x)
{
int powWrt2 = 0; /*The power of x wrt 2*/
std::frexp(x, &powWrt2); /*Getting the power wrt 2*/
int powWrt10 = ceil(powWrt2 * (log(2) / log(10))); /*Calculating the pow wrt 10*/
return powWrt10;
}