Juzzy Constrained: Software for Constrained Interval Type-2 Fuzzy Sets and Systems in Java

Constrained interval type-2 (CIT2) fuzzy sets are a class of type-2 fuzzy sets that has been recently proposed as a way to extend type-1 membership functions to interval type-2 (IT2) while keeping a semantic connection between the IT2 fuzzy set and the concept it models. Recent work has shown how their mathematical properties can be used to design CIT2 fuzzy logic systems that are able to provide explanations for their outputs. Although the CIT2 representation can be a valuable alternative to the IT2 one, no software library for their implementation is available for the research community. The aim of this paper is to introduce a new Java library, Juzzy Constrained, that has been developed as an extension of the popular type-1 and type-2 Java toolkit Juzzy, adding support for CIT2 sets and systems. Throughout the paper, the main classes and the structure of the new library are described, together with a working example that illustrates how to build a CIT2 fuzzy system from scratch and how it can be used to produce explanations for the output.


I. INTRODUCTION
The use of interval type-2 (IT2) [1] fuzzy sets and systems has rapidly grown over time. The development of practical and fast defuzzification algorithms (e.g. [2]) together with the increase in performance [3]- [5], led to the development of IT2 fuzzy logic systems (FLS) in controller design [6], classification and regression [7], modeling of data and words [8].
More recently, fuzzy logic has been adopted to build interpretable systems: the use of the rule-base structure together with the partitioning of the input and output variables with fuzzy sets (FSs) with a clear semantic meaning (i.e. a linguistic label) allow for the design of FLSs that show an understandable decision process. In the context of explainable artificial intelligence (XAI) [9], many T1 FLSs have been produced with the ability of providing clear explanations for each of the classifications produced by the system [10]- [12]. Implementing IT2 FLS with the same characteristics, however, has proven to be more challenging. In fact, although T1 and IT2 FLS share the same rule-based structure, there is a difference in how the output of the system is produced. As discussed in other research works [13], [14], the use of centroid defuzzification procedures like the Karnik-Mendel algorithm (KM) [2], makes it hard to find a direct link between the endpoints of the interval centroid and the rule-base of the FLS as well as producing a detailed explanation like for T1 FLSs. To ensure a higher level of interpretability when going from T1 to IT2 and type-2 (T2) membership functions, constrained type-2 (CT2) [15] and constrained interval type-2 (CIT2) [13] have been introduced. By the imposition of additional mathematical constraints on the footprint of uncertainty (FOU) and the shape of the embedded sets (ES), they establish a standard process to "extend" T1 fuzzy sets to IT2 ones while keeping a strong semantic relation between the constrained set and the concept it models. It has also been shown [13], [14] how the additional constraints make it easier to explain the interval centroid produced by CIT2 FLS thanks to the use of embedded sets with a "meaningful" shape. Therefore, these properties make CIT2 FLSs a valuable alternative to IT2 FLSs in contexts in which producing explainable outputs is important (e.g. XAI applications).
This new class of fuzzy sets has recently started to be explored, with a particular focus on CIT2 fuzzy sets. Although many practical applications of CIT2 FLS have already been shown [13], [14], there is no library that can be used by the research community to easily deploy CIT2 FLS. The aim of this paper is to present the first software library, named Juzzy Constrained, that implements CIT2 fuzzy sets and systems and also to collect constructive feedback on the CIT2 representation from the research community. Written in Java, Juzzy Constrained is an extension of the already wellknown Java library Juzzy [16] and follows its conventions to facilitate its use for developers. The new toolkit makes possible the design of CIT2 FLS using the defuzzification algorithms proposed in [13], [14] and is capable of using the constrained representation to provide human-readable explanations for the constrained interval centroids produced by the systems.
The rest of the paper is organized as follows: after a short description of other software libraries focused on T1 and T2 fuzzy logic (Sec. II), CIT2 fuzzy sets will be briefly described, highlighting their main characteristics and the motivations behind their introduction (Sec. III). Then, the new library Juzzy Constrained will be analyzed, describing its structure, its main classes and its relation with Juzzy (Sec. IV). Finally, a working example will be presented: a CIT2 FLS will be built from scratch, with the help of code snippets to facilitate the understanding of the usage of the toolkit (Sec. V).

II. RELATED WORKS
Many tools for the development of T1 and T2 FLS have been released over the years. One of the most famous ones is the Fuzzy Logic Toolbox for MATLAB 1 . It allows developers to design T1 fuzzy sets and systems through a set of functions or the use of a graphical interface. The sets built with the toolbox, the control surfaces and the rules can then be easily visualized. Similar toolboxes that include IT2 fuzzy sets have been proposed in [17]- [20].
Software libraries for different programming languages have also been released. In [21] a Python toolkit for the automatic generation of T1, IT2 and T2 fuzzy sets from data has been presented; [22], instead, describes a software library in R for the modelling of T1, IT2 and T2 FLS that also includes functions for the graphical visualization of fuzzy sets and control surfaces.
Software for the creation of fuzzy systems has also been included in famous suites for machine learning such as KEEL [23] and Weka [24]. Both offer various methods to learn fuzzy rules and sets from data (e.g. with the use of genetic algorithms) and to perform fuzzy clustering.
After the introduction of the IEEE Standard for Fuzzy Markup Language for the definition of fuzzy sets and systems in a "human-readable and hardware independent way" [25], new software libraries adhering to the novel standard have been developed such as JFML [26] and VisualJFML [27].

A. Juzzy
Juzzy Online [28], is a toolkit for the design, execution and sharing of T1 and T2 fuzzy sets and systems through the use of an online dashboard that is usable with no knowledge of programming.
A Java version of the same tool has been released. Juzzy [16] is a library for the implementation of T1, IT2 and T2 fuzzy sets and systems. It is written in Java, it is opensource and available online at http://juzzy.wagnerweb.net/, http://www.lucidresearch.org/software.html and on the Maven Central Repository 2 . The toolkit implements T2 fuzzy sets with the zSlices representation [29] and also supports multicore execution of the code.

III. CONSTRAINED INTERVAL TYPE-2 FUZZY SETS
Constrained type-2 (CT2) and constrained interval type-2 (CIT2) fuzzy sets were proposed [15] as a new way to model vague concepts using T2 and IT2 fuzzy sets starting from a T1 set modeling the same word or concept. The rest of the paper and the library presented here will focus only on CIT2 since most of the research work in this area [13], [14], [30] is focused on CIT2 only. CIT2 fuzzy sets start from a T1 fuzzy set, called generator set (GS), that models a given concept. The uncertainty in this case, is represented by the fact that the exact location on the x-axis of the GS is not known. This situation may arise, for example, when different people are asked to place the fuzzy set modeling the label medium height on the x-axis, as shown by the Gaussian MFs in black in Fig. 1  This uncertainty causes a blurring around the GS that determines the footprint of uncertainty (FOU). The constrained approach proposed a standard way of carrying out this operation: • The "width" of the blurring is modeled as an interval (in the continuous case) and called displacement interval. • The FOU of the generated CIT2 fuzzy set is defined as the points covered by the translation along the x-axis of the GS within the displacement interval (e.g. the shaded gray area in Fig. 1). • Within this FOU, the only embedded sets that are considered acceptable (acceptable embedded sets, AES) are the ones that have the same shape as the GS, i.e. the ones that represent a valid translation of the GS within the displacement interval. Only the AES are processed in operations that work with the embedded sets.
For more details, see [13]. Processing only AESs rather than all the embedded sets makes a significant difference in the explainability of some fuzzy operators, as analyzed in [13]. Specifically, for the centroid defuzzification, the endpoints of the constrained interval centroid are determined by acceptable embedded sets with a meaningful shape. As shown in Sec. V, the properties of these AES can be used to produce humanreadable explanations for the system output while providing both a formal and intuitive understanding of how they have been obtained. Therefore, the CIT2 modeling, represents a valuable alternative to IT2 systems in all the cases in which it is important to understand the decision process of the classification model (e.g. in the XAI field). The Java library for CIT2 fuzzy sets and systems has been conceived as an extension of Juzzy: it makes use of its T1 membership functions to define the generator sets of CIT2 fuzzy sets and also adopts some of its conventions (e.g. for the creation of rules) and utility classes (such as Input and Output to model the input and output variables of a CIT2 FLS). Therefore, for Juzzy Constrained to work, also Juzzy must be included in the given Java project.
The source-code released under the BSD 3-Clause license, the documentation and the JAR archive of Juzzy Constrained are freely available on GitHub at https://github.com/PasqualeDAlterio/JuzzyConstrained and http://www.lucidresearch.org/software.html. The library is also available on the Maven Central Repository and can be quickly included in any Java Maven project (for more information, see the GitHub page).

A. Library structure
The packages included in the library are shown in Fig. 3. The package CIT2_Generator includes the T1 membership functions that are usable as generator sets. Triangular, Gaussian, Gauangle and trapezoidal membership functions are currently supported. Each one of them is a wrapper of the correspondent T1MF defined in Juzzy; the main difference between them is that each of the CIT2_Generator must implement a method that returns all the points of local (and global) maximum and a method that returns all points of local minimum of the membership function, as requested by the CIT2_Generator interface. These two methods are needed to determine the upper and lower membership functions of the CIT2 fuzzy set, as discussed in Theorem 1, in the Appendix. The CIT2 package is the core of the library: it implements CIT2 fuzzy sets and systems using the same style used by Juzzy. Once the sets have been defined they can be used to build antecedents and consequents that are then organized in CIT2_Rule. Once the rules are created, they can be organized in a CIT2_Rulebase to implement a FLS.
CIT2_Explanations contains all the objects that are used in the generation of the explanation of the output of a CIT2_Rulebase. They mostly focus on organizing and formatting information in a humanly readable piece of text in order to show how the endpoints of the constrained centroid have been obtained. The remaining packages offer additional utilities and tools that were not originally implemented in Juzzy but are useful in the Juzzy Constrained context (e.g. an IT2 fuzzy set where the upper and lower bounds can have arbitrary shape or a T1 fuzzy set modeling the result of the inference operation). Fig. 2 shows the class diagrams with all the main classes used in Juzzy Constrained and their relation with the original classes in Juzzy. Each CIT2 fuzzy set, to be instantiated, needs a CIT2_Generator. This interface extends the T1MF_Interface defined in Juzzy, since the generator set is a T1 set, and requires the implementation of three additional methods: getMaxPoints, getMinPoints and shiftFunction. The first two, as described earlier in this section, are needed to determine the boundary functions of the generated CIT2 fuzzy; the shifting method, instead, is needed to generate the acceptable embedded sets: since they are translations along the x-axis of the generator set, this method takes a real number value as an argument and returns a new T1 membership function representing the generator set shifted by value. Additionally, since CIT2 fuzzy sets are a special case of IT2 fuzzy sets, i.e. they have been obtained by adding a set of additional mathematical constrained to the original IT2 definition, the class CIT2 extends the Juzzy abstract class IntervalT2MF_Prototype.
The generator sets implemented in the library extend CIT2_Generator_Prototype, i.e. an abstract class that already implements some functionalities that are used by all the generators provided. To add a new generator membership function, it is only required to implement the CIT2_Generator interface. This operation, as it will be shown in Sec. V, is straightforward for all the widely used T1 membership functions.
All the classes related to the the construction of a rule and a rule-base follow the same conventions used in Juzzy, making them easy to work with for the developers that are already used to the T1, IT2 and T2 rule-bases of the original library.

B. Defuzzification algorithms, other features and limitations
The toolkit provides two algorithms for the defuzzification of the output of a CIT2 FLS. The first one, implemented by the method sampleCentroid in the class CIT2_Rulebase, is based on the sampling approach proposed in [13], itself an adaptation for CIT2 sets of the sampling method for T2 fuzzy sets [31]. Since the extensive computation of the centroid by processing all the acceptable embedded sets has a prohibitive cost (similarly to what happens with "standard" T2 fuzzy sets) and each of these embedded sets only gives a small contribution to the final result, the idea is to calculate an approximation by sampling a subset of the acceptable embedded sets and use only them to compute the constrained centroid.
The other defuzzification algorithm included in Juzzy Constrained is the one presented in [14], based on the concept of switch indices instead of the switch points used by the KM procedure for IT2 fuzzy sets [2]. This approximation method is faster than the sampling one as it uses the properties of CIT2 fuzzy sets to quickly identify the small subset of acceptable embedded sets that will be used to determine the constrained centroid. For more details about this algorithm, please refer to [14]. This approach can also be used to produce humanreadable explanations for CIT2 FLSs as shown in [32] and in Sec. V.
In addition to the methods implemented in Juzzy for the visualization of T1 and IT2 fuzzy sets, Juzzy Constrained integrates the popular Java graphical library JFreeChart 3 . This 3 http://www.jfree.org/jfreechart/ represents a more flexible way of building plots, since they are easily and widely customizable, while also giving the opportunity of better highlight the FOUs of the CIT2 and IT2 fuzzy sets, as shown in Fig. 4.
Being currently still under development, Juzzy Constrained has some limitations. Specifically, CIT2_Rule only implements the and operator in the antecedent composition and does so with the min T-Norm. In addition to that, each rule can currently has only one consequent. At the moment, this limitation can be overcome by replacing a rule with n consequents with n replicas of the rule, one per consequent. In future works, we plan on expanding the library by adding the support to multiple-consequent rules and more antecedent connectors.

V. APPLICATIONS AND EXAMPLES
This section will show how Juzzy Constrained can be used in practice to develop CIT2 FLS, starting from the creation of CIT2 fuzzy sets and then illustrating how they can be put together to make rules and rulebases.
The example analyzed in this paper is the tipping problem. This system has been chosen for its simplicity and not to show the full potential of CIT2 FLSs. A more thorough analysis of the advantages of the use of CIT2 FLSs and case studies on real world datasets can be found in [32]. The tipping problem has the following structure: it has 2 input variables, food and service, and the goal is to use them to determine the adequate percentage to give as tip.
The first thing to do, is to instantiate the generator sets. Their creation is identical to the creation of T1 fuzzy sets in Juzzy. Here there is an example of how the generator sets for the service membership functions can be created. With the generator sets, it is possible to create CIT2 fuzzy sets. In addition to the generator sets, also the displacement intervals need to be specified. They determine how "wide" the shifting and therefore the FOU will be. In the example below, the positive shifting values shifting_size_2 is used to generate the displacement interval [-shifting_size_2, shifting_size_2]. The definition of the input and output variables, is taken from Juzzy since it uses the same Input and Output objects.
Input food = new Input("Food Quality", new Tuple(0,10)); Input service =new Input("Service Level", new Tuple(0,10)); Output tip = new Output("Tip", new Tuple(0,30)); The partitioning of the variables can then be plotted using JFreeChart as shown below. The results of this operation for the food, service and tip are shown respectively in Fig. 4, Fig.  5 and Fig. 6  Once the CIT2 fuzzy sets have been defined, they can be paired with the input and output variables to define the antecedents and the consesequents that will be used in the rulebase. In this case, Juzzy Constrained follows the same conventions used by Juzzy, making the creation of CIT2_Antecedent and CIT2_Consequent very similar to the creation of IT2 antecedents and consequents in the original library. Once the antecedents and consequents have been defined, they can be put together to create the rulebase. Again, the initialization of a CIT2 rulebase is very similar to the creation of T1 and IT2 rulebases in Juzzy. After the input values are set, there are two algorithms that can be used to do the inference and defuzzify the result: the sampling strategy [13] and the switch index method [14]. In the first case, the algorithm can be executed invoking the method rulebase.samplingDefuzzification(50) where 50 is the number of samples used to compute the constrained centroid. The function returns a Tuple representing the centroid.
food.setInput(7); service.setInput(8); Tuple constrained_centroid_sampling= rulebase.samplingDefuzzification(50); Tuple constrained_centroid_si= rulebase.switchIndexDefuzzification(100); ExplainableCentroid result= rulebase.explainableDefuzzification(100); The switch index approach, instead, can be used in two different ways: using the method rulebase.switchIndexDefuzzification(100) where 100 is the level of discretization used to defuzzify the acceptable embedded sets, the library returns a Tuple containing the value of the constrained centroid, just like in the sampling method case; the method rulebase.explainableDefuzzification(100), instead, returns the constrained centroid and the explanation for its generation in an ExplainableCentroid object.
As already discussed in other research works [13], [14], the properties of CIT2 fuzzy sets can be used to link the endpoints of the centroid to the specific acceptable embedded sets that Figure 7. FOU obtained from the inference (on the left) and the acceptable embedded sets determining the endpoints of the constrained centroid (on the right) generated them. They can then be used to determine which rules and input values led to the creation of the constrained interval centroid, in order to create a human-readable explanation. The selected acceptable embedded sets also have an interpretable structure: the consequent membership functions that contributed to their generation are clearly visible and so are the firing strengths of the rules they belong to (i.e. the heights at which they have been "truncated"). For other IT2 defuzzification procedures like the KM one, on the other hand, there is no guarantee that the chosen embedded sets will have any meaningful shape nor that it is possible to link them directly to the rules to produce an explanation. The ability to provide interpretable results when computing the constrained interval centroid is one of the reasons why CIT2 fuzzy sets can represent a valuable alternative to IT2 fuzzy sets in the context of XAI.
Once the ExplainableCentroid object is obtained, the acceptable embedded sets determining the constrained centroid can be plotted as shown below, together with the fired FOU. The plots for this example are show in Fig. 7. Juzzy Constrained currently supports 4 types of generator sets: Gaussian, Gauangle, triangular and trapezoidal. To add additional shapes, it is necessary to define a new class that implements the CIT2_Generator interface. The new class needs to provide methods that return the points of minimum and maximum of the membership function (so that the FOU of the CIT2 fuzzy set can be determined, see Theorem 1, in the Appendix) and a method for the shifting of the generator set (to generate the acceptable embedded sets).
Although implementing the methods that determine the points of minimum and maximum may seem challenging, it is relatively easy for many shapes. In the code snippet below, the implementation of these method is shown for the trapezoidal membership function.  The minimum and maximum points are stored in Interval objects which store generic intervals of the form [a, b]. The reason why intervals are used rather than points is that in some membership functions the points of minimum or maximum are infinite and all within a given interval. For example, in the case of a trapezoidal membership function, the points of maximum are all the points that make the shorter base, i.e. all the points in the segment BC. The minimum points, instead, are only A and B; in this case the Interval object is initialized using a single value a, representing the interval [a, a].
In other functions, the points of local minimum or maximum may not exist. For example, the Gaussian shape does not have any points of local minimum. In that situation, the getMinPoints() method can return a null value.

VI. CONCLUSION
In this paper, the new open-source library Juzzy Constrained has been presented. This toolkit, written in Java, has been developed as an extension of the fuzzy library Juzzy (for type-1 and type-2 fuzzy logic) and adds the support to constrained interval type-2 (CIT2) fuzzy sets and systems. This new class of fuzzy sets represents a useful alternative to the standard interval type-2 representation in the contexts in which a high level of interpretability is needed. Through the addition of some mathematical constraints, it ensure that a meaningful connection is kept between the shape of the footprint of the uncertainty, the embedded sets and the concept the CIT2 set is modeling. In the literature, it has also been shown how these properties can be used to produce explainable systems by processing only embedded sets with a meaningful shape for the determination of the interval centroid.
The paper demonstrates the library and showcases the properties and utility of CIT2 models using a worked, practical example, clearly highlighting the advantages of CIT2 FLSs from an XAI point of view.
The toolkit presented here, is the first one to support CIT2 fuzzy sets and systems. The aim of this paper is therefore to present the new library to the research community and also to receive feedback on the project and CIT2 fuzzy sets in general.
The structure of the library, its main classes and the defuzzification algorithms provided have been discussed, while in Sec. V a CIT2 fuzzy logic system is built from scratch, with the help of code snippets to facilitate the understanding of how the toolkit can be used.
Being still under development, the library has some limitation such as the fact that rules only support a single consequent or that the antecedents can only be connected using the and operator. In future works, we plan on improving these aspects, adding rules with multiple consequents and different connectors for the antecedents as well as making the library compliant with the fuzzy markup language.