Error in Fuzzy control system

1,834 views
Skip to first unread message

Nikhil Rao

unread,
Jun 16, 2016, 4:11:32 AM6/16/16
to scikit-fuzzy
When i tried to simulate two inputs
input range (-12,12,1) for both the inputs 
output range (-24,24,1)

input crisp values 

input1=-10
input2=0

The following error was obtained

Traceback (most recent call last):
  File "FBB.py", line 44, in <module>
    tipping.compute()
  File "/usr/local/lib/python2.7/dist-packages/scikit_fuzzy-0.2.dev0-py2.7.egg/skfuzzy/control/controlsystem.py", line 296, in compute
    CrispValueCalculator(consequent, self).defuzz()
  File "/usr/local/lib/python2.7/dist-packages/scikit_fuzzy-0.2.dev0-py2.7.egg/skfuzzy/control/controlsystem.py", line 445, in defuzz
    raise ValueError("Crisp output cannot be calculated, likely "
ValueError: Crisp output cannot be calculated, likely because the system is too sparse. Check to make sure this set of input values will activate at least one connected Term in each Antecedent via the current set of Rules.


JDWarner

unread,
Jun 16, 2016, 10:24:52 AM6/16/16
to scikit-fuzzy
This message appears when your Rules are not sufficient, and a given set of inputs misses all defined Rules. 

These has been some discussion about the possibility of a default firing in such a case, but I'm uncomfortable making assumptions.

Put simply, you need to make sure that your Rules connect Antecedent Terms such that any combination of inputs will fire at least one Rule. If this doesn't happen, the system can't execute because it doesn't have the information needed to proceed. We catch this and tell you with an information message - that's what the exception is saying. Recheck and/or add more Rules.

JDWarner

unread,
Jun 16, 2016, 2:51:00 PM6/16/16
to scikit-fuzzy
Example script sent to me directly via email:

``` python
import numpy as np
import skfuzzy.control as ctrl
import skfuzzy as fuzz
import commands

error = ctrl.Antecedent(np.arange(-12,12, 0.01), 'error')
derivative = ctrl.Antecedent(np.arange(-12, 12, 0.01), 'derivative')
output = ctrl.Consequent(np.arange(-24, 24, 0.01), 'output')

error['N']=fuzz.trimf(error.universe,[-12,-12,0])
error['P']=fuzz.trimf(error.universe,[0,12,12])
error['Z']=fuzz.trimf(error.universe,[-10,0,10])

derivative['N']=fuzz.trimf(derivative.universe,[-12,-12,0])
derivative['P']=fuzz.trimf(derivative.universe,[0,12,12])
derivative['Z']=fuzz.trimf(derivative.universe,[-10,0,10])

output['N']=fuzz.trimf(output.universe, [-24,-12, 0])
output['P']=fuzz.trimf(output.universe, [0,12,24])
output['Z']=fuzz.trimf(output.universe, [-10,0,10])



rule1 = ctrl.Rule(error['N'] & derivative['N'],output['N'] )
rule2 = ctrl.Rule(error['N'] & derivative['Z'],output['N'] )
rule3 = ctrl.Rule(error['N'] & derivative['P'],output['Z'] )
rule4 = ctrl.Rule(error['P'] & derivative['N'],output['Z'] )
rule5 = ctrl.Rule(error['P'] & derivative['P'],output['P'])
rule6 = ctrl.Rule(error['P'] & derivative['Z'],output['P'])
rule7 = ctrl.Rule(error['Z'] & derivative['N'],output['N'])
rule8 = ctrl.Rule(error['Z'] & derivative['P'],output['P'])
rule9 = ctrl.Rule(error['Z'] & derivative['Z'],output['Z'])

output_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9])
outputs = ctrl.ControlSystemSimulation(output_ctrl)
```

Two problems are apparent: 
  • The new API has a bug where multiple Rules converging on a single Consequent Term overwrite each other instead of combining. An Issue is raised on GitHub (https://github.com/scikit-fuzzy/scikit-fuzzy/issues/108) and a fix is pending.
  • Your Antecedent Terms called 'Z' should be extended to cover the full range of [-12, 12] instead of [-10, 10]. 
With the 'Z' range extended, this should run without problems after the fix for Issue #108 is merged.

JDWarner

unread,
Jun 18, 2016, 11:30:17 PM6/18/16
to scikit-fuzzy
This was fixed by PR #109 on GitHub, confirmed resolved with regression tests added, prior to 0.2 release.


On Thursday, June 16, 2016 at 3:11:32 AM UTC-5, Nikhil Rao wrote:
Reply all
Reply to author
Forward
0 new messages