def membership_f(mf, x, abcd): """ Returns y values corresponding to type of type of Membership fn. arguments: mf - string containing type of Membership function x - x axis values """ if mf == "zmf": return fuzz.zmf(x, abcd[0], abcd[1]) # zmf(x, a, b) elif mf == "trimf": return fuzz.trimf(x, abcd[0:3]) # trimf(x, abc) elif mf == "dsigmf": return fuzz.dsigmf(x, abcd[0], abcd[1], abcd[2], abcd[3]) # dsigmf(x, b1, c1, b2, c2) elif mf == "gauss2mf": return fuzz.gauss2mf(x, abcd[0], abcd[1], abcd[2], abcd[3]) # gauss2mf(x, mean1, sigma1, mean2, sigma2) elif mf == "gaussmf": return fuzz.gaussmf(x, abcd[0], abcd[1]) # gaussmf(x, mean, sigma) elif mf == "gbellmf": return fuzz.gbellmf(x, abcd[0], abcd[1], abcd[2]) # gbellmf(x, a, b, c) elif mf == "piecemf": return fuzz.piecemf(x, abcd[0:3]) # piecemf(x, abc) elif mf == "pimf": return fuzz.pimf(x, abcd[0], abcd[1], abcd[2], abcd[3]) # pimf(x, a, b, c, d) elif mf == "psigmf": return fuzz.psigmf(x, abcd[0], abcd[1], abcd[2], abcd[3]) # psigmf(x, b1, c1, b2, c2) elif mf == "sigmf": return fuzz.sigmf(x, abcd[0], abcd[1]) # sigmf(x, b, c) elif mf == "smf": return fuzz.smf(x, abcd[0], abcd[1]) # smf(x, a, b) elif mf == "trapmf": return fuzz.trapmf(x, abcd) # trapmf(x, abcd)
def membership_f(mf, x, abcd): """ Returns y values corresponding to type of type of Membership fn. arguments: mf - string containing type of Membership function x - x axis values """ if mf == 'zmf': return fuzz.zmf(x, abcd[0], abcd[1]) # zmf(x, a, b) elif mf == 'trimf': return fuzz.trimf(x, abcd[0:3]) # trimf(x, abc) elif mf == 'dsigmf': return fuzz.dsigmf(x, abcd[0], abcd[1], abcd[2], abcd[3]) # dsigmf(x, b1, c1, b2, c2) elif mf == 'gauss2mf': return fuzz.gauss2mf( x, abcd[0], abcd[1], abcd[2], abcd[3]) # gauss2mf(x, mean1, sigma1, mean2, sigma2) elif mf == 'gaussmf': return fuzz.gaussmf(x, abcd[0], abcd[1]) # gaussmf(x, mean, sigma) elif mf == 'gbellmf': return fuzz.gbellmf(x, abcd[0], abcd[1], abcd[2]) # gbellmf(x, a, b, c) elif mf == 'piecemf': return fuzz.piecemf(x, abcd[0:3]) # piecemf(x, abc) elif mf == 'pimf': return fuzz.pimf(x, abcd[0], abcd[1], abcd[2], abcd[3]) # pimf(x, a, b, c, d) elif mf == 'psigmf': return fuzz.psigmf(x, abcd[0], abcd[1], abcd[2], abcd[3]) # psigmf(x, b1, c1, b2, c2) elif mf == 'sigmf': return fuzz.sigmf(x, abcd[0], abcd[1]) # sigmf(x, b, c) elif mf == 'smf': return fuzz.smf(x, abcd[0], abcd[1]) # smf(x, a, b) elif mf == 'trapmf': return fuzz.trapmf(x, abcd) # trapmf(x, abcd)
def membership_f(mf, x, abc = [0,0,0], a = 1, b = 2, c = 3, d = 4, abcd = [0,0,0,0]): return { 'trimf' : fuzz.trimf(x, abc), # trimf(x, abc) 'dsigmf' : fuzz.dsigmf(x, a, b, c, d), # dsigmf(x, b1, c1, b2, c2) 'gauss2mf': fuzz.gauss2mf(x, a, b, c, d), # gauss2mf(x, mean1, sigma1, mean2, sigma2) 'gaussmf' : fuzz.gaussmf(x, a, b), # gaussmf(x, mean, sigma) 'gbellmf' : fuzz.gbellmf(x, a, b, c), # gbellmf(x, a, b, c) 'piecemf' : fuzz.piecemf(x, abc), # piecemf(x, abc) 'pimf' : fuzz.pimf(x, a, b, c, d), # pimf(x, a, b, c, d) 'psigmf' : fuzz.psigmf(x, a, b, c, d), # psigmf(x, b1, c1, b2, c2) 'sigmf' : fuzz.sigmf(x, a, b), # sigmf(x, b, c) 'smf' : fuzz.smf(x, a, b), # smf(x, a, b) 'trapmf' : fuzz.trapmf(x, abcd), # trapmf(x, abcd) 'zmf' : fuzz.zmf(x, a, b), # zmf(x, a, b) }[mf]
def membership_f(mf, x, abc=[0, 0, 0], a=1, b=2, c=3, d=4, abcd=[0, 0, 0, 0]): """ Returns y values corresponding to type of type of Membership fn. arguments: mf - string containing type of Membership function x - x axis values abc - list containing triangular edge point x-values """ return { "trimf": fuzz.trimf(x, abc), # trimf(x, abc) "dsigmf": fuzz.dsigmf(x, a, b, c, d), # dsigmf(x, b1, c1, b2, c2) "gauss2mf": fuzz.gauss2mf(x, a, b, c, d), # gauss2mf(x, mean1, sigma1, mean2, sigma2) "gaussmf": fuzz.gaussmf(x, a, b), # gaussmf(x, mean, sigma) "gbellmf": fuzz.gbellmf(x, a, b, c), # gbellmf(x, a, b, c) "piecemf": fuzz.piecemf(x, abc), # piecemf(x, abc) "pimf": fuzz.pimf(x, a, b, c, d), # pimf(x, a, b, c, d) "psigmf": fuzz.psigmf(x, a, b, c, d), # psigmf(x, b1, c1, b2, c2) "sigmf": fuzz.sigmf(x, a, b), # sigmf(x, b, c) "smf": fuzz.smf(x, a, b), # smf(x, a, b) "trapmf": fuzz.trapmf(x, abcd), # trapmf(x, abcd) "zmf": fuzz.zmf(x, a, b), # zmf(x, a, b) }[mf]
def membership_f(mf, x, abc = [0,0,0], a = 1, b = 2, c = 3, d = 4, abcd = [0,0,0,0]): """ Returns y values corresponding to type of type of Membership fn. arguments: mf - string containing type of Membership function x - x axis values abc - list containing triangular edge point x-values """ return { 'trimf' : fuzz.trimf(x, abc), # trimf(x, abc) 'dsigmf' : fuzz.dsigmf(x, a, b, c, d), # dsigmf(x, b1, c1, b2, c2) 'gauss2mf': fuzz.gauss2mf(x, a, b, c, d), # gauss2mf(x, mean1, sigma1, mean2, sigma2) 'gaussmf' : fuzz.gaussmf(x, a, b), # gaussmf(x, mean, sigma) 'gbellmf' : fuzz.gbellmf(x, a, b, c), # gbellmf(x, a, b, c) 'piecemf' : fuzz.piecemf(x, abc), # piecemf(x, abc) 'pimf' : fuzz.pimf(x, a, b, c, d), # pimf(x, a, b, c, d) 'psigmf' : fuzz.psigmf(x, a, b, c, d), # psigmf(x, b1, c1, b2, c2) 'sigmf' : fuzz.sigmf(x, a, b), # sigmf(x, b, c) 'smf' : fuzz.smf(x, a, b), # smf(x, a, b) 'trapmf' : fuzz.trapmf(x, abcd), # trapmf(x, abcd) 'zmf' : fuzz.zmf(x, a, b), # zmf(x, a, b) }[mf]
import numpy as np import skfuzzy as fuzz import matplotlib.pyplot as plt # Generate universe variables # * Quality and service on subjective ranges [0, 10] # * Tip has a range of [0, 25] in units of percentage points x_qual = np.arange(0, 11, 1) x_serv = np.arange(0, 11, 1) x_tip = np.arange(0, 26, 1) # Generate fuzzy membership functions qual_lo = fuzz.gaussmf(x_qual, 3, 0.5) qual_md = fuzz.gbellmf(x_qual, 1, 1, 5) qual_hi = fuzz.piecemf(x_qual, [6, 7, 10]) serv_lo = fuzz.pimf(x_serv, 0, 2.9, 3, 8) serv_md = fuzz.sigmoid(x_serv, 0.5) serv_hi = fuzz.smf(x_serv, 6, 9) tip_lo = fuzz.trapmf(x_tip, [0, 0, 3, 6]) tip_md = fuzz.trimf(x_tip, [0, 13, 25]) tip_hi = fuzz.zmf(x_tip, 14, 20) # Visualize these universes and membership functions fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, figsize=(8, 9)) ax0.plot(x_qual, qual_lo, 'b', linewidth=1.5, label='Bad') ax0.plot(x_qual, qual_md, 'g', linewidth=1.5, label='Decent') ax0.plot(x_qual, qual_hi, 'r', linewidth=1.5, label='Great') ax0.set_title('Food quality') ax0.legend()