-
Notifications
You must be signed in to change notification settings - Fork 0
/
transfer_functions_benchmark.py
74 lines (48 loc) · 1.45 KB
/
transfer_functions_benchmark.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#import skfuzzy
import numpy as np
from math import pi
from scipy.special import erf
import matplotlib.pylab as plt
#________________________V-shaped transfer functions______________________
def v1(x):
v1=abs(erf((np.sqrt(pi)/2)*x))
return v1
def v2(x):
v2=abs(np.tanh(x))
return v2
def v3(x):
v3= abs(x/np.sqrt(1+np.square(x)))
return v3
def v4(x):
v4= abs((2/pi)*np.arctan((pi/2)*x))
return v4
##______________________S-shaped transfer functions_______________________
def s1(x):
s1=1 / (1 + np.exp(-2*x))
return s1
def s2(x):
s2 = 1 / (1 + np.exp(-x))
return s2
# s2 is called logistic function and can be imported using scipy.special.expit(x) library
def s3(x):
s3=1 / (1 + np.exp(-x/3))
return s3
def s4(x):
s4=1 / (1 + np.exp(-x/2))
return s4
##________________________the sigmoid functions_________________________
# A customized function for SIGMOID
def sigmf1(x,b,c):
b=10
c=.5
y = 1 / (1. + np.exp(- c * (x - b)))
return y
## Built-in function for SIGMOID using skfuzzy.membership library
def sigmf2(x,b,c):
b=10
c=.5
y=skfuzzy.membership.sigmf(x,b,c)
return y
x = np.arange(-8, 8, 0.1)
# x is used inside this script and will be replaced by a binary individual (1-d binary vector)
#when the transfer function is called or imported in the optimizers scripts