Defuzzify

class floulib.Defuzzify(*args)

Bases: object

__init__(*args)

Constructor

Parameters:

*args (None | Terms | numpy.ndarray | Tuple[Term]) –

  • None fornumeric defuzzification of a discrete fuzzy subset.

  • numpy.ndarray for numeric defuzzification.

  • Terms if only one parameter is given or several Term parameters for symbolic defuzzification.

Raises:
  • TypeError – Raised if the argument is not an instance of Terms or numpy.ndarray when one parameter is given.

  • TypeError – Raised if args are not instances of Term when several parameters are given.

Return type:

None.

numeric(*args)

Numeric defuzzification

Parameters:

*args (callable | Discrete | Multilinear | Term) – The fuzzy set to defuzzify.

Raises:
  • TypeError – Raised if Defuzzify() was created without a numpy.ndarray parameter if the parameter is callable.

  • TypeError – Raised if parameter is not callable or an instance of Discrete, Multilinear or Term.

Returns:

Result of the defuzzification.

Return type:

float

Example

Defuzzificaion of a multilinear fuzzy subset.

>>> from floulib import Defuzzify, LR
>>> import numpy as np
>>> A = LR(1, 0.5, 1)
>>> u = Defuzzify(np.linspace(0, 4, 1000)).numeric(A)
>>> print(u)
1.1666683383450254

Defuzzification of a discrete fuzzy subset.

>>> from floulib import Defuzzify, Discrete
>>> A = Discrete((1, 0.1), (2, 0.4), (3, 0.1))
>>> u = Defuzzify().numeric(A)
>>> print(u)
2.0000000000000004

Defuzzificaion of a Term.

>>> from floulib import Defuzzify, LR, Term
>>> import numpy as np
>>> A = Term('A', LR(1, 0.5, 1))
>>> u = Defuzzify(np.linspace(0, 4, 1000)).numeric(A)
>>> print(u)
1.1666683383450254
symbolic(x, method='WAM-C', key=None)

Symbolic defuzzification

Parameters:
  • x (TYPE) – DESCRIPTION.

  • method (str, optional) –

    Defuzzificaion method. The default is ‘WAM-C’. possible values are:

    • CoS: Center of sums

    • WAM-C: Weighted Average Method using centroids

    • WAM-M: Weighted Average Method using modes

    • WAM_P: Weighted Average Method using prototypes

  • key (string, optional) – key for the prototype in WAM-P method. The default is None.

Raises:
  • Exception – Raised if Defuzzify() is not created with terms.

  • TypeError – Raised if the parameter is not an instance of Discrete.

  • Exception – Raised if the defuzzification is not CoS, WAM-C, WAM-M or WAM-P.

Returns:

Result of the defuzzification.

Return type:

float

Example

>>> from floulib import Defuzzify, Discrete, Term, Triangle
>>> import numpy as np
>>> B1 = Term('B1', Triangle(0, 5, 10, label = '$B_1$'))
>>> B2 = Term('B2', Triangle(5, 10, 15, label = '$B_2$'))
>>> B3 = Term('B3', Triangle(10, 15, 25, label = '$B_3$'))
>>> T = Terms(B1, B2, B3)
>>> A = Discrete(('B1', 0.0), ('B2', 0.3), ('B3', 0.7))
>>> u1 = Defuzzify(T).symbolic(A)
>>> u2 = Defuzzify(T).symbolic(A, method = 'CoS')
>>> print(u1, u2)
14.666666666666666 15.185185185185185