import numpy as np import skfuzzy as fuzz import matplotlib.pyplot as plt #from mpl_toolkit.mplot3d import Axes3D from skfuzzy import control as ctrl import math x_qual = np.arange(0,11,1) x_serv = np.arange(0,11,1) x_tip = np.arange(0,26,1) quality = ctrl.Antecedent(x_qual,'quality') service = ctrl.Antecedent(x_serv,'service') tip = ctrl.Consequent(x_tip,'tip') quality['L']=fuzz.trimf(x_qual,[0,0,5]) quality['M']=fuzz.trimf(x_qual,[0,5,10]) quality['H']=fuzz.trimf(x_qual,[5,10,10]) service['L']=fuzz.trimf(x_serv,[0,0,5]) service['M']=fuzz.trimf(x_serv,[0,5,10]) service['H']=fuzz.trimf(x_serv,[5,10,10]) tip['L']=fuzz.trimf(x_tip,[0,0,13]) tip['M']=fuzz.trimf(x_tip,[0,13,25]) tip['H']=fuzz.trimf(x_tip,[13,25,25]) quality.view() service.view() tip.view() tip.defuzzify_method='centroid' rule1=ctrl.Rule(antecedent=((quality['L']&service['L'])|(quality['L']&service['M'])|(quality['M']&service['L'])),consequent=tip['L'],label='Low') rule2=ctrl.Rule(antecedent=((quality['M']&service['M'])|(quality['L']&service['H'])|(quality['H']&service['L'])),consequent=tip['M'],label='Medium') rule3=ctrl.Rule(antecedent=((quality['M']&service['H'])|(quality['H']&service['M'])|(quality['H']&service['H'])),consequent=tip['H'],label='High') #rule2.view() tipping_ctrl = ctrl.ControlSystem([rule1,rule2,rule3]) tipping = ctrl.ControlSystemSimulation(tipping_ctrl) tipping.input['quality']=2 tipping.input['service']=2 tipping.compute() p=tipping.output['tip'] tip.view(sim=tipping) print(p) #upsampled = np.linspace(0,11,21) #x,y=np.meshgrid(upsampled,upsampled) #z=np.zeros_like(x) #pp=[] #for i in range(0,21): # for j in range(0,21): # tipping.input['quality']=x[i,j] # tipping.input['service']=y[i,j] # tipping.compute() # z[i,j]=tipping.output['tip'] # pp.append(z[i,j]) #print('max:',max(pp)) #print('min:',min(pp)) #fig = plt.figure(figsize=(8,8)) #ax = fig.add_subplot(111,projection='3d') #surf = ax.plot_surface(x,y,z,rstride=1,cstride=1,cmap='viridis',linewidth=0.4,antialiased=True) #ax.view_init(30,200) plt.show()