Python library for interval-valued fuzzy inference

Uncertainty is an essential feature of many concepts, data sets, and operations encountered in various applications related to computer science and engineering, and medical diagnostics. This paper introduces an extension to the Simpful library, enhancing it with capabilities for interval-valued fuzzy sets (IVFSs) and generalized fuzzy inference. Addressing the need for comprehensive uncertainty modeling in various applications, this extension offers intuitive definitions and operations for interval-valued fuzzy sets, facilitating advanced reasoning in uncertain environments.


Motivation and significance
Solving real-world problems often relies on the capability of the language of representation, or logic, to handle imperfect, inaccurate, or ambiguous information.Fuzzy logic and fuzzy sets [1] offer formal inference tools for dealing with imprecise information.By incorporating interval-valued fuzzy sets [2] into the rules model, we can obtain formal tools to enhance reasoning by modeling uncertain information, also known as generalized fuzzy inference systems.
Our work is motivated by the need to apply interval-valued fuzzy inference in various applications, particularly for classifying uncertain data -a task of significant importance.For example, in cases where uncertainty stems from missing data, developing new methods becomes essential to obtain more effective results.In our case, we address uncertain data represented by Interval-Valued Fuzzy Sets (IVFSs), where intervals represent uncertain data from an epistemic perspective.
Our library can be easily integrated into Python based projects via pip installations (Python Package Index (PyPI)) and is publicly https://doi.org/10.1016/j.).
Hence, we propose an extension of the Simpful library [3], called the Interval-Valued Fuzzy Inference System (IFIS).Simpful is a universal and user-friendly Python library designed for defining, analyzing, and interpreting fuzzy inference systems.Our extended and modified library facilitates programming applications in an uncertain environment.In many decision-making situations encountered during real problem-solving, interval inference processes and systems are necessary.Consequently, the implementation of a comprehensive library supporting these systems becomes imperative, which is the aim of our work.
IFIS overcomes the challenges and limitations associated with modeling uncertainty in fuzzy reasoning.An essential concept offered by the library is the ability to use inputs in the form of interval values, which represent measurements within certain limits, with known measurement error, or subject to fluctuations and uncertainty.Moreover, our library distinguishes itself from others available in the market by offering a wide range of interval operations, including interval aggregation operators or orders.
The area of application of the proposed software is multi-criteria decision-making, in particular in supporting a healthy society [4], medicine [5], economics predictions [6], or sport analytics [7].

Related work
This section provides an overview of existing tools and libraries related to interval-valued fuzzy logic and inference.Detailed information about software tools dealing with fuzzy logic and reasoning can be found in Simpful and in other sources [8].However, in this section, we will discuss some key tools and libraries connected specifically to interval-valued fuzzy logic and inference.
Various tools have been developed for interval-valued fuzzy inference, catering to different tasks and programming languages.We provide a brief overview and description of some of these toolkits documented in the literature.
Fuzzycreator [9] is an open-source Python-based toolkit that allows the creation and analysis of conventional and non-conventional type-1, interval type-2, and general type-2 fuzzy sets from data.It includes tools and measures for comparing and evaluating the similarity and distance between fuzzy sets.
SyFSeL [10] (Synthetic Fuzzy Set Library) is an open-source Pythonbased library that automatically generates synthetic fuzzy sets with specified characteristics and types.Users can adjust parameters to emulate real data, and the generated fuzzy sets can be exported for use in other fuzzy system software.
Perceptual Computing (Per-C) [11] is an open-source Python library that utilizes type-2 fuzzy sets for modeling words in the Computing With Words (CWW) paradigm.The CWW methodology aims to design intelligent systems that make decisions by manipulating linguistic information, similar to human reasoning.Type-2 fuzzy sets enable better representation of uncertainty in linguistic semantics for various problems.
Fuzzy Logic Toolbox for Matlab supports two types of inference systems, Mamdani and Sugeno systems.Mamdani fuzzy inference was first introduced as a method for creating a control system by synthesizing a set of linguistic control rules obtained from experienced human operators.The defuzzification process for a Sugeno system is more computationally efficient than that of a Mamdani system since it uses a weighted average or weighted sum of a few data points rather than a computed centroid of a two-dimensional area [12].
jFuzzyLogic [13] is a Java library that provides a fully functional implementation of a fuzzy inference system according to an associated standard.It offers a programming interface and an Eclipse plugin, making it convenient for writing and testing code for fuzzy control applications.
While several tools exist for implementing fuzzy inference systems in Python, we have not found any open-source tools specifically developed for generalized fuzzy inference.This lack of a universal open system for interval-valued fuzzy inference in Python motivated us to create our complementary library.However, in the context of intervalvalued inference systems in Python, some results can be found in [14], where PyIT2FLS is described.PyIT2FLS provides tools for fast and easy modeling of fuzzy systems.Nevertheless, it lacks advanced techniques for aggregating and comparing interval values, as well as the capability of handling interval data, which is crucial for uncertainty modeling.
In the landscape of Python-based fuzzy inference systems, there are many options, but none of them specifically address the complex needs of generalized fuzzy inference in an open-source manner.This obvious gap led us to develop our own library, which uniquely focuses on interval-valued fuzzy inference.

Key functionalities
Its primary function is to enhance Simpful with the capabilities of handling interval-valued fuzzy sets (IVFSs) and generalized fuzzy inference, thus providing a more comprehensive framework for uncertainty modeling.
Key Features of IFIS: • Enhanced Fuzzy Set Capabilities: IFIS introduces interval-valued fuzzy sets, allowing for intuitive definitions and operations, vital for advanced reasoning in uncertain environments.• Flexible Membership Function Definitions: The package enables users to define complex membership functions, including both polygonal (vertex-based) and various functional types such as sigmoidal and Gaussian.This flexibility enables users to model a wide range of fuzzy sets according to their specific requirements.• Complex Rule Construction: IFIS allows for the construction of complex fuzzy rules using logical operators like AND, OR, and NOT.These operators are adapted for interval-valued fuzzy sets, incorporating operations like minimum and maximum for intervalvalued aggregations.• Interval-Valued Fuzzy Inference: Given values for antecedents as input, IFIS can perform interval-valued fuzzy inference (includes Mamdani and Takagi-Sugeno inference methods).• Broad capabilities for comparing interval values (orders) and corresponding aggregating operations, which are essential for the inference system.• Two methods for entering data into the inference system: real values and/or interval data.This flexibility provides better uncertainty modeling at the beginning of the classification process.

Software description
We implemented the Interval-Valued Fuzzy Inference System (IFIS) in Python 3, enhancing the Simpful library [3] with dependencies on Numpy and Scipy.This system is adept at performing interval-valued fuzzy inference by processing input values for antecedents and then generating corresponding output values, as depicted in Fig. 1.
Fig. 2 illustrates the class structure within the IFIS module, showcasing the enhancements and new features integrated into the existing Simpful library framework.
The class structure in IFIS builds upon the existing structure of Simpful, incorporating additional classes and functionalities to support interval-valued fuzzy inference.IFIS introduces new elements such as interval-valued membership functions, interval-valued fuzzy rules, and the capability to handle arbitrary interval-valued aggregations.These additions enable the implementation of interval-valued fuzzy inference using Mamdani and Takagi-Sugeno methods.

Illustrative examples
The tipping problem involves calculating a fair tip as a percentage of the overall bill, considering the quality of service provided by a restaurant.
Listing 1 provides an example of IFIS code defining an interval inference system to calculate the tip amount based on two input variables: food quality and service quality.The code in Listing 1 demonstrates a range inference system designed to determine the tip percentage for the waiter, given an evaluation of the service in a restaurant.The system considers two inputs, namely food quality and service quality.This example showcases how to define an inference system using interval-valued fuzzy sets.Listing 1: An example implementation of an inference system based on the Takagi-Sugeno method The code begins by creating a root object on line 8.This object lays the groundwork for further enhancements with key components for interval-valued fuzzy inference.
Next, between lines 11 and 18, IVFS's are developed and linked with their corresponding linguistic variables.These sets are defined using two membership functions-one for the lower and one for the upper interval value.
The example code highlights two input variables: service and food quality.Service quality is divided into three fuzzy sets: ''poor'', ''good'', and ''excellent'', while food quality is categorized into ''rancid'' and ''delicious''.Fig. 3 illustrates these interval-valued fuzzy sets graphically, utilizing both triangular and trapezoidal functions for each linguistic label of the input variables.
Lines 21-25 define the output for the inference system, with variations depending on the chosen inference method.There are three possible outputs: two precise values representing tip percentages of 5% and 15% of the total order value, and one value derived from the relationship stated in line 25.Lines 27-30 set the fuzzy inference rules, and lines 33-34 determine the input variables' values.The inference, initiated on line 38 using Takagi-Sugeno method, produces a tip value interval based on given service and food quality ratings.
In the example, the service quality rating is 4 and the food quality rating is 8 (within the ranges [0, 10]), the resulting tip value is represented by the interval [14.1667%, 14.78143%].
An another illustrative example of practical application for our library is its integration into a fall detection algorithm specifically designed for monitoring elderly individuals.This algorithm is openly accessible on GitHub (https://github.com/PGrochowalski/ifis/tree/main/examples/posture_detection), where both the code and data links are provided.The model underwent testing at an elderly care facility in Poland, highlighting the critical role of elderly care in contemporary society.In our study [4], we focus on analyzing a single depth map to identify when a person is lying down.This is in contrast to the UR Fall Detection Dataset, which also offers analysis of character movement.We defined parameters for character posture by clustering 600 images that showcase various forms in different scenarios: everyday activities, falls, and lying down.These images were collected using an inertial motion sensor and Kinect cameras.To respect privacy, we opted to analyze only depth maps instead of video footage, leading to the development of a more precise posture detection model that reduced the error rate by 2.2 percentage points.

Impact
New research questions can span across multiple disciplines, leveraging the unique capabilities of the software to handle uncertainty and fuzzy logic.Here are some potential research questions: • How can interval-valued fuzzy logic be more effectively applied in real-world scenarios, such as medical diagnosis, financial risk assessment, or climate modeling, where uncertainty is a significant factor?• What new optimization techniques can be developed for intervalvalued fuzzy systems to enhance their performance in complex decision-making scenarios?• How can interval-valued fuzzy logic be used to better model human decision-making processes, particularly in situations where decisions are made under uncertainty or with imprecise information?• What are the potential applications of interval-valued fuzzy logic in less explored fields, such as social sciences, humanities, or arts, where qualitative data and subjective judgments are prevalent?• How can interval-valued fuzzy logic enhance the interpretation of sensory data in robotics and IoT devices, especially in environments with high levels of noise or uncertainty?

Fig. 2 .
Fig. 2. Overview of IFIS's class structure, showcasing enhancements and new additions to the Simpful framework.

Fig. 3 .
Fig. 3. Graphical representation of membership functions for interval-valued fuzzy sets for the linguistic variables (a) food quality and (b) service quality.
softx.2024.101730Received 27 January 2024; Received in revised form 22 March 2024; Accepted 29 March 2024 available under an open source licence on github (see code metadata table