Search code examples
pythonscipyartificial-intelligencefuzzy-logicskfuzzy

Assertion error in fuzzy logic enough rules


I have had use case for a fuzzy logic. I want to recommend a product based on needs. However my logic always errors, even though there should be enough rules.


AssertionError Traceback (most recent call last) File ~/opt/anaconda3/lib/python3.9/site-packages/skfuzzy/control/controlsystem.py:586, in CrispValueCalculator.defuzz(self) 585 try: --> 586 return defuzz(ups_universe, output_mf, 587 self.var.defuzzify_method) 588 except AssertionError:

File ~/opt/anaconda3/lib/python3.9/site-packages/skfuzzy/defuzzify/defuzz.py:248, in defuzz(x, mfx, mode) 247 zero_truth_degree = mfx.sum() == 0 # Approximation of total area --> 248 assert not zero_truth_degree, 'Total area is zero in defuzzification!' 250 if 'centroid' in mode:

AssertionError: Total area is zero in defuzzification!

During handling of the above exception, another exception occurred:


Solution

  • Your program gives an error because it doesn't have a rule for every possible situation. It's like trying to play a board game but you don't have instructions for every possible move.

    To fix it, you could either:

    1. Add more rules: This is like adding more instructions to your game.
    2. Add a default rule.
    3. Change your membership functions: If the criteria are too specific, a rule might never get used.