@@ -48,12 +48,9 @@ def test_instantiate_antecedent():
48
48
# Assure expected behavior
49
49
tst .assert_equal (universe , ant .universe )
50
50
assert ant .label == label
51
- assert ant .active is None
52
51
assert ant .input is None
53
52
assert ant ._id == id (ant )
54
- assert_empty_ordereddict (ant .output )
55
- assert_empty_ordereddict (ant .mf )
56
- assert_empty_ordereddict (ant .connections )
53
+ assert_empty_ordereddict (ant .terms )
57
54
assert ant .__name__ == 'Antecedent'
58
55
assert ant .__repr__ () == 'Antecedent: {0}' .format (label )
59
56
@@ -67,13 +64,8 @@ def test_instantiate_consequent():
67
64
# Assure expected behavior
68
65
tst .assert_equal (universe , con .universe )
69
66
assert con .label == label
70
- assert con .active is None
71
67
assert con ._id == id (con )
72
- assert con .output is None
73
- assert_empty_ordereddict (con .mf )
74
- assert_empty_ordereddict (con .connections )
75
- assert_empty_ordereddict (con .cuts )
76
- assert_empty_ordereddict (con .cut_mfs )
68
+ assert_empty_ordereddict (con .terms )
77
69
assert con .__name__ == 'Consequent'
78
70
assert con .__repr__ () == 'Consequent: {0}' .format (label )
79
71
@@ -91,37 +83,37 @@ def test_automf3():
91
83
92
84
# Test Antecedent
93
85
ant .automf (3 )
94
- assert list (ant .mf .keys ()) == label3
95
- for arr0 , arr1 in zip (ant .mf .values (), mfs3 ):
96
- tst .assert_allclose (arr0 , arr1 )
86
+ assert list (ant .terms .keys ()) == label3
87
+ for arr0 , arr1 in zip (ant .terms .values (), mfs3 ):
88
+ tst .assert_allclose (arr0 . mf , arr1 )
97
89
98
90
ant .automf (3 , variable_type = 'quant' )
99
- assert list (ant .mf .keys ()) == alt_label3
91
+ assert list (ant .terms .keys ()) == alt_label3
100
92
101
93
ant .automf (3 , invert = True )
102
- assert list (ant .mf .keys ()) == label3 [::- 1 ]
94
+ assert list (ant .terms .keys ()) == label3 [::- 1 ]
103
95
104
96
ant .automf (3 , variable_type = 'quant' , invert = True )
105
- assert list (ant .mf .keys ()) == alt_label3 [::- 1 ]
97
+ assert list (ant .terms .keys ()) == alt_label3 [::- 1 ]
106
98
107
99
# Test Consequent
108
100
mfs3b = [np .r_ [1. , 7 / 9. , 5 / 9. , 3 / 9. , 1 / 9. , 0. , 0. , 0. , 0. , 0. ],
109
101
np .r_ [0. , 2 / 9. , 4 / 9. , 6 / 9. , 8 / 9. , 8 / 9. , 6 / 9. , 4 / 9. , 2 / 9. , 0. ],
110
102
np .r_ [0. , 0. , 0. , 0. , 0. , 1 / 9. , 3 / 9. , 5 / 9. , 7 / 9. , 1. ]]
111
103
112
104
con .automf (3 )
113
- assert list (con .mf .keys ()) == label3
114
- for arr0 , arr1 in zip (con .mf .values (), mfs3b ):
115
- tst .assert_allclose (arr0 , arr1 )
105
+ assert list (con .terms .keys ()) == label3
106
+ for arr0 , arr1 in zip (con .terms .values (), mfs3b ):
107
+ tst .assert_allclose (arr0 . mf , arr1 )
116
108
117
109
con .automf (3 , variable_type = 'quant' )
118
- assert list (con .mf .keys ()) == alt_label3
110
+ assert list (con .terms .keys ()) == alt_label3
119
111
120
112
con .automf (3 , invert = True )
121
- assert list (con .mf .keys ()) == label3 [::- 1 ]
113
+ assert list (con .terms .keys ()) == label3 [::- 1 ]
122
114
123
115
con .automf (3 , variable_type = 'quant' , invert = True )
124
- assert list (con .mf .keys ()) == alt_label3 [::- 1 ]
116
+ assert list (con .terms .keys ()) == alt_label3 [::- 1 ]
125
117
126
118
127
119
@nose .with_setup (setup )
@@ -139,18 +131,18 @@ def test_automf5():
139
131
140
132
# Test Antecedent
141
133
ant .automf (5 )
142
- assert list (ant .mf .keys ()) == label5
143
- for arr0 , arr1 in zip (ant .mf .values (), mfs5 ):
144
- tst .assert_allclose (arr0 , arr1 )
134
+ assert list (ant .terms .keys ()) == label5
135
+ for arr0 , arr1 in zip (ant .terms .values (), mfs5 ):
136
+ tst .assert_allclose (arr0 . mf , arr1 )
145
137
146
138
ant .automf (5 , variable_type = 'quant' )
147
- assert list (ant .mf .keys ()) == alt_label5
139
+ assert list (ant .terms .keys ()) == alt_label5
148
140
149
141
ant .automf (5 , invert = True )
150
- assert list (ant .mf .keys ()) == label5 [::- 1 ]
142
+ assert list (ant .terms .keys ()) == label5 [::- 1 ]
151
143
152
144
ant .automf (5 , variable_type = 'quant' , invert = True )
153
- assert list (ant .mf .keys ()) == alt_label5 [::- 1 ]
145
+ assert list (ant .terms .keys ()) == alt_label5 [::- 1 ]
154
146
155
147
# Test Consequent
156
148
mfs5b = [np .r_ [1. , 5 / 9. , 1 / 9. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
@@ -160,18 +152,18 @@ def test_automf5():
160
152
np .r_ [0. , 0. , 0. , 0. , 0. , 0. , 0. , 1 / 9. , 5 / 9. , 1. ]]
161
153
162
154
con .automf (5 )
163
- assert list (con .mf .keys ()) == label5
164
- for arr0 , arr1 in zip (con .mf .values (), mfs5b ):
165
- tst .assert_allclose (arr0 , arr1 )
155
+ assert list (con .terms .keys ()) == label5
156
+ for arr0 , arr1 in zip (con .terms .values (), mfs5b ):
157
+ tst .assert_allclose (arr0 . mf , arr1 )
166
158
167
159
con .automf (5 , variable_type = 'quant' )
168
- assert list (con .mf .keys ()) == alt_label5
160
+ assert list (con .terms .keys ()) == alt_label5
169
161
170
162
con .automf (5 , invert = True )
171
- assert list (con .mf .keys ()) == label5 [::- 1 ]
163
+ assert list (con .terms .keys ()) == label5 [::- 1 ]
172
164
173
165
con .automf (5 , variable_type = 'quant' , invert = True )
174
- assert list (con .mf .keys ()) == alt_label5 [::- 1 ]
166
+ assert list (con .terms .keys ()) == alt_label5 [::- 1 ]
175
167
176
168
177
169
@nose .with_setup (setup )
@@ -193,18 +185,18 @@ def test_automf7():
193
185
194
186
# Test Antecedent
195
187
ant .automf (7 )
196
- assert list (ant .mf .keys ()) == label7
197
- for arr0 , arr1 in zip (ant .mf .values (), mfs7 ):
198
- tst .assert_allclose (arr0 , arr1 )
188
+ assert list (ant .terms .keys ()) == label7
189
+ for arr0 , arr1 in zip (ant .terms .values (), mfs7 ):
190
+ tst .assert_allclose (arr0 . mf , arr1 )
199
191
200
192
ant .automf (7 , variable_type = 'quant' )
201
- assert list (ant .mf .keys ()) == alt_label7
193
+ assert list (ant .terms .keys ()) == alt_label7
202
194
203
195
ant .automf (7 , invert = True )
204
- assert list (ant .mf .keys ()) == label7 [::- 1 ]
196
+ assert list (ant .terms .keys ()) == label7 [::- 1 ]
205
197
206
198
ant .automf (7 , variable_type = 'quant' , invert = True )
207
- assert list (ant .mf .keys ()) == alt_label7 [::- 1 ]
199
+ assert list (ant .terms .keys ()) == alt_label7 [::- 1 ]
208
200
209
201
# Test Consequent
210
202
mfs7b = [np .r_ [1. , 3 / 9. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
@@ -216,18 +208,18 @@ def test_automf7():
216
208
np .r_ [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 3 / 9. , 1. ]]
217
209
218
210
con .automf (7 )
219
- assert list (con .mf .keys ()) == label7
220
- for arr0 , arr1 in zip (con .mf .values (), mfs7b ):
221
- tst .assert_allclose (arr0 , arr1 )
211
+ assert list (con .terms .keys ()) == label7
212
+ for arr0 , arr1 in zip (con .terms .values (), mfs7b ):
213
+ tst .assert_allclose (arr0 . mf , arr1 )
222
214
223
215
con .automf (7 , variable_type = 'quant' )
224
- assert list (con .mf .keys ()) == alt_label7
216
+ assert list (con .terms .keys ()) == alt_label7
225
217
226
218
con .automf (7 , invert = True )
227
- assert list (con .mf .keys ()) == label7 [::- 1 ]
219
+ assert list (con .terms .keys ()) == label7 [::- 1 ]
228
220
229
221
con .automf (7 , variable_type = 'quant' , invert = True )
230
- assert list (con .mf .keys ()) == alt_label7 [::- 1 ]
222
+ assert list (con .terms .keys ()) == alt_label7 [::- 1 ]
231
223
232
224
233
225
@nose .with_setup (setup )
@@ -241,24 +233,6 @@ def test_automf_bad():
241
233
tst .assert_raises (ValueError , con .automf , 13 )
242
234
243
235
244
- def test_set_active ():
245
- universe = np .linspace (0 , 5 , 7 )
246
- ant_label = 'service'
247
- con_label = 'TIP'
248
-
249
- ant = Antecedent (universe , ant_label )
250
- con = Consequent (universe , con_label )
251
-
252
- ant .automf (5 )
253
- for label in list (ant .mf .keys ()):
254
- ant [label ]
255
- assert ant .active == label
256
-
257
- con .automf (7 )
258
- for label in list (con .mf .keys ()):
259
- con [label ]
260
- assert con .active == label
261
-
262
236
263
237
@nose .with_setup (setup )
264
238
def test_bad_set_active ():
@@ -286,18 +260,18 @@ def test_add_mf():
286
260
ant ['high' ] = mf1
287
261
288
262
# Ensure they were added correctly
289
- assert list (ant .mf .keys ()) == ['wavy' , 'high' ]
290
- tst .assert_equal (ant .mf ['wavy' ], mf0 )
291
- tst .assert_equal (ant .mf ['high' ], mf1 )
263
+ assert list (ant .terms .keys ()) == ['wavy' , 'high' ]
264
+ tst .assert_equal (ant .terms ['wavy' ]. mf , mf0 )
265
+ tst .assert_equal (ant .terms ['high' ]. mf , mf1 )
292
266
293
267
# Assign mfs to Consequent
294
268
con ['wavy' ] = mf0
295
269
con ['high' ] = mf1
296
270
297
271
# Ensure they were added correctly
298
- assert list (con .mf .keys ()) == ['wavy' , 'high' ]
299
- tst .assert_equal (con .mf ['wavy' ], mf0 )
300
- tst .assert_equal (con .mf ['high' ], mf1 )
272
+ assert list (con .terms .keys ()) == ['wavy' , 'high' ]
273
+ tst .assert_equal (con .terms ['wavy' ]. mf , mf0 )
274
+ tst .assert_equal (con .terms ['high' ]. mf , mf1 )
301
275
302
276
303
277
@nose .with_setup (setup )
@@ -309,29 +283,25 @@ def test_set_patch():
309
283
310
284
# Setting a patch
311
285
con .set_patch ('average' , 0.4 )
312
- assert con .cuts ['average' ] == 0.4
313
286
314
287
# Overriding it with a higher patch
315
288
con .set_patch ('average' , 0.55 )
316
- assert con .cuts ['average' ] == 0.55
317
289
318
290
# Setting the other patches
319
291
con .set_patch ('good' , 0.3 )
320
292
con .set_patch ('poor' , 0.88 )
321
- assert con .cuts ['good' ] == 0.3
322
- assert con .cuts ['poor' ] == 0.88
323
293
324
- con .compute ()
325
294
tst .assert_allclose (con .output , 3.6644951140065136 )
326
295
327
296
328
297
@nose .with_setup (setup )
329
298
def test_set_input ():
330
299
global ant
331
300
ant .automf (3 )
332
- ant .set_input ( 2.3 )
301
+ ant .input = 2.3
333
302
334
- assert ant .input == 2.3
303
+ assert ant .input == 2.3 , "Value is %s" % ant .input
304
+ assert ant .crisp_value == 2.3 , "Value is %s" % ant .crisp_value
335
305
336
306
337
307
@nose .with_setup (setup )
@@ -350,8 +320,10 @@ def test_add_bad_mf():
350
320
def test_cannot_compute ():
351
321
global ant
352
322
global con
353
- tst .assert_raises (ValueError , ant .compute )
354
- tst .assert_raises (ValueError , con .compute )
323
+ with tst .assert_raises (ValueError ):
324
+ ant .crisp_value
325
+ with tst .assert_raises (ValueError ):
326
+ con .crisp_value
355
327
356
328
357
329
if __name__ == '__main__' :
0 commit comments