-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifs_operators_topo.py
288 lines (203 loc) · 9.64 KB
/
ifs_operators_topo.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
##############################################################################
def F_continuous_lower(t,
alpha0, alpha, gamma_a
# beta0, beta, , gamma_b
):
# lower - izpaknala function
dAlpha = alpha - alpha0
result = None
if 0 <= t < alpha0:
result = t
elif alpha0 <= t < alpha0 + gamma_a * dAlpha:
result = alpha0
elif alpha0 + gamma_a * dAlpha <= t < alpha and gamma_a < 1.0:
result = (1. / (1. - gamma_a) )*(t - alpha) + alpha
elif alpha <= t <= 1:
result = t
else:
raise AttributeError
return result
def F_continuous_upper(t, alpha0, alpha, gamma_a):
return 1.0 - F_continuous_lower(1.0 - t,
alpha0 = 1.0 - alpha,
alpha = 1.0 - alpha0,
gamma_a = 1.0 - gamma_a)
######################################################################
##### Spike ########
######################################################################
def F_spike_upper(t,
alpha0, alpha, gamma_a):
dAlpha = alpha - alpha0
result = None
if 0.0 <= t <= alpha0:
result = t
elif alpha0 <= t < alpha:
result = (1. - gamma_a)*t + gamma_a*alpha
elif alpha <= t <= 1.:
result = t
else:
raise AttributeError
return result
def F_spike_lower(t, alpha0, alpha, gamma_a):
return 1.0 - F_spike_upper(1.0 - t,
alpha0 = 1.0 - alpha,
alpha = 1.0 - alpha0,
gamma_a = 1.0 - gamma_a)
##############################################################################
##############################################################################
##############################################################################
def incGeneral_single(
mu_type, # 'continuous' or 'spike'
nu_type, # 'continuous' or 'spike'
cut_type, # 'mu' or 'nu'
alpha0, alpha, gamma_a,
beta0, beta, gamma_b):
assert 0.0 <= alpha0 <= alpha <= 1.0
assert 0.0 <= gamma_a <= 1.0
assert 0.0 <= beta0 <= beta <= 1.0
assert 0.0 <= gamma_b <= 1.0
assert mu_type in ['continuous', 'spike'] and nu_type in ['continuous', 'spike']
assert nu_type in ['continuous', 'spike'] and nu_type in ['continuous', 'spike']
assert cut_type in ['mu', 'nu']
F_mu = F_continuous_lower if mu_type == 'continuous' else F_spike_lower
F_nu = F_continuous_upper if nu_type == 'continuous' else F_spike_upper
def inc_single(mu, nu):
mu_inc = F_mu(mu, alpha0, alpha, gamma_a)
nu_inc = F_nu(nu, beta0, beta, gamma_b)
if cut_type == 'mu':
nu_inc = min(nu_inc, 1 - mu_inc)
elif cut_type == 'nu':
mu_inc = min(mu_inc, 1. - nu_inc)
else:
raise AttributeError
return mu_inc, nu_inc
return inc_single
def clGeneral_single(
mu_type, # 'continuous' or 'spike'
nu_type, # 'continuous' or 'spike'
cut_type, # 'mu' or 'nu'
alpha0, alpha, gamma_a,
beta0, beta, gamma_b):
assert 0.0 <= alpha0 <= alpha <= 1.0
assert 0.0 <= gamma_a <= 1.0
assert 0.0 <= beta0 <= beta <= 1.0
assert 0.0 <= gamma_b <= 1.0
assert mu_type in ['continuous', 'spike'] and nu_type in ['continuous', 'spike']
assert nu_type in ['continuous', 'spike'] and nu_type in ['continuous', 'spike']
assert cut_type in ['mu', 'nu']
F_mu = F_continuous_upper if mu_type == 'continuous' else F_spike_upper
F_nu = F_continuous_lower if nu_type == 'continuous' else F_spike_lower
def cl_single(mu, nu):
mu_inc = F_mu(mu, alpha0, alpha, gamma_a)
nu_inc = F_nu(nu, beta0, beta, gamma_b)
if cut_type == 'mu':
nu_inc = min(nu_inc, 1 - mu_inc)
elif cut_type == 'nu':
mu_inc = min(mu_inc, 1. - nu_inc)
else:
raise AttributeError
return mu_inc, nu_inc
return cl_single
if __name__ == "__main__":
from matplotlib import pyplot as plt
import numpy as np
alpha0, alpha = .3, .8
gamma_a = .3
def plot_spike(alpha0, alpha, gamma_a):
x = np.arange(0.0, 1.0, 0.001)
# y_continuous_lower =[ F_continuous_lower(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
# y_continuous_upper =[ F_continuous_upper(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
y_spike_lower =[ F_spike_lower(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
y_spike_upper =[ F_spike_upper(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
# y_continuous_ =[ 1.0 - F_continuous(1-t,
# alpha0= 1 - alpha,
# alpha= 1 - alpha0,
# gamma_a = 1- gamma_a) for t in x]
# y_spike = [ F_spike(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
# plt.plot(x, y_continuous_lower, color='r', label = 'Spike lower')
# plt.plot(x, y_continuous_upper, color='blue', label = 'Spike upper')
fig, ax = plt.subplots()
ax.plot(x, y_spike_lower, color='r', alpha=0.5, label='Spike lower')
ax.plot([alpha, alpha], [alpha - (1.-gamma_a)*(alpha-alpha0), alpha], '--', color='red',alpha=1.0)
ax.plot(x, y_spike_upper, color='blue',alpha=0.5, label = 'Spike upper')
ax.plot([alpha0, alpha0], [alpha0, alpha0 + gamma_a*(alpha-alpha0)], '--', color='blue',alpha=1.0)
ax.plot([0., alpha], [alpha0 + gamma_a*(alpha-alpha0), alpha0 + gamma_a*(alpha-alpha0)], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([0., alpha0], [alpha0 , alpha0 ], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([0., alpha], [alpha , alpha ], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([alpha0, alpha0], [0.0 , alpha0 ], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([alpha, alpha], [.0 , alpha ], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim([0., 1.])
ax.set_ylim([0., 1.])
ax.set_xticks([0, alpha0, alpha, 1])
ax.set_xticklabels([0,
r'$\alpha_1$',
r'$\alpha_2$' ,
1])
ax.set_yticks([0, alpha0, alpha0 + gamma_a*(alpha-alpha0), alpha, 1])
ax.set_yticklabels([0, r'$\alpha_1$',
r'$\alpha_1 + \gamma.\Delta \alpha$',
r'$\alpha_2$',
1])
ax.legend(loc="upper left")
ax.set_aspect('equal', adjustable='box')
plt.show()
# plt.plot()
def plot_continuous(alpha0, alpha, gamma_a):
x = np.arange(0.0, 1.0, 0.001)
y_continuous_lower =[ F_continuous_lower(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
y_continuous_upper =[ F_continuous_upper(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
# y_spike_lower =[ F_spike_lower(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
# y_spike_upper =[ F_spike_upper(t, alpha0=alpha0, alpha=alpha, gamma_a=gamma_a) for t in x]
# plt.plot(x, y_continuous_lower, color='r', label = 'Spike lower')
# plt.plot(x, y_continuous_upper, color='blue', label = 'Spike upper')
fig, ax = plt.subplots()
ax.plot(x, y_continuous_lower, color='r', alpha=0.5, label='Continuous lower')
# ax.plot([alpha, alpha], [alpha - (1.-gamma_a)*(alpha-alpha0), alpha], '--', color='red',alpha=1.0)
ax.plot(x, y_continuous_upper, color='blue',alpha=0.5, label = 'Continuous upper')
# ax.plot([alpha0, alpha0], [alpha0, alpha0 + gamma_a*(alpha-alpha0)], '--', color='blue',alpha=1.0)
ax.plot([alpha0 + gamma_a*(alpha-alpha0), alpha0 + gamma_a*(alpha-alpha0)],[0., alpha], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([alpha0 , alpha0 ],[0., alpha0], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([alpha , alpha ], [0., alpha], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([0.0 , alpha0 ], [alpha0, alpha0], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.plot([.0 , alpha0 + gamma_a*(alpha-alpha0) ], [alpha, alpha], '--', color='black',
linewidth = 0.5, alpha=0.9 )
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim([0., 1.])
ax.set_ylim([0., 1.])
ax.set_yticks([0, alpha0, alpha, 1])
ax.set_yticklabels([0,
r'$\alpha_1$',
r'$\alpha_2$',
1])
ax.set_xticks([0,
alpha0, alpha0 + gamma_a*(alpha-alpha0), alpha,
1])
ax.set_xticklabels([0,
r'$\alpha_1$',
r'$\alpha_1 + \gamma.\Delta \alpha$',
r'$\alpha_2$',
1])
ax.legend(loc="upper left")
ax.set_aspect('equal', adjustable='box')
plt.show()
# plt.plot()
plot_continuous(alpha0=alpha0,
alpha=alpha,
gamma_a=gamma_a)
plot_spike(alpha0=alpha0,
alpha=alpha,
gamma_a=gamma_a)
# def incGeneral2_single(mu, nu, alpha0, beta0, alpha, beta, gamma_a, gamma_b):
# if