-
Notifications
You must be signed in to change notification settings - Fork 19
/
transfer_functions_benchmark.py
179 lines (113 loc) · 2.53 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
"""
Created on Tue Dec 27 12:46:20 2019
@author: Ibrahim Aljarah, and Ruba Abu Khurma
"""
#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
#__________________Calling for transfer functions inside this script____________________
#T1=v1(x)
#T2=v2(x)
#T3=v3(x)
#T4=v4(x)
#
#T5=s1(x)
#T6=s2(x)
#T7=s3(x)
#T8=s4(x)
#
#T9=sigmf1(x,.5,10)
#T10=sigmf2(x,.5,10)
#
##_______________Plotting of transfer functions inside this script________________________
#plt.figure(1)
#plt.subplot(211)
#
#plt.plot(x, T1)
#plt.plot(x, T2)
#plt.plot(x, T3)
#plt.plot(x, T4)
#plt.xlabel('x')
#plt.ylabel('f(x)')
##plt.show()
##
##plt.figure(2)
##
#plt.subplot(212)
#plt.plot(x, T5)
#plt.plot(x, T6)
#plt.plot(x, T7)
#plt.plot(x, T8)
#
#
#plt.xlabel('x')
#plt.ylabel('f(x)')
##plt.show()
##
##plt.figure(3)
##plt.subplot(222)
##plt.plot(x, T9)
#
##plt.xlabel('x')
##plt.ylabel('f(x)')
##plt.show()
##
###plt.subplot(212)
##plt.plot(x, T10)
##
##
##plt.xlabel('x')
##plt.ylabel('f(x)')
#plt.show()
##
##
#
#
#
#
#