-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathalphaOps.py
More file actions
138 lines (78 loc) · 2.89 KB
/
alphaOps.py
File metadata and controls
138 lines (78 loc) · 2.89 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
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
import matplotlib.pyplot as plt
import numpy as np
from memfuncs import MemFunc
w = 2
class AlphaOps:
def __init__(self,op):
self.opName = op
self.op = getattr(self,op)
#raise ValueError("Do not have that operator in AlphaOps")
def pos1(self, fNum, alpha):
return ((fNum[1]-fNum[0]) * alpha + fNum[0])
def pos2(self, fNum, alpha):
size = len(fNum)
return (fNum[size - 1] - (fNum[size - 1]-fNum[size - 2]) * alpha)
def add(self,a,b,c,d):
return [a + c, b + d]
def sub(self,a,b,c,d):
return [a - d, b - c]
def max(self,a,b,c,d):
return [max(a,c), max(b,d)]
def min(self,a,b,c,d):
return [min(a,c), min(b,d)]
def mul(self,a,b,c,d):
return [min(a*c,a*d,b*c,b*d), max(a*c,a*d,b*c,b*d)]
def div(self,a,b,c,d):
return self.mul(a,b,1/d,1/c)
#Look into the change here
def comp(self,a,b):
return [1-b, 1-a]
########## Yager Ops ####################
#Beta
def yagerComp(self,a,b):
return [(1-a)**(1/w), (1-b)**(1/w)]
def yagerUnion(self,a,b,c,d):
return [min(1, (a**w + c**w) ** (1/w)),min(1, (b**w + d**w) ** (1/w))]
def yagerIntersect(self,a,b,c,d):
return [1 - min(1,((1 - a)**w + (1 - c)**w)), 1 - min(1,((1 - b)**w + (1 - d)**w))]
def alphaCuts(self, params):
#The levels of alpha cuts to take
alphas = [0,.2,.8,1]
fNum1 = params[0]
points = []
if len(params) == 1:
for alpha in alphas:
a = self.pos1(fNum1,alpha)
b = self.pos2(fNum1,alpha)
points.append(self.op(a,b))
fNum1 = [points[0][0],points[3][0],points[3][1],points[0][1]]
return fNum1
#Use the belive equations to get the alpha intervals from the membership functions
#TRI: [(b-a)alpha + a, c - (c-b)alpha]
#TRAP: [(b-a)alpha + a, d - (d-c)alpha]
for i in range(1,len(params)):
fNum2 = params[i]
for alpha in alphas:
a = self.pos1(fNum1,alpha)
b = self.pos2(fNum1,alpha)
c = self.pos1(fNum2,alpha)
d = self.pos2(fNum2,alpha)
points.append(self.op(a,b,c,d))
#Create a trap membership function, tri is the same but the b and c values are equal
#Comment out for regular fuzzy sets
fNum1 = [points[0][0],points[3][0],points[3][1],points[0][1]]
points = []
return fNum1
# a = AlphaOps("mul").alphaCuts
# A = [.1,.3,.5]
# B = [.3,.5,.7]
# f = a([A,B])
# m1 = MemFunc('tri',A)
# m2 = MemFunc('tri',B)
# f1 = MemFunc('trap',f)
# X = np.arange(0,2,.1)
# print([f1.memFunc(i) for i in X ])
# plt.plot(X,[m1.memFunc(i) for i in X ],c='g')
# plt.plot(X,[m2.memFunc(i) for i in X ],c='b')
# plt.plot(X,[f1.memFunc(i) for i in X ],c='r')
# plt.show()