-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoperators.py
More file actions
68 lines (42 loc) · 1.74 KB
/
operators.py
File metadata and controls
68 lines (42 loc) · 1.74 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
from alphaOps import AlphaOps
from extention import ExtentionOps
#Gloabal w value, bad practice but this easy for now
w = 2
class Ops():
"""Used the generate the correct fuzzy set operation for each node"""
def printStuff(self):
print(dir(self))
def getFunc(self,operator):
ops = operator.split(":")
if ops[0] == "alpha":
return AlphaOps(ops[1]).alphaCuts
elif ops[0] == "extend":
return ExtentionOps(ops[1]).func
else:
return getattr(self,ops[0])
#Zadeh Operators#########################
def compliment(self, x):
return 1 - x[0]
def intersect(self, params):
return min(*params)
def union(self, params):
return max(*params)
#boudned sum operations##################
def bunion(self,params):
return min(1,sum(params))
def bintersect(self,params):
return max(0,(sum(params) - 1))
#Yager Operations##########################
def ycompliment(self,x):
return (1 - x[0]**w)**(1/w)
def yunion(self,params):
if(len(params) < 2):
raise Exception("Must provide at lease two params to perform an union")
# Takes the list of params, maps them to the lambda function thaat
# will take x to the power of w
return (min(1,(sum(list(map(lambda x : x ** w,params))))**(1/w)))
def yintersect(self,params):
if(len(params) < 2):
raise Exception("Must provide at lease two params to perform an intersection")
# does the same mapping as above but subtracts one before the mapping
return (min(1,(sum(list(map(lambda x : (1-x) ** w,params))))**(1/w)))