1

I've been recently learning python through a course. Everything works smoothly except when I use view method. Anybody having this problem as well?

I even used a sample code in https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html#example-plot-tipping-problem-newapi-py. (link updated)

import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl

quality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')
service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')
tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')

quality.automf(3)
service.automf(3)

tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])
tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])
tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])

# HERE COMES MY PROBLEM
quality['average'].view()

Whenever I get to view query part, all I get is a little square box that should show me the graph but it just keeps on loading. Any advice is greatly appreciated. Thank you!

hw2python
  • 11
  • 3
  • This is a specific problem with the `skfuzzy` module. `view` here is a `networkX` `fig.show()`, This has nothing to do with `numpy` array `view`. – hpaulj Feb 15 '19 at 05:52
  • The link to sample code is broken. Please provide a valid URL – programmer Feb 15 '19 at 05:57
  • @hpaulj I've checked my installation of skfuzzy but it is the most current version already. Noted that this isn't related with numpy. – hw2python Feb 15 '19 at 06:53
  • @programmer I've updated the link, thanks for the info! Please do note that I also did this with an entirely different code (with view method as well) and still gotten the same result. – hw2python Feb 15 '19 at 06:57

2 Answers2

1

This is the complete example running:

import matplotlib.pyplot as plt
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl

quality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')
service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')
tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')

quality.automf(3)
service.automf(3)

tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])
tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])
tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])

Here is my problem

quality['average'].view()


service.view()

tip.view()

rule1 = ctrl.Rule(quality['poor'] | service['poor'], tip['low'])
rule2 = ctrl.Rule(service['average'], tip['medium'])
rule3 = ctrl.Rule(service['good'] | quality['good'], tip['high'])

rule1.view()

tipping_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])

tipping = ctrl.ControlSystemSimulation(tipping_ctrl)

Pass inputs to the ControlSystem using Antecedent labels with Pythonic API

# Note: if you like passing many inputs all at once, use .inputs(dict_of_data)
tipping.input['quality'] = 6.5
tipping.input['service'] = 9.8

# Crunch the numbers
tipping.compute()
print (tip)
tip.view(sim=tipping)

plt.show()
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
user3642831
  • 311
  • 3
  • 3
0

Since skfuzzy uses matplotlib and NetworkX underhood, you can try this code to show your figure:

import matplotlib.pyplot as plt
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl

quality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')
service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')
tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')

quality.automf(3)
service.automf(3)

tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])
tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])
tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])

# HERE COMES MY PROBLEM
quality['average'].view()

plt.show()
shahriar
  • 362
  • 4
  • 17