-
Notifications
You must be signed in to change notification settings - Fork 0
/
Estimate_FCM.py
38 lines (32 loc) · 1.2 KB
/
Estimate_FCM.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
import numpy as np
import membership_function as mf
import Bayesian_optimization as bo
def cal_estimate_FCM(candidate_FCM):
numFCM = candidate_FCM.shape[0]
numRow = candidate_FCM.shape[1]
numCol = candidate_FCM.shape[2]
E = np.zeros(shape=(3, numRow, numCol))
E_Res = np.zeros(shape=(3, numRow, numCol))
tmp = np.zeros(shape=(3))
for n in range(numFCM): # The number of candidate FCMs
for i in range(numRow):
for j in range(numCol):
# spare
if np.abs(candidate_FCM[n, i, j]) < 0.05:
candidate_FCM[n, i, j] = 0
tmp = mf.Memebership(candidate_FCM[n, i, j])
E[:, i, j] = E[:, i, j] + tmp # Cumulative membership
N = E[0] + E[1] + E[2]
E_Res[0] = E[0]
E_Res[1] = E[1]
E_Res[2] = E[2]
#Bayesian optimization
a, r, Q, itr = bo.bayesian_optimization(N, E_Res)
estimate_FCM = np.zeros(shape=(numRow, numCol))
for i in range(numRow):
for j in range(numCol):
if Q[2, i, j] > 0.5:
estimate_FCM[i, j] = 1 # Q[2] postive
if Q[0, i, j] > 0.5:
estimate_FCM[i, j] = -1 # Q[0] negative
return estimate_FCM, Q