Paper Implementation - Uncertain rule-based fuzzy logic systems Introduction and new directions-Jerry M. Mendel; Prentice-Hall, PTR, Upper Saddle River, NJ, 2001,    555pp., ISBN 0-13-040969-3. Example 9-4, page 261

Sat October 8, 2022
type2-fuzzy type2-fuzzy-library fuzzy python IT2FS paper-workout

In this post, we will validate the implementation of the Karnik-Mendel algorithm found in the type-2 fuzzy logic library with a worked example available in Mendel’s book “Uncertain rule-based fuzzy logic systems."

The example calculates the centroid of interval type-2 fuzzy sets with uncertain means $m\in[m_1, m_2]$, where the UMF and LMF of the set are calculated as follows:

$exp \left[ -0.5 \times (\frac{x-m_1}{\sigma})^2 \right]$ ,$x<m_1$
$UMF(\tilde{A})=$ $1$ ,$m_1, \geq x \geq m_2$
$exp \left[ -0.5 \times (\frac{x-m_2}{\sigma})^2 \right]$ ,$x>m_2$

$$ LMF(\tilde{A}) = min \left( exp \left[ -0.5 \times \left (\frac{x-m_1}{\sigma} \right)^2 \right], exp \left[ -0.5 \times \left( \frac{x-m_2}{\sigma} \right)^2 \right] \right) $$ The example specifies nine $[m_1, m_2]$ sets having the following values:

    [5,5],
    [4.875, 5.125],
    [4.75, 5.25],
    [4.625, 5.375],
    [4.5, 5.5],
    [4.25, 5.75],
    [4,6],
    [3.75, 6.25],
    [3.5, 6.]

Note that the first case, where $m_1=m_2=5$ will produce a type-1 fuzzy set.

The following python code is used to create the sets. As the sigma value is specified to be 1, it is not passed as a parameter in the generation function. The function expects the m-values as parameters and returns an IntervalType2FuzzySet class that contains CrispSet values having UMF and LMF for each primary domain value.

def generate_set_uncertain_mean(m_1:int, m_2:int) -> ItervalType2FuzzySet:

    '''
    Generates an interval type-2 fuzzy set with uncertain mean as
    specified by Jerry Mendel in his book.  The set has LMF and UMF
    constructed from two Gaussian functions with fixed standard  
    deviation and uncertain means that takes values in [m1. m2].

    Arguments:
    ----------
    m_1 - lower mean value
    m_2 - upper mean value

    Returns:
    --------
    it2fs - Interval type-2 fuzzy set
 
    Reference:
    ----------
    Uncertain rule-based fuzzy logic systems:
    Introduction and new directions-Jerry M. Mendel;
    Prentice-Hall, PTR, Upper Saddle River, NJ, 2001,
    555pp., ISBN 0-13-040969-3.,  page 91
    '''

    # function to calculate UMF and LMF
    sigma=1
    u_A = lambda x,m: exp((((x-m)/sigma)**2)*-0.5)

    # range of primary domain
    primary_domain = np.linspace(0, 10, 101)

    it2fs = IntervalType2FuzzySet()

    for x_val in primary_domain:

        if x_val < m_1:
            it2fs.add_element(
                x_val,
                CrispSet(
                    u_A(x_val, m_2),
                    u_A(x_val, m_1))
            )
        elif x_val >m_2:
            it2fs.add_element(
                x_val,
                CrispSet(
                    u_A(x_val, m_1),
                    u_A(x_val, m_2))
            )
        else:
            it2fs.add_element(
                x_val,
                CrispSet(
                    min(u_A(x_val, m_2), u_A(x_val, m_1)),
                    1)
            )

    return it2fs

When calculating the centroids, Mendel produces the following result in his book:

book results, copyright Jerry Mendel

The next step is replicating this result using the type-2 fuzzy logic library. We will use the following classes in this exercise.

The code used to generate and plot the sets and calculate the centroids is below:


def mendel_example_9_4():
    '''
    Computation of centroid of interval type-2 fuzzy sets
    having Gaussian primary membership function with uncertain mean,
    m \in [m1, m2] with the following values:
        [5,5],
        [4.875, 5.125],
        [4.75, 5.25],
        [4.625, 5.375],
        [4.5, 5.5],
        [4.25, 5.75],
        [4,6],
        [3.75, 6.25],
        [3.5, 6.]
    Note that the case where m1=m2=5 is the type-1 set.
  
    Arguments:
    ----------
  
    Returns:
    --------
  
    Reference:
    ----------
    Uncertain rule-based fuzzy logic systems:
    Introduction and new directions-Jerry M. Mendel;
    Prentice-Hall, PTR, Upper Saddle River, NJ, 2001,
    555pp., ISBN 0-13-040969-3. page 261
    '''
  
 
    # results table
    table = PrettyTable()
    table.field_names=['[m1, m2]', 'm2-m1', '[cl, cr]', 'cr-cl']
  
    # Setplotter from type-2 fuzzy library to plot sets
    set_plotter = SetPlotter()
  
    # ranges specified in the text
    m_pairs = [
        (5,5),
        (4.875, 5.125),
        (4.75, 5.25),
        (4.625, 5.375),
        (4.5, 5.5),
        (4.25, 5.75),
        (4,6),
        (3.75, 6.25),
        (3.5, 6.5)
    ]

 
    for m1, m2 in m_pairs:
  
        # create set
        i_set = generate_set_uncertain_mean(m1, m2)
        # find its centroid
        cen = it2_kernikmendel_reduce(i_set)
  
        table.add_row([
            f'[{m2}, {m1}]',

           m2-m1,
            f'[{cen.right}, {cen.left}]',
            round(cen.left-cen.right, 4)
        ])
  
        # add set to plt
        set_plotter.add_invervaltype2set(i_set, f'[{m2}, {m1}]')
  
    print(table)
    set_plotter.plot(5)
    plt.show()

Results

We generated the following plots to illustrate the interval type-2 sets produced. As expected, the first example had a type-1 set.

book results

The centroid results match those obtained by the author:

+----------------+-------+--------------------+--------+
|    [m1, m2]    | m2-m1 |      [cl, cr]      | cr-cl  |
+----------------+-------+--------------------+--------+
|     [5, 5]     |   0   |     [5.0, 5.0]     |  0.0   |
| [5.125, 4.875] |  0.25 | [4.87498, 5.12502] |  0.25  |
|  [5.25, 4.75]  |  0.5  | [4.74952, 5.25048] | 0.501  |
| [5.375, 4.625] |  0.75 | [4.62265, 5.37735] | 0.7547 |
|   [5.5, 4.5]   |  1.0  | [4.49285, 5.50715] | 1.0143 |
|  [5.75, 4.25]  |  1.5  | [4.21675, 5.78325] | 1.5665 |
|     [6, 4]     |   2   | [3.90697, 6.09303] | 2.1861 |
|  [6.25, 3.75]  |  2.5  | [3.55194, 6.44806] | 2.8961 |
|   [6.5, 3.5]   |  3.0  | [3.15053, 6.84947] | 3.6989 |
+----------------+-------+--------------------+--------+



Type Reduction of Interval Type-2 Fuzzy Sets

April 6, 2022
type2-fuzzy type2-fuzzy-library fuzzy python IT2FS

Paper Implementation - C. Wagner and H. Hagras. 'Toward general type-2 fuzzy logic systems based on zSlices.'

A look at C. Wagner and H. Hagras. 'Toward general type-2 fuzzy logic systems based on zSlices.', working of paper examples using T2Fuzz Library
type2-fuzzy paper-workout type2-fuzzy-library fuzzy python

Linear Regression, Part 10 - Analysis of Gradient Descent Algorithms; Results obtained

March 12, 2022
machine-learning linear-regression gradient-descent python
comments powered by Disqus


machine-learning 25 python 21 fuzzy 14 hugo_cms 11 azure-ml 10 linear-regression 10 gradient-descent 9 type2-fuzzy 8 type2-fuzzy-library 8 type1-fuzzy 5 cnc 4 dataset 4 datastore 4 it2fs 4 excel 3 paper-workout 3 r 3 c 2 c-sharp 2 experiment 2 iot 2 programming 2 robotics 2 weiszfeld_algorithm 2 arduino 1 automl 1 classifier 1 computation 1 cost-functions 1 development 1 embedded 1 fuzzy-logic 1 game 1 hyperparameter-tuning 1 javascript 1 learning 1 mathjax 1 maths 1 model-optimization 1 mxchip 1 pandas 1 pipeline 1 random_walk 1 roc 1 tools 1 vscode 1 wsl 1