-
Notifications
You must be signed in to change notification settings - Fork 0
/
Delinearizer.cpp
152 lines (134 loc) · 3.66 KB
/
Delinearizer.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
#include "Delinearizer.h"
/* Calculation */
float Logarithmic (float Input, boolean Range)
{
if (Range == false)
{
Input = 100.0 - Trim (Input) * 99.0 / 100.0;
return 100.0 - 50.0 * log10(Input);
}
else
{
Input = 100.0 - Trim (Input + 1.0, 0.0, 2.0) * 99.0 / 1.99999;
return 1.0 - log10(Input);
}
}// Execution time: 222.18us (Range: 0.0 to 100.0); 229.496us (Range: -1.0 to 1.0)
float InverseLogarithmic (float Input, boolean Range)
{
if (Range == false)
{
Input = Trim (Input) * 99.0 / 100.0 + 1.0;
return 50.0 * log10(Input);
}
else
{
Input = Trim (Input + 1.0, 0.0, 2.0) * 99.0 / 1.99999 + 1.0;
return log10(Input) - 1.0;
}
}// Execution time: 223.02us (Range: 0.0 to 100.0); 230.292us (Range: -1.0 to 1.0)
float SCurve (float Input, boolean Range)
{
if (Range == false)
{
Input = Trim (Input);
if (Input < 50.0)
return InverseLogarithmic (Input) / ScaleILL;
else
return Logarithmic (Input) / ScaleILL + OffsetILL;
}
else
{
Input = Trim (Input + 1.0, 0.0, 2.0) * 50.0;
if (Input < 50.0)
return (InverseLogarithmic (Input) / ScaleILL) / 50 - 1;
else
return (Logarithmic (Input) / ScaleILL + OffsetILL) / 50 - 1;
}
}// Execution time: 281.124us (Range: 0.0 to 100.0); 335.092us (Range: -1.0 to 1.0)
float BellCurve (float Input, boolean Range)
{
if (Range == false)
{
Input = Trim (Input);
return 50.0 + 50.0 * sin ((-90.0 + Input * (360.0 / 100.0)) * (PI / 180.0));
}
else
{
Input = Trim (Input + 1.0, 0.0, 2.0);
return sin ((-90.0 + Input * (360.0 / 2.0)) * (PI / 180.0));
}
}// Execution time: 151.1us (Range: 0.0 to 100.0); 158.828us (Range: -1.0 to 1.0)
float ReLU (float Input, boolean Range)
{
if (Range == true)
return Trim (Input, 0.0, 1.0);
else
return Trim (Input, 50.0, 100.0);
}// Execution time: 16.496us (Range: 0.0 to 100.0); 16.568us (Range: -1.0 to 1.0)
float SigmoidExp (float Input, boolean Range)
{
if (Range == true)
{
Input = Trim (Input, -1.0, 1.0) * 10;
return (1.0 / (1.0 + exp (-Input))) * 2 - 1;
}
else
{
Input = Trim (Input);
return (1.0 / (1.0 + exp (-((Input - 50) / 5)))) * 100;
}
}// Execution time: 218.224us (Range: 0.0 to 100.0); 190.088us (Range: -1.0 to 1.0)
float SigmoidSine (float Input, boolean Range)
{
if (Range == true)
{
Input = Trim (Input + 1, 0.0, 2.0);
return sin ((-90.0 + Input * (180.0 / 2.0)) * (PI / 180.0));
}
else
{
Input = Trim (Input);
return 50.0 + 50.0 * sin ((-90.0 + Input * (180.0 / 100.0)) * (PI / 180.0));
}
}// Execution time: 148.748us (Range: 0.0 to 100.0); 156.468us (Range: -1.0 to 1.0)
float SigmoidInvLog (float Input, boolean Range)
{
if (Range == true)
{
Input = Trim (Input + 1.0, 0.0, 2.0) * 50.0;
if (Input < 49.99999)
return (50.00856 - InverseLogarithmic (50.0 - Input) / ScaleILL) / 50.0 - 1.0;
else
return (InverseLogarithmic (Input - 50.0) / ScaleILL + 49.99144) / 50.0 - 1.0;
}
else
{
Input = Trim (Input);
if (Input < 49.99999)
return 50.00856 - InverseLogarithmic (50.0 - Input) / ScaleILL;
else
return InverseLogarithmic (Input - 50.0) / ScaleILL + 49.99144;
}
}// Execution time: 285.128us (Range: 0.0 to 100.0); 338.396us (Range: -1.0 to 1.0)
/* Conversion */
float ItoF (unsigned int Input)
{
if (Input > 10000)
Input = 10000;
return float(Input) / 100;
}
unsigned int FtoI (float Input)
{
if (Input > 100)
Input = 100;
return (unsigned int)(Input * 100);
}
float Trim (float Input, float LowerLimit, float UpperLimit)
{
if (Input < LowerLimit)
return LowerLimit;
else if (Input > UpperLimit)
return UpperLimit;
else
return Input;
}