forked from Alfiuman/WhydahGally-LSTM-MLP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LossFunctions.cpp
131 lines (100 loc) · 3.28 KB
/
LossFunctions.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
#include "LossFunctions.h"
namespace WhydahGally
{
namespace Maths
{
//Simple loss function.
std::vector<float> lossFunctSimple(const std::vector<float>& x, const std::vector<float>& y)
{
return vectorsDifference(x, y);
}
std::vector<float> lossFunctSimple(const std::vector<std::vector<float>>& x, const std::vector<float>& y)
{
return matrixVectorDifference(x, y);
}
//Logarithmic loss function.
std::vector<float> lossFunctLog(const std::vector<float>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = (-((y[i] * log(x[i])) + ((1 - y[i]) * log(1 - x[i])))) * sign(x[i] - y[i]);
}
return results;
}
std::vector<float> lossFunctLog(const std::vector<std::vector<float>>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = (-((y[i] * log(x[i][0])) + ((1 - y[i]) * log(1 - x[i][0])))) * sign(x[i][0] - y[i]);
}
return results;
}
//Cubic logarithmic loss function.
std::vector<float> lossFunctLogPow3(const std::vector<float>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = pow((-((y[i] * log(x[i])) + ((1 - y[i]) * log(1 - x[i])))) * sign(x[i] - y[i]), 3);
}
return results;
}
std::vector<float> lossFunctLogPow3(const std::vector<std::vector<float>>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = pow((-((y[i] * log(x[i][0])) + ((1 - y[i]) * log(1 - x[i][0])))) * sign(x[i][0] - y[i]), 3);
}
return results;
}
//Cubic loss function.
std::vector<float> lossFunctPow3(const std::vector<float>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = pow(x[i] - y[i], 3);
}
return results;
}
std::vector<float> lossFunctPow3(const std::vector<std::vector<float>>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = pow(x[i][0] - y[i], 3);
}
return results;
}
//Cubic plus cubic logarithmic loss function.
std::vector<float> lossFunctPow3PLogPow3(const std::vector<float>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = pow(x[i] - y[i], 3) + pow((-((y[i] * log(x[i])) + ((1 - y[i]) * log(1 - x[i])))) * sign(x[i] - y[i]), 3);
}
return results;
}
std::vector<float> lossFunctPow3PLogPow3(const std::vector<std::vector<float>>& x, const std::vector<float>& y)
{
std::vector<float> results;
results.resize(x.size());
for (int i = 0; i < x.size(); ++i)
{
results.at(i) = pow(x[i][0] - y[i], 3) + pow((-((y[i] * log(x[i][0])) + ((1 - y[i]) * log(1 - x[i][0])))) * sign(x[i][0] - y[i]), 3);
}
return results;
}
}
}