Пример #1
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 18:56:00 2019

@author: arslan
"""

from pyit2fls import IT2FS_Gaussian_UncertMean, IT2FS_plot, meet, \
                     join, min_t_norm, max_s_norm
from numpy import linspace

domain = linspace(0., 1., 100)

A = IT2FS_Gaussian_UncertMean(domain, [0., 0.1, 0.1, 1.])
B = IT2FS_Gaussian_UncertMean(domain, [0.33, 0.1, 0.1, 1.])
C = IT2FS_Gaussian_UncertMean(domain, [0.66, 0.1, 0.1, 1.])

IT2FS_plot(A, B, C, title="", legends=["Small","Medium","Large"], filename="multiSet")

AB = meet(domain, A, B, min_t_norm)
AB.plot(filename="meet")

BC = join(domain, B, C, max_s_norm)
BC.plot(filename="join")
Пример #2
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 14 18:16:26 2020

@author: arslan
"""

from pyit2fls import IT2FS_Gaussian_UncertMean, join, IT2FS_plot, \
    max_s_norm, probabilistic_sum_s_norm, bounded_sum_s_norm, \
    drastic_s_norm, nilpotent_maximum_s_norm, einstein_sum_s_norm
from numpy import linspace

domain = linspace(-1., 7., 8001)
A1 = IT2FS_Gaussian_UncertMean(domain, [0., 0.2, 0.25, 1.])
A2 = IT2FS_Gaussian_UncertMean(domain, [1., 0.2, 0.25, 1.])
A3 = IT2FS_Gaussian_UncertMean(domain, [2., 0.2, 0.25, 1.])
A4 = IT2FS_Gaussian_UncertMean(domain, [3., 0.2, 0.25, 1.])
A5 = IT2FS_Gaussian_UncertMean(domain, [4., 0.2, 0.25, 1.])
A6 = IT2FS_Gaussian_UncertMean(domain, [5., 0.2, 0.25, 1.])
A7 = IT2FS_Gaussian_UncertMean(domain, [6., 0.2, 0.25, 1.])
IT2FS_plot(
    A1,
    A2,
    A3,
    A4,
    A5,
    A6,
    A7,
    title="Sets",
    legends=["Set 1", "Set 2", "Set 3", "Set 4", "Set 5", "Set 6", "Set 7"])
Пример #3
0
                     join, min_t_norm, max_s_norm
from numpy import linspace


# Defining three interval type 2 fuzzy sets for testing the meet and join 
# functions.

# Domain is defined as discrete space in the interval [0, 1] divided to 100 parts.
domain = linspace(0., 1., 100)

# The first IT2FLS is defined as a Gaussian set with uncertain mean value.
# Center of the mean = 0.25, 
# Spread of the mean = 0.1, 
# Standard deviation = 0.1, and 
# Height = 1.
A = IT2FS_Gaussian_UncertMean(domain, [0.25, 0.1, 0.1, 1.])

# The second IT2FLS is defined as a Gaussian set with uncertain mean value.
# Center of the mean = 0.5, 
# Spread of the mean = 0.1, 
# Standard deviation = 0.1, and 
# Height = 1.
B = IT2FS_Gaussian_UncertMean(domain, [0.5, 0.1, 0.1, 1.])

# The third IT2FLS is defined as a Gaussian set with uncertain mean value.
# Center of the mean = 0.75, 
# Spread of the mean = 0.1, 
# Standard deviation = 0.1, and 
# Height = 1.
C = IT2FS_Gaussian_UncertMean(domain, [0.75, 0.1, 0.1, 1.])
Пример #4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  9 20:10:33 2021

@author: arslan
"""

from pyit2fls import (IT2FS_Gaussian_UncertMean, IT2_Emphasize, IT2FS_plot,
                      T1FS, gaussian_mf, T1_Emphasize, T1FS_plot)
from numpy import linspace

domain = linspace(0., 1., 101)

IT2mySet = IT2FS_Gaussian_UncertMean(domain, [0.5, 0.1, 0.2, 1.],
                                     check_set=True)
IT2Emphasized_mySet = IT2_Emphasize(IT2mySet, m=3.)
IT2FS_plot(IT2mySet, IT2Emphasized_mySet, legends=["Simple", "Emphasized"])

T1mySet = T1FS(domain, mf=gaussian_mf, params=[0.5, 0.1, 1.])
T1Emphasized_mySet = T1_Emphasize(T1mySet, m=3.)
T1FS_plot(T1mySet, T1Emphasized_mySet, legends=["Simple", "Emphasized"])
def calculate_FLS(cough_inp, fever_inp, breath_inp, age, env_inp,
                  hypertension_inp, diabetes_inp, cardiovascular_inp,
                  respiratory_inp, immune_inp):
    severity = linspace(0.0, 10.0, 100)

    # For IT2FS_Gaussian_UncertMean, the parameters define:
    # 1 - The tip of the center point of the curve
    # 2 - The width of the lower curve (higher value = lower width)
    # 3 - The height of the lower curve (higher value = higher tip)
    # 4 - The height of the center point of the outer curve.

    Cough_neg = IT2FS(severity, trapezoid_mf, [0., 0.001, 3, 7, 1.0], tri_mf,
                      [0, 0.001, 2, 0.5])
    Cough_pos = IT2FS(severity, trapezoid_mf, [5, 8, 9.999, 10, 1.0], tri_mf,
                      [8.5, 9.999, 10, 0.5])

    Fever_low = IT2FS_Gaussian_UncertMean(severity, [0, 2.65, 1, 1.0])
    Fever_mod = IT2FS_Gaussian_UncertMean(severity, [5, 2.65, 1, 1.0])
    Fever_high = IT2FS_Gaussian_UncertMean(severity, [10, 2.65, 1, 1.0])

    BreathDiff_low = IT2FS_Gaussian_UncertMean(severity, [0, 1.75, 1, 1.0])
    BreathDiff_mod = IT2FS_Gaussian_UncertMean(severity, [5, 2.5, 1, 1.0])
    BreathDiff_extr = IT2FS_Gaussian_UncertMean(severity, [10, 1.75, 1, 1.0])

    Add_low = IT2FS_Gaussian_UncertMean(severity, [0, 5, 2, 1.0])
    Add_high = IT2FS_Gaussian_UncertMean(severity, [10, 5, 2, 1.0])

    Risk_low = IT2FS_Gaussian_UncertMean(severity, [0, 3, 1, 1.0])
    Risk_high = IT2FS_Gaussian_UncertMean(severity, [6.5, 2, 1, 1.0])
    Risk_veryhigh = IT2FS_Gaussian_UncertMean(severity, [10.7, 1, 1, 1.0])

    def plot_cough_mf():
        IT2FS_plot(
            Cough_neg,
            Cough_pos,
            title="Cough",
            legends=["Negative", "Positive"],
        )

    def plot_fever_mf():
        IT2FS_plot(
            Fever_low,
            Fever_mod,
            Fever_high,
            title="Fever",
            legends=["Low", "Moderate", "High"],
        )

    def plot_additional_mf():
        IT2FS_plot(
            Add_low,
            Add_high,
            title="Additional Risks",
            legends=["Low", "High"],
        )

    def plot_breathdiff_mf():
        IT2FS_plot(
            BreathDiff_low,
            BreathDiff_mod,
            BreathDiff_extr,
            title="Breathing Difficulty",
            legends=["Low", "Moderate", "High"],
        )

    def plot_risk_mf():
        IT2FS_plot(
            Risk_low,
            Risk_high,
            Risk_veryhigh,
            title="Overall Risk",
            legends=["Unlikely", "Likely", "Extremely Likely"],
        )

    plot_fever_mf()
    plot_cough_mf()
    plot_breathdiff_mf()
    plot_additional_mf()

    plot_risk_mf()

    myIT2FLS = IT2FLS()

    myIT2FLS.add_input_variable("cough")
    myIT2FLS.add_input_variable("fever")
    myIT2FLS.add_input_variable("breath")
    myIT2FLS.add_input_variable("add")
    myIT2FLS.add_output_variable("risk")

    myIT2FLS.add_rule([("cough", Cough_neg), ("fever", Fever_low),
                       ("breath", BreathDiff_low), ("add", Add_low)],
                      [("risk", Risk_low)])
    myIT2FLS.add_rule([("cough", Cough_pos), ("fever", Fever_mod),
                       ("breath", BreathDiff_low), ("add", Add_low)],
                      [("risk", Risk_low)])
    myIT2FLS.add_rule([("cough", Cough_neg), ("fever", Fever_high),
                       ("breath", BreathDiff_low), ("add", Add_low)],
                      [("risk", Risk_low)])
    myIT2FLS.add_rule([("cough", Cough_neg), ("fever", Fever_high),
                       ("breath", BreathDiff_low), ("add", Add_high)],
                      [("risk", Risk_low)])
    myIT2FLS.add_rule([("cough", Cough_neg), ("fever", Fever_low),
                       ("breath", BreathDiff_extr), ("add", Add_low)],
                      [("risk", Risk_high)])
    myIT2FLS.add_rule([("cough", Cough_neg), ("fever", Fever_high),
                       ("breath", BreathDiff_mod), ("add", Add_low)],
                      [("risk", Risk_high)])
    myIT2FLS.add_rule([("cough", Cough_pos), ("fever", Fever_mod),
                       ("breath", BreathDiff_mod), ("add", Add_high)],
                      [("risk", Risk_veryhigh)])
    myIT2FLS.add_rule([("cough", Cough_pos), ("fever", Fever_low),
                       ("breath", BreathDiff_extr), ("add", Add_high)],
                      [("risk", Risk_veryhigh)])
    myIT2FLS.add_rule([("cough", Cough_pos), ("fever", Fever_mod),
                       ("breath", BreathDiff_mod), ("add", Add_high)],
                      [("risk", Risk_veryhigh)])
    myIT2FLS.add_rule([("cough", Cough_pos), ("fever", Fever_high),
                       ("breath", BreathDiff_extr), ("add", Add_high)],
                      [("risk", Risk_veryhigh)])

    # cough_inp = float(input("Enter severity of coughing, between 0 and 10: "))
    # fever_inp = float(input("Enter severity of fever, between 0 and 10: "))
    # breath_inp = float(input("Enter severity of breathing difficulty, between 0 and 10: "))
    # print("Input age and other additional risk factors.")
    add_inp = calc_additional_risks(age, env_inp, hypertension_inp,
                                    diabetes_inp, cardiovascular_inp,
                                    respiratory_inp, immune_inp)

    it2out, tr = myIT2FLS.evaluate(
        {
            "cough": cough_inp,
            "fever": fever_inp,
            "breath": breath_inp,
            "add": add_inp
        },
        min_t_norm,
        max_s_norm,
        severity,
        method="Centroid",
        algorithm="EKM")
    print(tr)
    print(it2out)

    it2out["risk"].plot(title="Type-2 output MF converted to Type-1")
    TR_plot(severity, tr["risk"])
    print("Chance of C19 Infection: ", int((crisp(tr["risk"])) * 10), "%")

    return int((crisp(tr["risk"])) * 10)
Пример #6
0
             check_set=True)

IT2FS_plot(Const, Tri, legends=["Const Set", "Triangular Set"])
IT2FS_plot(RTri, LTri, legends=["Right Triangular Set", "Left Triangular Set"])

Trapezoid = IT2FS(domain,
                  trapezoid_mf, [0.1, 0.35, 0.65, 0.9, 1.0],
                  trapezoid_mf, [0.2, 0.4, 0.6, 0.8, 0.8],
                  check_set=True)

Trapezoid.plot(legend_text="Trapezoid IT2FS")

Gaussian = IT2FS(domain,
                 gaussian_mf, [0.5, 0.1, 1.0],
                 gaussian_mf, [0.5, 0.05, 0.8],
                 check_set=True)

Gaussian.plot(legend_text="Gaussian IT2FS")

Gaussian_UncertMean = IT2FS_Gaussian_UncertMean(domain, [0.5, 0.1, 0.1, 1.])
Gaussian_UncertMean.plot(legend_text="Gaussian IT2FS with Uncertain Mean")

Gaussian_UncertStd = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.1, 0.05, 0.75])
Gaussian_UncertStd.plot(legend_text="Gaussian IT2FS with Uncertain Std")

RGaussian_UncertStd = R_IT2FS_Gaussian_UncertStd(domain, [0.5, 0.1, 0.05, 0.8])
RGaussian_UncertStd.plot(legend_text="Right Gaussian IT2FS with Uncertain Std")

LGaussian_UncertStd = L_IT2FS_Gaussian_UncertStd(domain, [0.5, 0.1, 0.05, 0.8])
LGaussian_UncertStd.plot(legend_text="Left Gaussian IT2FS with Uncertain Std")