Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import ipdb; # ipdb.set_trace()
- import numpy as np
- import skfuzzy as fuzz
- from skfuzzy import control as ctrl
- import matplotlib.pyplot as plt
- # example from https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html
- # New Antecedent/Consequent objects hold universe variables and membership
- # functions
- 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')
- # Auto-membership function population is possible with .automf(3, 5, or 7)
- quality.automf(3)
- service.automf(3)
- # Custom membership functions can be built interactively with a familiar,
- # Pythonic API
- 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])
- quality['average'].view()
- #ipdb.set_trace()
- quality['good'].view()
- #ipdb.set_trace()
- #fig, ax = tip.view()
- #ipdb.set_trace()
- #ipdb.set_trace()
- 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'])
- #fig, ax = rule1.view()
- #fig.show()
- #ipdb.set_trace()
- # Control System Creation and Simulation
- 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'] = 5
- tipping.input['service'] = 4
- # Crunch the numbers
- tipping.compute()
- print(tipping.output['tip'])
- tip.view(sim=tipping)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement