def plot_cough_mf(): IT2FS_plot( Cough_neg, Cough_pos, title="Cough", legends=["Negative", "Positive"], )
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"], )
def plot_fever_mf(): IT2FS_plot( Fever_low, Fever_mod, Fever_high, title="Fever", legends=["Low", "Moderate", "High"], )
def plot(self, root_path: str) -> NoReturn: IT2FS_plot( self.antecedent['Velocity']['very_slow'], self.antecedent['Velocity']['slow'], self.antecedent['Velocity']['normal'], self.antecedent['Velocity']['fast'], self.antecedent['Velocity']['very_fast'], title='Velocity', legends=['Very Slow', 'Slow', 'Normal', 'Fast', 'Very Fast'], filename=os.path.join(root_path, 'antecedent_velocity.png')) IT2FS_plot(self.antecedent['Acceleration']['small'], self.antecedent['Acceleration']['medium'], self.antecedent['Acceleration']['large'], title='Acceleration', legends=['Small', 'Medium', 'Large'], filename=os.path.join(root_path, 'antecedent_acceleration.png')) IT2FS_plot(self.antecedent['Deceleration']['small'], self.antecedent['Deceleration']['medium'], self.antecedent['Deceleration']['large'], title='Deceleration', legends=['Small', 'Medium', 'Large'], filename=os.path.join(root_path, 'antecedent_deceleration.png')) IT2FS_plot(self.antecedent['LateralJerk']['small'], self.antecedent['LateralJerk']['medium'], self.antecedent['LateralJerk']['large'], title='LateralJerk', legends=['Small', 'Medium', 'Large'], filename=os.path.join(root_path, 'antecedent_lateral_std_jerk.png')) IT2FS_plot(self.consequent['DrivingStyle']['calm'], self.consequent['DrivingStyle']['moderate'], self.consequent['DrivingStyle']['aggressive'], title='Driving Style', legends=['Calm', 'Moderate', 'Aggressive'], filename=os.path.join(root_path, 'consequent_driving_stye.png'))
@author: arslan """ from pyit2fls import TSK, IT2FS_Gaussian_UncertStd, IT2FS_plot, \ product_t_norm, max_s_norm from numpy import linspace from time import time domain = linspace(0., 1., 100) Small = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1, 1.]) Medium = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1, 1.]) Large = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1, 1.]) IT2FS_plot(Small, Medium, Large, title="Sets", legends=["Small", "Medium", "Large"]) myIT2FLS = TSK(product_t_norm, max_s_norm) myIT2FLS.add_input_variable("x1") myIT2FLS.add_input_variable("x2") myIT2FLS.add_output_variable("y1") myIT2FLS.add_output_variable("y2") myIT2FLS.add_rule([("x1", Small), ("x2", Small)], [("y1", {"const":0.5, "x1":1., "x2":2.3}), ("y2", {"const":1., "x1":1.2, "x2":1.5})]) myIT2FLS.add_rule([("x1", Medium), ("x2", Medium)], [("y1", {"const":1., "x1":2.7, "x2":1.9}), ("y2", {"const":1., "x1":2.5, "x2":2.})]) myIT2FLS.add_rule([("x1", Large), ("x2", Large)],
from pyit2fls import IT2FLS, IT2FS_Gaussian_UncertStd, IT2FS_plot, \ min_t_norm, max_s_norm, TR_plot, crisp from numpy import linspace #domain = linspace(0., 1., 100) domain = linspace(-1., 1., 100) ''' Small = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) Medium = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) Large = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) ''' S = IT2FS_Gaussian_UncertStd(domain, [-1., 0.15, 0.1]) Z = IT2FS_Gaussian_UncertStd(domain, [0., 0.15, 0.1]) B = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(S, Z, B, legends=["S", "Z", "B"], filename="x1_simp_ex_sets") SS = IT2FS_Gaussian_UncertStd(domain, [-1., 0.15, 0.1]) ZZ = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) BB = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(SS, ZZ, BB, legends=["SS", "ZZ", "BB"], filename="x2_simp_ex_sets") A1 = IT2FS_Gaussian_UncertStd(domain, [-1, 0.15, 0.1]) A2 = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) A3 = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(A1, A2, A3, legends=["A1", "A2", "A3"], filename="y1_simp_ex_sets") B1 = IT2FS_Gaussian_UncertStd(domain, [-1., 0.15, 0.1]) B2 = IT2FS_Gaussian_UncertStd(domain, [-0.75,0.15, 0.1]) B3 = IT2FS_Gaussian_UncertStd(domain, [-0.5, 0.15, 0.1]) B4 = IT2FS_Gaussian_UncertStd(domain, [-0.25, 0.15, 0.1])
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 15 02:40:21 2019 @author: arslan """ from pyit2fls import IT2FLS, IT2FS_Gaussian_UncertStd, IT2FS_plot, \ min_t_norm, max_s_norm, TR_plot, crisp from pyit2fls import IT2FS, trapezoid_mf, tri_mf, zero_mf from numpy import linspace #domain = linspace(0., 1., 100) domain = linspace(-1., 1., 100) ''' Small = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) Medium = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) Large = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(Small, Medium, Large, legends=["Small", "Medium", "large"], filename="asb(x1,x2)_ex_sets") S = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) M = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) L = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(S, M, L, legends=["S", "M", "L"], filename="y1_ex_sets") myIT2FLS = IT2FLS() myIT2FLS.add_input_variable("x1") myIT2FLS.add_input_variable("x2") myIT2FLS.add_output_variable("y1") #myIT2FLS.add_output_variable("y2")
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed May 15 02:40:21 2019 @author: arslan """ from pyit2fls import IT2FLS, IT2FS_Gaussian_UncertStd, IT2FS_plot, \ min_t_norm, max_s_norm, TR_plot, crisp from pyit2fls import IT2FS, trapezoid_mf, tri_mf, zero_mf from numpy import linspace #domain = linspace(0., 1., 100) domain = linspace(-1., 1., 100) NB = IT2FS_Gaussian_UncertStd(domain, [0, 0.25, 0.05]) IT2FS_plot(NB, filename="1") # IT2FS_plot(NB, NS, PS,PB, legends=["NB", "NS", "PS","PB"], filename="asb(x1,x2)_ex_sets")
#!/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"])
drastic_t_norm, nilpotent_minimum_t_norm, hamacher_product_t_norm from numpy import linspace domain = linspace(-1., 7., 8001) A1 = IT2FS_Gaussian_UncertMean(domain, [0., 0.2, 0.5, 1.]) A2 = IT2FS_Gaussian_UncertMean(domain, [1., 0.2, 0.5, 1.]) A3 = IT2FS_Gaussian_UncertMean(domain, [2., 0.2, 0.5, 1.]) A4 = IT2FS_Gaussian_UncertMean(domain, [3., 0.2, 0.5, 1.]) A5 = IT2FS_Gaussian_UncertMean(domain, [4., 0.2, 0.5, 1.]) A6 = IT2FS_Gaussian_UncertMean(domain, [5., 0.2, 0.5, 1.]) A7 = IT2FS_Gaussian_UncertMean(domain, [6., 0.2, 0.5, 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"]) M1 = meet(domain, A1, A2, min_t_norm) M2 = meet(domain, A2, A3, product_t_norm) M3 = meet(domain, A3, A4, lukasiewicz_t_norm) M4 = meet(domain, A4, A5, drastic_t_norm) M5 = meet(domain, A5, A6, nilpotent_minimum_t_norm) M6 = meet(domain, A6, A7, hamacher_product_t_norm) IT2FS_plot(M1, M2, M3,
[ 0.3, -0.3, 0.0], [ 0.2, -0.3, 0.0], [ 0.2, 0.0, 0.0]]) decisions = array([1, 0, 1, 0, 0, 1]) def error(p): myClassifier = Classifier(attributes, decisions, p) return myClassifier.error() mySolver= PyPSO(error, 5, 100, parametersGenerator, velocityGenerator) mySolver.solve() p = mySolver.best_known_position myClassifier = Classifier(attributes, decisions, p) IT2FS_plot(myClassifier.att1_s1, myClassifier.att1_s2, myClassifier.att1_s3) IT2FS_plot(myClassifier.att2_s1, myClassifier.att2_s2, myClassifier.att2_s3) IT2FS_plot(myClassifier.att3_s1, myClassifier.att3_s2, myClassifier.att3_s3) IT2FS_plot(myClassifier.deci_s1, myClassifier.deci_s2) print(myClassifier.error())
@author: arslan """ from pyit2fls import IT2FLS, IT2FS_Gaussian_UncertStd, IT2FS_plot, \ min_t_norm, max_s_norm, TR_plot, crisp from numpy import linspace domain = linspace(0., 1., 100) Small = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1, 1.]) Medium = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1, 1.]) Large = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1, 1.]) IT2FS_plot(Small, Medium, Large, legends=["Small", "Medium", "large"], filename="simp_ex_sets") myIT2FLS = IT2FLS() myIT2FLS.add_input_variable("x1") myIT2FLS.add_input_variable("x2") myIT2FLS.add_output_variable("y1") myIT2FLS.add_output_variable("y2") myIT2FLS.add_rule([("x1", Small), ("x2", Small)], [("y1", Small), ("y2", Large)]) myIT2FLS.add_rule([("x1", Medium), ("x2", Medium)], [("y1", Medium), ("y2", Small)]) myIT2FLS.add_rule([("x1", Large), ("x2", Large)], [("y1", Large), ("y2", Small)])
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"]) M1 = join(domain, A1, A2, max_s_norm) M2 = join(domain, A2, A3, probabilistic_sum_s_norm) M3 = join(domain, A3, A4, bounded_sum_s_norm) M4 = join(domain, A4, A5, drastic_s_norm) M5 = join(domain, A5, A6, nilpotent_maximum_s_norm) M6 = join(domain, A6, A7, einstein_sum_s_norm) IT2FS_plot(M1, M2, M3,
# -*- coding: utf-8 -*- """ Created on Wed May 15 02:40:21 2019 @author: arslan """ from pyit2fls import IT2FLS, IT2FS_Gaussian_UncertStd, IT2FS_plot, \ min_t_norm, max_s_norm, TR_plot, crisp from pyit2fls import IT2FS, trapezoid_mf, tri_mf from numpy import linspace import numpy as np #domain = linspace(0., 1., 100) domain = linspace(-1., 1., 100) ''' Small = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) Medium = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) Large = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(Small, Medium, Large, legends=["Small", "Medium", "large"], filename="asb(x1,x2)_ex_sets") S = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) M = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) L = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(S, M, L, legends=["S", "M", "L"], filename="y1_ex_sets") myIT2FLS = IT2FLS() myIT2FLS.add_input_variable("x1") myIT2FLS.add_input_variable("x2") myIT2FLS.add_output_variable("y1") #myIT2FLS.add_output_variable("y2")
[0.1, 0.5, 0.9, 0.8], ) Medium.plot(filename="Medium") Large = IT2FS( domain, tri_mf, [0, 0.5, 1., 1.], tri_mf, [0.1, 0.5, 0.9, 0.8], ) Large.plot(filename="Large") S = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) M = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) L = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(S, M, L, legends=["S", "M", "L"], filename="y1_ex_sets") myIT2FLS = IT2FLS() myIT2FLS.add_input_variable("x1") myIT2FLS.add_input_variable("x2") myIT2FLS.add_output_variable("y1") #myIT2FLS.add_output_variable("y2") myIT2FLS.add_rule([("x1", Small), ("x2", Small)], [("y1", S)]) myIT2FLS.add_rule([("x1", Small), ("x2", Medium)], [("y1", S)]) myIT2FLS.add_rule([("x1", Small), ("x2", Large)], [("y1", M)]) myIT2FLS.add_rule([("x1", Medium), ("x2", Small)], [("y1", S)]) myIT2FLS.add_rule([("x1", Medium), ("x2", Medium)], [("y1", M)]) myIT2FLS.add_rule([("x1", Medium), ("x2", Large)], [("y1", L)])
Tri = IT2FS(domain, tri_mf, [0.1, 0.5, 0.9, 1], tri_mf, [0.3, 0.5, 0.7, 0.7], check_set=True) RTri = IT2FS(domain, rtri_mf, [0.85, 0.2, 1], rtri_mf, [0.75, 0.1, 1.], check_set=True) LTri = IT2FS(domain, ltri_mf, [0.15, 0.8, 1], ltri_mf, [0.25, 0.9, 1.], 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")
#!/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")
Small2 = IT2FS_Gaussian_UncertStd(domain2, [2., 0.15, 0.05, 1.]) # Defining the Medium set for the input variable x1. Medium1 = IT2FS_Gaussian_UncertStd(domain1, [1.5, 0.15, 0.05, 1.]) # Defining the Medium set for the input variable x2. Medium2 = IT2FS_Gaussian_UncertStd(domain2, [2.5, 0.15, 0.05, 1.]) # Defining the Large set for the input variable x1. Large1 = IT2FS_Gaussian_UncertStd(domain1, [2., 0.15, 0.05, 1.]) # Defining the Large set for the input variable x1. Large2 = IT2FS_Gaussian_UncertStd(domain2, [3., 0.15, 0.05, 1.]) # Plotting the sets defined for the input variable x1. IT2FS_plot(Small1, Medium1, Large1, legends=["Small", "Medium", "large"]) # Plotting the sets defined for the input variable x1. IT2FS_plot(Small2, Medium2, Large2, legends=["Small", "Medium", "large"]) # Defining the Low set for the output variable y1 Low1 = IT2FS_Gaussian_UncertStd(domain3, [3., 0.1, 0.05, 1.]) # Defining the Low set for the output variable y2 Low2 = IT2FS_Gaussian_UncertStd(domain4, [4., 0.1, 0.05, 1.]) # Defining the High set for the output variable y1 High1 = IT2FS_Gaussian_UncertStd(domain3, [4., 0.1, 0.05, 1.]) # Defining the High set for the output variable y2 High2 = IT2FS_Gaussian_UncertStd(domain4, [5., 0.1, 0.05, 1.])
def u_dot(t): # return 0 a = 10 return (a if 1. < t < (1. + 1. / a) else 0) # %% Interval Type 2 Fuzzy PID Codes ... domain = linspace(-1., 1., 201) N = IT2FS_Gaussian_UncertStd(domain, [-1., 0.5, 0.1, 1.]) Z = IT2FS_Gaussian_UncertStd(domain, [0., 0.2, 0.025, 1.]) P = IT2FS_Gaussian_UncertStd(domain, [1., 0.5, 0.1, 1.]) IT2FS_plot(N, Z, P, legends=["Negative", "Zero", "Positive"], filename="delay_pid_input_sets") NB = IT2FS_Gaussian_UncertStd(domain, [-1., 0.1, 0.05, 1.]) NM = IT2FS_Gaussian_UncertStd(domain, [-0.5, 0.1, 0.05, 1.]) ZZ = IT2FS_Gaussian_UncertStd(domain, [0., 0.1, 0.05, 1.]) PM = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.1, 0.05, 1.]) PB = IT2FS_Gaussian_UncertStd(domain, [1., 0.1, 0.05, 1.]) IT2FS_plot(NB, NM, ZZ, PM, PB, legends=[ "Negative Big", "Negative Medium", "Zero", "Positive Medium",
min_t_norm, max_s_norm, TR_plot, crisp from numpy import linspace #domain = linspace(0., 1., 100) domain = linspace(-1., 1., 100) ''' Small = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) Medium = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) Large = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) ''' NS = IT2FS_Gaussian_UncertStd(domain, [-1., 0.15, 0.1]) NB = IT2FS_Gaussian_UncertStd(domain, [-0.5, 0.15, 0.1]) ZO = IT2FS_Gaussian_UncertStd(domain, [0., 0.15, 0.1]) PS = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) PB = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(NS, NB, ZO,PS,PB, legends=["NS", "NB", "ZO", "PS", "PB"], filename="simp_ex_sets") A1 = IT2FS_Gaussian_UncertStd(domain, [-1, 0.15, 0.1]) A2 = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) A3 = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(A1, A2, A3, legends=["A1", "A2", "A3"], filename="y1_simp_ex_sets") B1 = IT2FS_Gaussian_UncertStd(domain, [-1., 0.15, 0.1]) B2 = IT2FS_Gaussian_UncertStd(domain, [-0.25,0.15, 0.1]) B3 = IT2FS_Gaussian_UncertStd(domain, [-0.5, 0.15, 0.1]) B4 = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1]) B5 = IT2FS_Gaussian_UncertStd(domain, [0.25, 0.15, 0.1]) B6 = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1]) B7 = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1]) IT2FS_plot(B1, B2, B3,B4,B5,B6,B7, legends=["B1", "B2", "B3", "B4", "B5", "B6", "B7"], filename="y2_simp_ex_sets")