Membership Functions

Functions in this module returns a standard membership function specificaion as a list of points (x_i, u_i).

class fuzzy_expert.mf.MembershipFunction(n_points=9)[source]

Bases: object

Membership function constructor.

Parameters

n_points – Number base point for building the approximations.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=3)
>>> mf(('gaussmf', 5, 1))
[(2, 0), (3.0, 0.1353352832366127), (3.8, 0.48675225595997157), (4.6, 0.9231163463866356), (5.0, 1.0), (5.4, 0.9231163463866356), (6.2, 0.48675225595997157), (7.0, 0.1353352832366127), (8, 0)]
gaussmf(center, sigma)[source]

Gaussian membership function.

Parameters
  • center – Defines the center of the membership function.

  • sigma – Defines the width of the membership function, where a larger value creates a wider membership function.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=3)
>>> mf.gaussmf(center=5, sigma=1)
[(2, 0), (3.0, 0.1353352832366127), (3.8, 0.48675225595997157), (4.6, 0.9231163463866356), (5.0, 1.0), (5.4, 0.9231163463866356), (6.2, 0.48675225595997157), (7.0, 0.1353352832366127), (8, 0)]
gbellmf(center, width, shape)[source]

Generalized bell-shaped membership function.

Parameters
  • center – Defines the center of the membership function.

  • width – Defines the width of the membership function, where a larger value creates a wider membership function.

  • shape – Defines the shape of the curve on either side of the central plateau, where a larger value creates a more steep transition.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=3)
>>> mf.gbellmf(center=5, width=1, shape=0.5)
[(-1, 0), (0.0, 0.16666666666666666), (1.0, 0.2), (2.0, 0.25), (3.0, 0.3333333333333333), (3.8, 0.45454545454545453), (4.0, 0.5), (4.6, 0.7142857142857141), (5.0, 1.0), (5.4, 0.7142857142857141), (6.0, 0.5), (6.2, 0.45454545454545453), (7.0, 0.3333333333333333), (8.0, 0.25), (9.0, 0.2), (10.0, 0.16666666666666666), (11, 0)]
pimf(left_feet, left_peak, right_peak, right_feet)[source]

Pi-shaped membership function.

Parameters
  • left_feet – Defines the left feet of the membership function.

  • left_peak – Defines the left peak of the membership function.

  • right_peak – Defines the right peak of the membership function.

  • right_feet – Defines the right feet of the membership function.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=4)
>>> mf.pimf(left_feet=1, left_peak=2, right_peak=3, right_feet=4)
[(1.0, 0.0), (1.3333333333333333, 0.22222222222222213), (1.6666666666666665, 0.7777777777777776), (2.0, 1.0), (3.0, 1.0), (3.3333333333333335, 0.7777777777777776), (3.6666666666666665, 0.22222222222222243), (4.0, 0.0)]
sigmf(center, width)[source]

Sigmoidal membership function.

Parameters
  • center – Defines the center of the membership function.

  • width – Defines the width of the membership function.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=3)
>>> mf.sigmf(center=5, width=1)
[(-1, 0), (0.0, 0.0066928509242848554), (2.0, 0.04742587317756678), (4.0, 0.2689414213699951), (5.0, 0.5), (6.0, 0.7310585786300049), (8.0, 0.9525741268224334), (10.0, 0.9933071490757153), (11, 1)]
smf(foot, shoulder)[source]

S-shaped membership function.

Parameters
  • foot – Defines the foot of the membership function.

  • shoulder – Defines the shoulder of the membership function.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=4)
>>> mf.smf(foot=1, shoulder=2)
[(1.0, 0.0), (1.3333333333333333, 0.22222222222222213), (1.6666666666666665, 0.7777777777777776), (2.0, 1.0)]
trapmf(left_feet, left_peak, right_peak, right_feet)[source]

Trapezoidal membership function.

Parameters
  • left_feet – Defines the left feet of the membership function.

  • left_peak – Defines the left peak of the membership function.

  • right_peak – Defines the right peak of the membership function.

  • right_feet – Defines the right feet of the membership function.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=4)
>>> mf.trapmf(left_feet=1, left_peak=2, right_peak=3, right_feet=4)
[(1.0, 0.0), (2.0, 1.0), (3.0, 1.0), (4.0, 0.0)]
trimf(left_feet, peak, right_feet)[source]

Triangular membership function.

Parameters
  • left_feet – Defines the left feet of the membership function.

  • peak – Defines the peak of the membership function.

  • right_feet – Defines the right feet of the membership function.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=4)
>>> mf.trimf(left_feet=1, peak=2, right_feet=4)
[(1.0, 0.0), (2.0, 1.0), (4.0, 0.0)]
zmf(shoulder, feet)[source]

Z-shaped membership function.

Parameters
  • shoulder – Defines the shoulder of the membership function.

  • feet – Defines the feet of the membership function.

>>> from fuzzy_expert.mf import MembershipFunction
>>> mf = MembershipFunction(n_points=4)
>>> mf.zmf(shoulder=1, feet=2)
[(1.0, 1.0), (1.3333333333333333, 0.7777777777777779), (1.6666666666666665, 0.22222222222222243), (2.0, 0.0)]