@@ -422,7 +422,7 @@ def __getitem__(self, key):
422422
423423 def __call__ (self , args : "dict[Domain, float]" , method = "cog" ):
424424 """Calculate the infered value based on different methods.
425- Default is center of gravity.
425+ Default is center of gravity (cog) .
426426 """
427427 assert len (args ) == max (
428428 len (c ) for c in self .conditions .keys ()
@@ -433,11 +433,13 @@ def __call__(self, args: "dict[Domain, float]", method="cog"):
433433 len ({C .domain for C in self .conditions .values ()}) == 1
434434 ), "For CoG, all conditions must have the same target domain."
435435 actual_values = {f : f (args [f .domain ]) for S in self .conditions .keys () for f in S }
436- weights = [
437- (v , x )
438- for K , v in self .conditions .items ()
439- if (x := min (actual_values [k ] for k in K if k in actual_values )) > 0
440- ]
436+
437+ weights = []
438+ for K , v in self .conditions .items ():
439+ x = min (actual_values [k ] for k in K if k in actual_values )
440+ if x > 0 :
441+ weights .append ((v , x ))
442+
441443 if not weights :
442444 return None
443445 target_domain = list (self .conditions .values ())[0 ].domain
@@ -447,7 +449,7 @@ def __call__(self, args: "dict[Domain, float]", method="cog"):
447449 ) * index + target_domain ._low
448450
449451
450- def rule_from_table (table : str , references :dict ):
452+ def rule_from_table (table : str , references : dict ):
451453 """Turn a (2D) string table into a Rule of fuzzy sets.
452454
453455 ATTENTION: This will eval() all strings in the table.
@@ -466,10 +468,13 @@ def rule_from_table(table: str, references:dict):
466468 df = pd .read_table (io .StringIO (table ))
467469 D = {}
468470 for x , y in product (range (len (df .index )), range (len (df .columns ))):
469- D [(eval (df .index [x ].strip (), references ), eval (df .columns [y ].strip (), references ))] = eval (df .iloc [x , y ], references )
471+ D [(eval (df .index [x ].strip (), references ), eval (df .columns [y ].strip (), references ))] = eval (
472+ df .iloc [x , y ], references
473+ )
470474 return Rule (D )
471475
472476
473477if __name__ == "__main__" :
474478 import doctest
479+
475480 doctest .testmod ()
0 commit comments