-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfuzzyRunner.py
140 lines (91 loc) · 3.24 KB
/
fuzzyRunner.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
from tree import DecisionTree
import numpy as np
import matplotlib.pyplot as plt
from memfuncs import MemFunc
from file import File
inputs2 = [
[25.0, 82.0, 24.0, 9233.0, 0.0, 102.0],
[33.0, 86.0, 27.0, 7895.0, 0.0, 106.0],
[34.0, 85.0, 27.0, 8495.0, 2.0, 94.0],
[32.0, 94.0, 26.0, 9960.0, 0.0, 102.0],
[28.0, 121.0, 21.0, 21105.0, 0.0, 188.0],
]
#Trash
#[37, 82, 32, 7126, 0, 102],
#[34.0, 76.0, 30.0, 7129.0, 1.0, 101.0],
#[37.0, 69.0, 31.0, 6849.0, 1.0, 122.0],
#[28.0, 114.0, 24.0, 16515.0, -1.0, 74.0],
#[32.0, 84.0, 26.0, 11245.0, 0.0, 115.0],
#[30.0, 88.0, 24.0, 8921.0, -1.0, 74.0],
#.1
# [32.0, 100.0, 26.0, 9995.0, 2.0, 94.0]
# [33.0, 82.0, 28.0, 7775.0, 0.0, 102.0]
# [32.0, 84.0, 26.0, 8495.0, 0.0, 115.0]
#.2
# [32.0, 84.0, 26.0, 11245.0, 0.0, 115.0]
# [33.0, 86.0, 27.0, 7895.0, 0.0, 106.0]
# [25.0, 82.0, 24.0, 9233.0, 0.0, 102.0]
#5,7
Car_ID = 0
Risk = 1
Value_Loss = 2
Horsepower = 3
City_MPG = 4
Highway_MPG = 5
Price = 6
#Used to name files for printing out the graphs
testA = "alpha"
testE = "extend"
testN = "ZadehBaseTree"
wValue = "-w2"
#convert the data to the correct order for the base tree
def convertCarData(data):
return [data[Highway_MPG],data[Horsepower],data[City_MPG],data[Price],data[Risk],data[Value_Loss]]
#conver the data to the correct oder for the newly generated tree
def convertCarData2(data):
return [data[City_MPG],data[Highway_MPG],data[Price],data[Value_Loss],data[Horsepower],data[Risk]]
#prints the order of the inputs stored in the tree
def printInputs():
dTree = DecisionTree('jsonTrees/' + testName + '.json')
dTree.printInputs()
def main():
fmemFile = File("fmemFile.csv")
#import the data from a csv
car_data = np.genfromtxt('car_data.csv', delimiter=',')
#call the tree creator module and pass the name of the json file to it
aTree = DecisionTree('jsonTrees/' + testA + '.json')
nTree = DecisionTree('jsonTrees/' + testN + '.json')
eTree = DecisionTree('jsonTrees/' + testE + '.json')
#iterator = car_data[np.random.randint(car_data.shape[0], size=100), :]
#iterator = car_data
iterator = inputs2
for inputs in iterator:
#change the inputs for each of the cars in the tree
#inputs = convertCarData(inputs)
aTree.changeInputs(inputs)
nTree.changeInputs(inputs)
eTree.changeInputs(inputs)
#get the score for that car
aScore = aTree.run()
nScore = nTree.run()
eScore = eTree.run()
print("Inputs:",inputs)
print("ASCORE #######:",aScore)
print("NSCORE #######:",nScore)
print("ESCORE #######:",eScore)
eScore = np.array(eScore)
f1 = MemFunc('trap',aScore)
X = np.arange(0,1,.05)
l1, = plt.plot(X,[f1.memFunc(i) for i in X],c='r',linewidth=2.0,label="AlphaCuts")
l2, = plt.plot(eScore[:,0],eScore[:,1],c='b',linewidth=2.0,label="Extention Principle")
l3 = plt.axvline(nScore,c='g',linewidth=2.0,label="Crisp")
plt.legend(handles=[l1,l2,l3])
plt.title("Regular Title")
plt.xlabel("Output Score")
plt.ylabel("Membership Value")
#Batch Save Rember to remove input
#plt.savefig("test.png")
plt.show()
break
if __name__ == '__main__':
main()