1

I'm developing a fuzzy system for predicting the increase in price of flight according to the distance of journey and number of active users. Such that, more the number of users higher would be the price.

For that I've defined the Antecents (Inputs) & Consequent (Outputs) :

distance = ctrl.Antecedent(np.arange(1, 20000, 1), 'distance')
users = ctrl.Antecedent(np.arange(0, 50, 1), 'users')
price = ctrl.Consequent(np.arange(0, 10000, 1), 'price')

I can auto-generate membership functions by :

distance.automf(3)
users.automf(3)
price.automf(5)

But, I would like to make custom membership functions like this :

distance['low'] = fuzz.trimf(distance.universe, [50, 1000, 2000])
distance['medium'] = fuzz.trimf(distance.universe, [2000, 3000, 5000])
distance['high'] = fuzz.trimf(distance.universe, [5000, 10000, 20000])

And similarly for others as well.

But on computing, I'm getting :

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.

I suppose, this error is due to my wrong choice of values in my custom membership functions.

Due to lack of sufficient examples in official documentation, I am not able find the root cause or to understand the proper methodology of choice of x,y,z values in the membership functions.

where, x, y, z are :

distance['low'] = fuzz.trimf(distance.universe, [x, y, z])
.
.
users['low'] = fuzz.trimf(users.universe, [x, y, z])
. 
.

What am I missing here ?

petezurich
  • 9,280
  • 9
  • 43
  • 57
Rohit Lal
  • 2,791
  • 1
  • 20
  • 36

2 Answers2

0

You defined distance using np.arange(1, 20000, 1) but you created the fuzzified distance starting from 50 in distance['low'] = fuzz.trimf(distance.universe, [50, 1000, 2000]). So i believe you can solve the error by simply doing this:

distance['low'] = fuzz.trimf(distance.universe, [1, 1000, 2000])
shahriar
  • 362
  • 4
  • 17
  • 1
    Yes, I did tried that out, but still struggling with the choice of x, y, z values. Any recommendation of documentation on that ? – Rohit Lal Jun 16 '19 at 05:37
  • 1
    https://loctv.wordpress.com/2016/10/02/using-scikit-fuzzy-to-build-an-obesity-diagnosis-system/ – shahriar Jun 16 '19 at 12:30
0

You have to do just two things to fix the error because I have experienced it personally and fixed it. Unfortunately, I cannot share my code yet as it is still under consideration for my Ph.D. and had to be protected first. Nevertheless, I will tell you what to do which if you do it well, your problem will be solved.

The first step is to correct antecedents for distance to cover from 1 to 2000 as follows:

distance = ctrl.Antecedent(np.arange(0, 20001, 1), 'distance')

And make this adjustment too to start from 1.

distance['low'] = fuzz.trimf(distance.universe, [1, 1000, 2000])

The last step is to look at your fuzzy rules. You did not share them so I do not know what is covered and what is not, but you need to write rules that cover all possible outputs or antecedents. For instance, What do you want the system to do when both conditions (inputs) are extreme highs, lows, or directly opposite like low distance and high users or the other way round? Just ensure all the possible outcomes are covered.

Finally, as I understand from using the package, the inputs seem to be vectorized and so opposite extreme inputs such as one being low and the other being high, the rules must cover for both directions. If this is not the case, the additional rules will not still harm your final result. I'm happy to discuss if the error is not resolved by this answer.