-
Notifications
You must be signed in to change notification settings - Fork 0
/
objective_functions.py
31 lines (25 loc) · 949 Bytes
/
objective_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
import math
def absolute_percentage_error(x: float, y: float) -> float:
"""
Calculates the absolute percentage error between 2 values using the formula: abs((x - y) / y).
:param x: the calculated value.
:param y: the given value.
:return: the absolute percentage error between the 2 values.
"""
return math.fabs((y - x) / y)
def absolute_error(x: float, y: float) -> float:
"""
Calculates the absolute error between 2 values using the formula: abs(x - y).
:param x: the calculated value.
:param y: the given value.
:return: the absolute error between the 2 values.
"""
return math.fabs(y - x)
def squared_error(x: float, y: float) -> float:
"""
Calculates the squared error between 2 values using the formula: (x - y)^2.
:param x: the calculated value.
:param y: the given value.
:return: the squared error between the 2 values.
"""
return math.pow(y - x, 2)