Membership functions

Creating membership function

Any function with take float as an argument and returns value from range of [0, 1] can serve as membership function. One of the simples membership function is singleton - this membership function return 1 when x is equal to given value, 0 otherwise.

from math import isclose
def singleton_at_5(x):
    return 1 if isclose(x, 5) else 0

It’s not wise to declare membership functions this way. Most of the time membership function can be parametrised, and they’r creation should be abstracted into higher order function:

from math import isclose
def singleton(at):
    return lambda x: 1 if isclose(x, at) else 0

or simple class with overloaded __call__:

from math import isclose
class Singleton:
    def __call__(self, x):
        return 1 if isclose(self.at, x) else 0

    def __init__(self, at):
        self.at = at

Both form are equivalent but this library prefer second form. Python classes are flexible and expandable than python lambda calculus.

Predefined membership functions

Triangular

(Source code, png, hires.png, pdf)

_images/simple_triangle.png
class yvain.membership_functions.Triangle(a: float, b: float, c: float)

For triangular membership function x is member of fuzzy set only if it’s greater than a and smaller than c. In this function x is fully member of fuzzy set only for x = b. Each value between a - b and b - c represent partial membership.

Trapezoid

(Source code, png, hires.png, pdf)

_images/simple_trapeze.png
class yvain.membership_functions.Trapezoid(a: float, b: float, c: float, d: float)

For trapezoidal membership function x is member of fuzzy set only if it’s greater than a and smaller than d. In this function x is fully member of fuzzy set when b <= x <= c. Each value between a - b and c - d represent partial membership.

Gaussian

(Source code, png, hires.png, pdf)

_images/simple_gaussian.png
class yvain.membership_functions.Gaussian(mu: float, sigma: float)

Gaussian function with mean = mu and standard deviation = sigma. This function has it center at mu and x = mu is only point where x is fully member of fuzzy set. Increasing sigma parameter increases width and slope of the function.

Bell

(Source code, png, hires.png, pdf)

_images/simple_bell.png
class yvain.membership_functions.Bell(mu: float, sigma: float, gamma: float)

Generalized bell curve with center at ‘mu’. ‘sigma’ parameter is responsible for width of the function and gamma is related to width of bell plateau

Sigmoid

(Source code, png, hires.png, pdf)

_images/simple_sigmoid.png
class yvain.membership_functions.Sigmoid(a: float, b: float)

S-shaped function with slope center at ‘a’. b parameter controls skewness of slope and direction of the function. When b < 0 then left side values are fully member of fuzzy set and slope decreases membership to 0. When b > 0 then left side is not member of fuzzy set and slope increases membership to 1.