-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloss_functions.py
60 lines (40 loc) · 1010 Bytes
/
loss_functions.py
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
"""
number of loss functions to use with different models
"""
import numpy
def abs_loss(residual):
"""
absolute loss
"""
return numpy.abs(residual)
def squared_loss(residual):
"""
squared loss
"""
return residual * residual
def eps_loss(residual, epsilon):
"""
epsilon-insensitive loss
"""
if numpy.abs(residual) < epsilon:
return 0
else:
return numpy.abs(residual) - epsilon
def eps_loss_bounded(residual, epsilon):
"""
epsilon-insensitive loss
"""
if numpy.abs(residual) < epsilon:
return 0
else:
return max(numpy.abs(residual) - epsilon, 3)
def eps_loss_asym(residual, epsilon, slope_inside, slope_outside):
"""
asymmetric loss for inside and outside of the circle
"""
if numpy.abs(residual) < epsilon:
return 0
elif residual > 0:
return (residual - epsilon) * slope_outside
else:
return (numpy.abs(residual) - epsilon) * slope_inside