While the fuzzy logic had not attracted many researchers in the first years of its presentation, the usage of the fuzzy approaches in science and engineering applications has raised over time. By increasing the number of successful applications of this approach on real-world problems, research on analyzing and design of fuzzy systems has flourished . The key idea of the fuzzy systems is approximate reasoning, which is based on IF-THEN rules. A fuzzy IF-THEN rule is defined as a statement built of words, expressed by membership functions . Measuring the membership grade using crisp numbers yields type 1 fuzzy sets. But when the membership grade is also uncertain and is represented using fuzzy membership functions, the concept of type 2 and higher types of fuzzy sets are introduced . It must be noticed that, by increasing the type of a fuzzy set, the computational burden significantly grows. Therefore researchers have introduced the concept of interval type 2 fuzzy sets for decreasing the computational load, in which the secondary membership value is always considered to be equal to one .
Type-2 fuzzy systems are applied widely to solve engineering and industrial problems, which among them control of buck and boost DC-DC converters , coiler entry temperature prediction , levelling the cable-driven parallel mechanism , control of induction motor , and digital image filtering  can be mentioned. Similar applications of type 2 fuzzy systems are advancing rapidly. However, compared with type 1 fuzzy systems, type 2 fuzzy systems have been used very limitedly . Public access and use of an approach, derived from theoretical results, is mainly affected by the availability of software implementations.
There are some toolkits developed for utilizing type 2 fuzzy sets and systems in science and engineering applications. In , a new MATLAB toolbox for interval type 2 fuzzy logic systems is introduced. In addition to basic features for designing IT2FLSs, this toolbox includes a graphical user interface for construction, edition, and observation of the fuzzy systems. Also, the mentioned paper studies both educational and research sides of developing the toolbox. The results of the experiments, in addition to the effectiveness of the toolbox, indicate the technical improvement of the students who have used the tool. Another toolbox which is designed to be used with MATLAB, like the previous one, is presented in . In this toolbox, in addition to the graphic user interface for designing and editing fuzzy systems, a Simulink model is also presented which can be mentioned as its advantage. As an example of using the toolbox, in this paper, an IT2-Fuzzy PID controller is designed for controlling a system in the presence of time delay. Another Java-based fuzzy logic toolkit, named Juzzy, is presented in . Juzzy supports type 1, interval type 2 and general type 2 fuzzy logic systems. The aim of the developers of Juzzy toolkit is facilitating the application of fuzzy logic systems in real-world problems, along with improving accessibility to the type 2 fuzzy logic systems for academic purposes. Recently a new Python-based toolkit for automatically generating and analyzing data-driven fuzzy sets is developed and presented in . The introduced toolkit, fuzzycreator, provides many routines for creating conventional and non-conventional type 1, interval type 2 and general type 2 fuzzy sets from data. It must be noticed that the developed toolbox focuses on fuzzy sets rather than fuzzy systems.
Due to the increasing popularity of the Python programming language and its frequent use for scientific and engineering applications, the need for a tool for providing IT2FLSs support has been felt. To respond to this need, the PyIT2FLS toolkit is developed and presented in this paper. This toolkit provides many useful functions for creating and processing fuzzy sets and systems. There are two core classes, which the features of the toolbox are available through them, IT2FS and IT2FLS. The first one for modeling the fuzzy sets and the latter for the systems. It must be noticed that the ease of use was considered as the main criterion in the development of the toolkit. In the rest of the paper when a keyword refers to a function, variable or class it is written in italic form.
The rest of the paper is organized as follows. The second section consists of a brief discussion on the toolkit and how to use it. In Section 3, three examples of using the PyIT2FLS are provided. Finally, Section 4 presents some conclusions.
This section presents how to use the new developed Python toolkit, PyIT2FLS, for modeling and simulation of interval type 2 fuzzy systems. PyIT2FLS is developed to respond to the lack of an integrated tool for facilitating the use of IT2FLSs. This toolkit, which its development will not stop in this stage, will allow the users to apply IT2FL based methods for solving issues encountered in science and engineering problems. PyIT2FLS is based on well-known numeric library NumPy  and plotting library Matplotlib . It consists of two main classes, IT2FS for interval type 2 fuzzy sets and IT2FLS for interval type 2 fuzzy logic systems, and many utility functions concerning the interval type 2 fuzzy logic. As a starting point, we introduce some of the utility functions defined in the toolkit, which are used in creating interval type 2 fuzzy sets. These are general membership functions, which would be used as the lower membership function (LMF) and the upper membership function (UMF) for IT2FSs. Table 1
represents these functions with a brief description. All these functions have two inputs, vector-like inputindicating points from the domain which the function must be evaluated, and indicating the function’s parameters. It should be noted that the latter parameter must be a list, and for each function its items are described in its corresponding docstring.
|zero_mf||All zero membership function|
|singleton_mf||Singleton membership function|
|const_mf||Constant membership function|
|tri_mf||Triangular membership function|
|trapezoid_mf||Trapezoidal membership function|
|gaussian_mf||Gaussian membership function|
|gauss_uncert_mean_umf||UMF of Gaussian membership function with uncertain mean value|
|gauss_uncert_mean_lmf||LMF of Gaussian membership function with uncertain mean value|
|gauss_uncert_std_umf||UMF of Gaussian membership function with uncertain std. value|
|gauss_uncert_std_lmf||LMF of Gaussian membership function with uncertain std. value|
2.1 Interval type 2 fuzzy sets
The class IT2FS defines interval type 2 fuzzy sets by specifying the domain, UMF, parameters of UMF function, LMF, and parameters of LMF function. The first example in appendix shows how to define an IT2FS using aforementioned membership functions. The only constraint for using these functions is to choose the function parameters in such a way that for all points in the universe of discourse, be satisfied.
The set defined using the code is depicted in Figure. 1
. There are two conventional types of IT2FSs which can be defined easily using two other functions available in PyIT2FLS. In order to define Gaussian IT2FS with uncertain mean value and uncertain standard deviation value, users can calland functions, respectively. The parameters of the both functions are and . For the first function, the second parameter consists of the mean value center, mean value spread, and standard deviation and for the second function, the second parameter consists of the mean value, standard deviation center, and standard deviation spread (for both as lists). Each IT2FS in PyIT2FLS contains some parameters and functions which are indicated in Table 2 and Table 3, respectively. More detailed descriptions and instruction for each of them are available in docstrings.
|domain||Defines the universe of discourse|
|umf||Defines upper membership function|
|umf_params||Defines upper membership function parameters|
|lmf||Defines lower membership function|
|lmf_params||Defines lower membership function parameters|
|upper||Upper membership function values in the discrete universe of discourse|
|lower||Lower membership function values in the discrete universe of discourse|
|copy||Returns a copy of the IT2FS|
|plot||Plots the IT2FS in the universe of discourse|
The next function to be introduced is which plots a number of IT2FSs together in the same figure. The main inputs of this function are a number of IT2FSs, but title and legends can also be assigned. Furthermore if the user wishes to save the plotted figure in format, he/she can set the filename input variable. More detailed description and examples are available in docstrings.
2.2 T-norms, s-norms, join and meet
As basic operators in fuzzy calculations, t-norms and s-norms have special importance. PyIT2FLS by default contains two t-norm functions, and for minimum and product t-norms respectively, and a s-norm, for maximum s-norm. However, new t-norm and s-norm functions can be defined by users. In the standard form, these functions must have two array-like inputs for calculating t-norm or s-norm, element-wise on them. The next two main operators in type 2 fuzzy logic are meet and join operators which are defined by two functions with the same names, meet and join. The inputs of these operators are domain, first and second IT2FS, and norm operator. For the meet, norm operator must be a t-norm and for the join, norm operator must be a s-norm. The second code in the appendix shows how to use meet and join operators and plotting multiple sets together. The results are demonstrated in Figure 2.
2.3 Interval type 2 fuzzy logic systems
The most important part of the developed toolkit, the class IT2FLS, is prepared for modeling the interval type 2 fuzzy logic systems. Each IT2FLS has three parameters, inputs, outputs, and rules. There are five functions defined in IT2FLS class for utilizing it which are presented in Table 4. No construction parameters are needed when an IT2FLS is created. The input parameters of the functions for adding inputs and outputs are only the names. In order to define the rule base of the fuzzy system function is used. This function accepts two lists as input which the first one indicates antecedent part of the rule and the second one indicates conclusion part of the rule. Each list consists of tuples indicating the attachment of input variables to corresponding IT2FSs. Assume that a fuzzy type 2 IF-THEN rule be as below:
So this rule can be added to an IT2FLS named myIT2FLS as pseudo-code below:
In order to evaluate an IT2FLS for arbitrary inputs the evaluate function must be used. The inputs of this function are values of the system inputs as a dict, t-norm, s-norm, domain, and the type reduction algorithm and method. The default output of the evaluate function is depended on type reduction method and algorithm specified by the user and is described in details in docstrings. Let TR be an output dictionary for an IT2FLS with two type reduced outputs, and . In order to plot the type reduced set, the function can be used with the inputs domain, type reduced set, and if the user wants to save the figure, file name. Also, for calculating the crisp output, the function crisp can be used with the only input of type reduced set. The third code in the appendix section shows how to plot the and calculate the crisp output for the described case.
|add_input_variable||Adds a new input variable to IT2FLS|
|add_output_variable||Adds a new output variable to IT2FLS|
|add_rule||Adds a new rule to IT2FLS’s rule base|
|evaluate||Evaluates the IT2FLS with specific inputs|
|copy||Returns a copy of the defined IT2FLS|
2.4 Type reduction
A very important concept in type 2 fuzzy systems is type reduction algorithms and methods. Eight type reduction algorithms are provided in PyIT2FLS which are KM , EKM, WEKM, TWEKM [6, 25], EIASC, WM , BMM , LBMM , and NT . These type reduction algorithms can be used alongside the methods Centroid, Center of sets, Center of sum, Height, and Modified height. The functions corresponding with these algorithms and methods and their brief description are presented in Tables 5 and Table 6, respectively. These functions and methods are not called directly by the user most of the times, but their name is passed to the evaluate function of IT2FLS class as parameters, method and algorithm. The aforementioned tables also contain the names which the algorithms and methods are passed to the evaluate function. Docstrings are also available for a more detailed explanation of the instructions.
|EKM||Enhanced KM algorithm||EKM|
|WEKM||Weighted EKM algorithm||WEKM|
|TWEKM||Trapezoidal WEKM algorithm||TWEKM|
|EIASC||Enhanced IASC algorithm||EIASC|
|LBMM||BMM method edited by Li et al.||LBMM|
|Centroid||Centroid type reduction method||Centroid|
|Center of sets||Centr of sets type reduction method||CoSet|
|Center of sum||Center of sums type reduction method||CoSum|
|Height||Height type reduction method||Height|
|Modified height||Modified height type reduction method||ModiHe|
In this section three examples of using proposed PyIT2FLS are under study. First a simple example for using the toolkit to evaluate fuzzy IF-THEN rules as a fuzzy logic system is given. After that an example of using the toolkit for prediction of chaotic time series is given, in which the parameters of fuzzy system are determined using PSO algorithm to have minimum mean square error. And finally, the toolkit is used for modeling an interval type 2 fuzzy PID (IT2FPID) controller, and using it to control a time-delay linear system.
3.1 A simple example for using PyIT2FLS
Assume an IT2FLS with two inputs and two outputs. Let the universe of discourse in this example be the interval . Assume that three IT2FSs are defined in the universe of discourse which are Gaussian IT2FS with uncertain standard deviation values. Also let the rule base of the IT2FLS be as below:
With these assumptions, the codes for modeling this IT2FLS would be as provided in fourth subsection of the appendix. The discrete domain is defined as 100 equal-distance points in the interval . The sets defining the universe of discourse are constructed using the function IT2FS_Gaussian_UncertStd and are plotted. The inputs and , and the outputs and are added to the system. Based on defined IT2FSs and input and output variables, fuzzy IF-THEN rules are defined. Finally the output is evaluated and represented for .
The outputs generated by running this code are demonstrated in Figure. 3. IT2FS output for first and second outputs of the system are illustrated in Figures 2(a) and 2(b), respectively. Also type reduced outputs are shown in Figures 2(c) and 2(d).
3.2 Prediction of Mackey-Glass Chaotic Time Series
In this section, the results achieved by using the developed PyIT2FLS in a practical application, prediction of Mackey-Glass chaotic time series, is shown. The Mackey-Glass nonlinear time delay differential equation is defined as:
in which the parameters , , and are real numbers. In addition, shows the delayed value of variable at time . The response of the Mackey-Glass dynamic equation is demonstrated in Figure. 4 for parameters , , , and and random initial conditions.
The Mackey-Glass Equation alongside the logistic map, Lorenz equations, and Chen systems is known as a paragon of chaotic systems . Due to the chaotic behavior of the Mackey-Glass time series, it has been the subject of many scientific studies. These studies mainly concern the prediction of time series [29, 8] and the synchronization of chaotic systems [19, 20].
Let indicate the time series, in order to predict the Mackey-Glass time series using IT2FLS, three inputs are considered which are consecutive samples , , and . Assume that inputs are named as A, B, and C. Each input in its universe of discourse is expressed by three IT2FSs, which can be shown by indices 1 to 3 (as an example for the input A there will be three sets , , and ). The output of system, named O, is and is expressed using three IT2FSs, , , and . All the fuzzy sets are Gaussian IT2FS with uncertain standard deviation values. The rule base of the system is demonstrated in Table 7. All the parameters of the fuzzy sets are selected by PSO algorithm to have minimum Mean Square Error (MSE) in prediction. In this step, 100 samples are used for optimizing the selected parameters. Also the prediction is repeated on an other 100 samples in order to guarantee the performance of the IT2FLS. The result of prediction, real value of time series and absolute error are illustrated in Figure 4(a). Further more the convergence diagram of the PSO algorithm is demonstrated in Figure 4(b). The codes used for simulating this example are openly accessible over the toolkit’s GitHub page.
3.3 Interval Type 2 Fuzzy PID Controller for Time Delay Linear System
In this section in order to show the generality of the proposed toolkit, it is used to model an IT2FPID controller. It must be noted that this case study is adopted from . Let’s consider the transfer function of the system under study as below:
And let the block diagram representation of the overall system be as illustrated in Figure. 6.
As it can be seen in Figure. 6, the inputs of the IT2FPID are scaled verions of the error signal () and its derivative (). For each input there is three IT2FSs, Negative (N), Zero (Z), and Positive (P). The single output of the IT2FPID is used with scaling factors for achieving the proportional and integral terms coefficients. The output is demonstrated using five IT2FSs, Negative Big (NB), Negative Medium (NM), Zero (Z), Positive Medium (PM), and Positive Big (PB). All input and output sets are Gaussian ones with uncertain standard deviation. Also, the universe of discourse is defined as the interval . Input and output sets are illustrated in Figures 6(a) and 6(b), respectively.
The IT2FLS is constructed using 9 rules which are shown in Table. 8.
Parameters of the nominal system are set as , , and . In order to study the effect of parameters uncertainty on the controller’s performance, two more parameter settings are considered; , , (Perturbed System-1) and , , (Perturbed System-2). The scaling factors of the IT2FPID are set and fixed as , , , and . The performance of the designed control system is measured based on overshoot, settling time, and Integral Time Absolute Error (ITAE) values. The step response of the systems are illustrated in Figure. 8, and the performance measures are reported in Table. 9. As it can be seen, interval type 2 fuzzy logic system improves the robustness of the system response faced with system parameters perturbation. The simulations are done with multiple type reduction algorithms alongside with Centroid method. The results show that WM and BMM type reduction algorithms demonstrate better performance facing with control problems.
In this paper a new Python toolbox for utilizing interval type 2 fuzzy logic systems is presented. This toolbox facilitates the use of IT2FLSs in practical scientific and engineering applications. How to use this library and its features are briefly described. Also, several examples are included for better understanding. Prediction of time series is one of the most common applications of fuzzy systems. PyIT2FLS used to predict the chaotic Mackey-Glass time series. As the results show, the presented toolbox is able to be used in complex application of IT2FLSs. The development of the provided toolbox here is not over, but will continue to cover a wider variety of systems, methods and applications. It should be noted that the developers of the PyIT2FLS are ready to receive comments and suggestions about the toolkit and possible bug reports. The PyIT2FLS is openly accessible on the GitHub page: https://github.com/Haghrah/PyIT2FLS.
Appendix: Python codes
Simple python codes used in the paper for generating outputs are provided here. The codes for the two last complete examples are accessible in PyIT2FLS GitHub page.
Defining an IT2FS using PyIT2FLS
from pyit2fls import IT2FS, trapezoid_mf, tri_mf from numpy import linspace
mySet = IT2FS(linspace(0., 1., 100), trapezoid_mf, [0, 0.4, 0.6, 1., 1.], tri_mf, [0.25, 0.5, 0.75, 0.6])
Plotting the meet and join of IT2FSs
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]) B = IT2FS_Gaussian_UncertMean(domain, [0.33, 0.1, 0.1]) C = IT2FS_Gaussian_UncertMean(domain, [0.66, 0.1, 0.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”)
Plotting the type reduced output of IT2FLS and calculating the crisp output
TR_plot(domain, TR[”y1”], filename=”y1_tr”) print(crisp(TR[”y1”]))
TR_plot(domain, TR[”y2”], filename=”y2_tr”) print(crisp(TR[”y2”]))
Full example of defining and using an IT2FLS
from pyit2fls import IT2FLS, IT2FS_Gaussian_UncertStd, IT2FS_plot, min_t_norm, max_s_norm, TR_plot from numpy import linspace
domain = linspace(0., 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=”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)])
it2out, tr = myIT2FLS.evaluate(”x1”:0.9, ”x2”:0.9, min_t_norm, max_s_norm, domain, method=”Centroid”)
it2out[”y1”].plot(filename=”y1_out”) TR_plot(domain, tr[”y1”], filename=”y1_tr”)
it2out[”y2”].plot(filename=”y2_out”) TR_plot(domain, tr[”y2”], filename=”y2_tr”)
-  (2012) A type-2 fuzzy logic controller design for buck and boost dc–dc converters. Journal of intelligent manufacturing 23 (4), pp. 1023–1034. Cited by: §1.
-  (2008) Application of type-2 fuzzy logic controller to an induction motor drive with seven-level diode-clamped inverter and controlled infeed. Electrical Engineering 90 (5), pp. 347–359. Cited by: §1.
-  (2008) Stability analysis of type-2 fuzzy systems. In 2008 IEEE International Conference on Fuzzy Systems (IEEE World Congress on Computational Intelligence), pp. 947–953. Cited by: §2.4.
-  (2013) Computational intelligence software for interval type-2 fuzzy logic. Computer Applications in Engineering Education 21 (4), pp. 737–747. Cited by: §1.
Inverse control of cable-driven parallel mechanism using type-2 fuzzy neural network. Acta Automatica Sinica 36 (3), pp. 459–464. Cited by: §1.
-  (2008) Improved iterative algorithm for computing the generalized centroid of an interval type-2 fuzzy set. In NAFIPS 2008-2008 Annual Meeting of the North American Fuzzy Information Processing Society, pp. 1–5. Cited by: §2.4.
-  (2010) Mackey-glass equation. Scholarpedia 5 (3), pp. 6908. Cited by: §3.2.
-  (2016) Chaotic time series prediction via artificial neural square fuzzy inference system. Expert Systems with Applications 55, pp. 461–468. Cited by: §3.2.
-  (2007) Matplotlib: a 2d graphics environment. Computing in science & engineering 9 (3), pp. 90. Cited by: §2.
-  (1999) Type-2 fuzzy logic systems. IEEE transactions on Fuzzy Systems 7 (6), pp. 643–658. Cited by: §2.4.
-  (2015) An open source matlab/simulink toolbox for interval type-2 fuzzy logic systems. In 2015 IEEE Symposium Series on Computational Intelligence, pp. 1561–1568. Cited by: §1, §3.3.
-  (2010) Stability analysis of sirms based type-2 fuzzy logic control systems. In International Conference on Fuzzy Systems, pp. 1–7. Cited by: §2.4.
-  (2017) Fuzzycreator: a python-based toolkit for automatically generating and analysing data-driven fuzzy sets. In 2017 IEEE International Conference on Fuzzy Systems (FUZZ-IEEE), pp. 1–6. Cited by: §1.
-  (2014) Introduction to type-2 fuzzy logic control: theory and applications. pp. 43. Cited by: §1.
-  (2010) Modelling and control of coiling entry temperature using interval type-2 fuzzy logic systems. Ironmaking & Steelmaking 37 (2), pp. 126–134. Cited by: §1.
-  (2008) Towards an efficient type-reduction method for interval type-2 fuzzy logic systems. In 2008 IEEE International Conference on Fuzzy Systems (IEEE World Congress on Computational Intelligence), pp. 1425–1432. Cited by: §2.4.
-  (2006) A guide to numpy. Vol. 1, Trelgol Publishing USA. Cited by: §2.
-  (2018) The mackey-glass models, 40 years later. Biomath Communications 5 (2), pp. 140–158. Cited by: §3.2.
-  (2006) Chaos synchronization between the mackey–glass systems with multiple time delays. Chaos, Solitons & Fractals 29 (4), pp. 854–861. Cited by: §3.2.
-  (2017) Synchronization of time-delayed systems with discontinuous coupling. Kybernetika 53 (5), pp. 765–779. Cited by: §3.2.
-  (2018) Adaptive type-2 fuzzy approach for filtering salt and pepper noise in grayscale images. IEEE Transactions on Fuzzy Systems 26 (5), pp. 3170–3176. Cited by: §1.
-  (2004) Fuzzy control systems design and analysis: a linear matrix inequality approach. pp. 5. Cited by: §1.
-  (2013) Juzzy-a java based toolkit for type-2 fuzzy logic. In 2013 IEEE Symposium on Advances in Type-2 Fuzzy Logic Systems (T2FUZZ), pp. 45–52. Cited by: §1.
-  (1997) A course in fuzzy systems and control. Vol. 2, pp. 2–3. Cited by: §1.
-  (2008) Enhanced karnik–mendel algorithms. IEEE Transactions on Fuzzy Systems 17 (4), pp. 923–934. Cited by: §2.4.
-  (2011) Comparison and practical implementation of type-reduction algorithms for type-2 fuzzy sets and systems. In 2011 IEEE International Conference on Fuzzy Systems (FUZZ-IEEE 2011), pp. 2131–2138. Cited by: §2.4.
-  (2002) Uncertainty bounds and their use in the design of interval type-2 fuzzy logic systems. IEEE Transactions on fuzzy systems 10 (5), pp. 622–639. Cited by: §2.4.
-  (1975) The concept of a linguistic variable and its application to approximate reasoning—i. Information sciences 8 (3), pp. 199–249. Cited by: §1.
-  (2017) A prediction method based on wavelet transform and multiple models fusion for chaotic time series. Chaos, Solitons & Fractals 98, pp. 158–172. Cited by: §3.2.