Module type2fuzzy.type1_defuzzification

type2fuzzy.type1_defuzzification

Type-1 defuzzification methods.
Centre of Gravity.
Mean of Maxima.

Expand source code
"""
type2fuzzy.type1_defuzzification 

Type-1 defuzzification methods.<br/>
Centre of Gravity.<br/>
Mean of Maxima.<br/>

"""
from type2fuzzy.type1_defuzzification.cog_defuzzifier import cog_defuzzify
from type2fuzzy.type1_defuzzification.mom_defuzzifier import mom_defuzzify
from type2fuzzy.type1_defuzzification.zslice_centroid_defuzzifier import zslice_centroid_defuzzify

__all__ = ['cog_defuzzify', 'mom_defuzzify', 'zslice_centroid_defuzzify']

Sub-modules

type2fuzzy.type1_defuzzification.cog_defuzzifier
type2fuzzy.type1_defuzzification.mom_defuzzifier
type2fuzzy.type1_defuzzification.zslice_centroid_defuzzifier

Functions

def cog_defuzzify(type1_set)

Centre of gravity defuzzification method

References:

Pedrycz, Witold. Fuzzy control and fuzzy systems (2nd. Research Studies Press Ltd., 1993.

Arguments:

type1_set – Type1FuzzySet, the set whose centroid is to be computed

Returns:

centroid – float, the centroid of this set

Raises:

Exception if the denominator of the calculation is zero

Expand source code
def cog_defuzzify(type1_set):
        '''
        Centre of gravity defuzzification method

        References:
        -----------
        Pedrycz, Witold. Fuzzy control and fuzzy systems (2nd. Research Studies Press Ltd., 1993.

        Arguments:
        ----------
        type1_set   -- Type1FuzzySet, the set whose centroid is to be computed

        Returns:
        --------
        centroid    -- float, the centroid of this set

        Raises:
        -------
        Exception if the denominator of the calculation is zero

        '''
        numerator = 0
        denominator = 0

        for domain_element in type1_set.domain_elements():
                numerator = numerator + (domain_element * type1_set[domain_element])
                denominator = denominator + type1_set[domain_element]

        centroid = 0
        if denominator == 0:
                raise Exception('Cannot determine centroid')
        else:
                centroid = numerator / denominator

        return centroid
def mom_defuzzify(type1_set)

Mean of Maxima defuzzification method

References:

Mamdani, E. H., H. J. Efstathiou, and K. Sugiyama. "Developments in fuzzy logic control." Decision and Control, 1984. The 23rd IEEE Conference on. Vol. 23. IEEE, 1984.

Arguments:

type1_set – Type1FuzzySet, the set whose centroid is to be computed

Returns:

centroid – float, the centroid of this set

Raises:

Expand source code
def mom_defuzzify(type1_set):
    '''
    Mean of Maxima defuzzification method

    References:
    -----------
    Mamdani, E. H., H. J. Efstathiou, and K. Sugiyama. 
    "Developments in fuzzy logic control." Decision and Control, 1984. 
    The 23rd IEEE Conference on. Vol. 23. IEEE, 1984.

    Arguments:
    ----------
    type1_set   -- Type1FuzzySet, the set whose centroid is to be computed

    Returns:
    --------
    centroid    -- float, the centroid of this set

    Raises:
    -------
    '''

    max_domain_elements = []
    max_dom = 0

    for domain_element in type1_set.domain_elements():

        if type1_set[domain_element] > max_dom:
            max_dom = type1_set[domain_element]
            max_domain_elements.clear()
            max_domain_elements.append(domain_element)
        elif type1_set[domain_element] == max_dom:
            max_domain_elements.append(domain_element)

    centroid = sum(max_domain_elements)/len(max_domain_elements)

    return centroid
def zslice_centroid_defuzzify(zSlice_set)
Expand source code
def zslice_centroid_defuzzify(zSlice_set):
        
        numerator = 0
        denominator = 0

        for cut in zSlice_set.cuts():
                left = zSlice_set[cut].left
                right = zSlice_set[cut].right

                numerator = numerator + (cut * ((left + right)/2))
                denominator = denominator + cut
        
        centroid = numerator / denominator

        return centroid