Repository navigation
Expand file tree
/
Copy pathlossFuncs.py
More file actions
40 lines (27 loc) · 1.48 KB
/
Copy pathlossFuncs.py
File metadata and controls
40 lines (27 loc) · 1.48 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
import numpy as np
import activationFuncs
from numba import jit
@jit(nopython=True) # Set "nopython" mode for best performance, equivalent to @njit
# loss functions to be imported in class
def binary_crossentropy(target, output): # binary crossentropy error
output = activationFuncs.sigmoid(output)
return -np.multiply(target,np.log(output)) - np.multiply((1-target),np.log(1-output))
def categorical_crossentropy(target, output): # categorical cross entropy error
# print('output:',output.shape)
# output = activationFuncs.softmax(output)
# print('softmax output: ', output.shape)
# print('applied log: ', np.log(output).shape)
# print('target:',target.shape)
# print('multiplied:',np.multiply(target, np.log(output)).shape)
# print('error:', -np.sum(np.multiply(target, np.log(output))).shape)
return -np.sum(np.multiply(target, np.log(output)))
def mean_squared_error(target, output): # mean squared error
return np.square(target-output)/target.shape[0]
def mean_absolute_error(target, output): # mean absolute error
return np.abs(target-output)/target.shape[0]
loss_func_dict = { 'binary_crossentropy' : binary_crossentropy,
'categorical_crossentropy': categorical_crossentropy,
'mean_squared_error' : mean_squared_error,
'mean_absolute_error' : mean_absolute_error }
def get_loss_func(identifier): # function to return loss function corresponding to
return loss_func_dict[identifier]