# Fuzzy Logic
## Introduction

Fuzzy logic is a form of many-valued logic in which the truth values of variables may be any real number between 0 and 1 both inclusive. It is employed to handle the concept of partial truth, where the truth value may range between completely true and completely false. By contrast, in Boolean logic, the truth values of variables may only be the integer values 0 or 1.

### History

The term fuzzy logic was introduced with the 1965 proposal of fuzzy set theory by Lotfi Zadeh. Fuzzy logic had, however, been studied since the 1920s, as infinite-valued logic—notably by Łukasiewicz and Tarski.

### Real world motivation for the Fuzzy Logic

Fuzzy logic is based on the observation that people make decisions based on imprecise and non-numerical information. Fuzzy models or sets are mathematical means of representing vagueness and imprecise information (hence the term fuzzy). These models have the capability of recognising, representing, manipulating, interpreting, and utilising data and information that are vague and lack certainty.

### Areas of Application

Fuzzy logic has been applied to many fields, from control theory to artificial intelligence.

## Learning Task

The activity supports you in applying the Fuzzy Logic to real world setting. The first step will be the application on a spatial problem represented with membership function $\mu :\mathbb {D} \to [0,1]$ that have a geographical area as the domain $\mathbb {D}$

### Geographical Coordinates

If we apply Fuzzy Logic on a spatial problem, then all geographical locations can be represented with coordinates $(x,y)$ (e.g. latitude, longitude). The coordinates $(x,y)$ are mapped with a fuzzy membership function $\mu (x,y)$to a degrees of truth $\mu (x,y)\in [0,1]$ for a property at the geolocation $(x,y)$.

#### Visualisation of a Spatial Membership Function
### Spatial Membership Function for Temperature

Apply this concept on the current temperature $T(x,y)$ at the geolocation $(x,y)$ and define $\mu (x,y):=f(T(x,y))$ in way that the temperature for mosquitos is optimal for mosquitos around 25 degrees Celsius. The degree of truth with a value $\mu (x,y):=0.9$ indicates that the temperature is close to 25 degrees Celsius. Explain why the function $f(t):={\frac {1}{1+{\frac {(t-25)^{2}}{s^{2}}}}}$ with $s>0$ and $\mu (x,y):=f(T(x,y))$ serves as fuzzification of the temperature $T(x,y)$ at the geolocation $(x,y)$ .

### Calculations for Membership Function

* Use e.g. OpenSource LibreOffice Calc and enter in the cell "A1" a temperature and in cell "B1" the following function =1/(1+((A1-25))^2) and change the temperature value in cell "A1". Test for values 0, 5, 10, 15, 20, 25, 30, 35. What you see for degree of truth for the fuzzyfied temperature value in "B1".

### Degree of Truth for optimal Temperature

Explain why 25 degree Celsius is the optimal temperature with the definition of the mapping.
* Explain, why Spatial Fuzzy Logic can be used in Spatial Decision Support Systems.
* Look at the Open Search learning resource and apply Fuzzy Logic to search queries. Describe the benefits and drawbacks of the application of Fuzzy Logic for search queries.

## Overview

Classical logic only permits conclusions which are either true or false. However, there are also propositions with variable answers, such as one might find when asking a group of people to identify a color. In such instances, the truth appears as the result of reasoning from inexact or partial knowledge in which the sampled answers are mapped on a spectrum.

### Similarities and Differences with Probability

Both degrees of truth and probabilities range between 0 and 1 and hence may seem similar at first, but fuzzy logic uses degrees of truth as a mathematical model of vagueness, while probability is a mathematical model of ignorance.

### Applying truth values

A basic application might characterize various sub-ranges of a continuous variable. For instance, a temperature measurement for anti-lock brakes might have several separate membership functions defining particular temperature ranges needed to control the brakes properly. Each function maps the same temperature value to a truth value in the 0 to 1 range. These truth values can then be used to determine how the brakes should be controlled.

### Linguistic Variable, Linguistic Values and Rules

While variables in mathematics "x" usually take numerical values "x=5", in fuzzy logic applications, non-numeric linguistic variables like "age" can be populated with linguistic values like "young", "old" or linguistic variable "speed" with "fast", "slow",... This concept is often used to facilitate the expression of facts and rules, e.g. "if a person is youong he/she can run fast"

#### Natural Languages and Adjectives

A linguistic variable such as age may accept values such as young and its antonym old. Because natural languages do not always contain enough value terms to express a fuzzy value scale, it is common practice to modify linguistic values with adjectives or adverbs. For example, we can use the hedges rather and somewhat to construct the additional values rather old or somewhat young.

#### Context Dependency of linguistic Variables and Values

A linguistic variable such as age is dependent of the context in which the linguistic values and variables are used. From the perspective of a teenager a 27 year old man would be assigned the linguistic value "old" while a senior of the 85 years could regard the a 27 year old man as young. A dog of 17 years might be regarded as "old" which is dependent of average lifespan of a dog.

#### Fuzzification

Fuzzification operations can map linguistic values (like "old") into fuzzy membership functions $\mu _{old}:\mathbb {D} \to [0,1]$. The fuzzy membership function $\mu _{old}$ maps the numeric value of age to a degree of truth for the linguistic value $x$ e.g. for an age of 65 $\mu _{old}(65)=0.8$ while for 2 year old baby might be $\mu _{old}(2)=0.05$.

#### De-Fuzzification

The opposite de-fuzzifying operations can be used to map a fuzzy output membership function into a "crisp" output value that can be then used for decision or control purposes, e.g. after a applying the rule the degree of truth is 0.9 then the def-fuzzification translates that into "fast". In the context of rule this means "the person can run 'fast'".

## Process

* Fuzzify all input values into fuzzy membership functions.
* Execute all applicable rules in the rulebase to compute the fuzzy output functions.
* De-fuzzify the fuzzy output functions to get "crisp" output values.

### Fuzzification

Fuzzification is the process of assigning the numerical input of a system to fuzzy sets with some degree of membership. This degree of membership may be anywhere within the interval [0,1]. If it is 0 then the value does not belong to the given fuzzy set, and if it is 1 then the value completely belongs within the fuzzy set. Any value between 0 and 1 represents the degree of uncertainty that the value belongs in the set. These fuzzy sets are typically described by words, and so by assigning the system input to fuzzy sets, we can reason with it in a linguistically natural manner.

#### Example for Linguistic Values - Temperature

For example, in the image below the meanings of the expressions cold, warm, and hot are represented by functions mapping a temperature scale. A point on that scale has three "truth values"—one for each of the three functions. The vertical line in the image represents a particular temperature that the three arrows (truth values) gauge. Since the red arrow points to zero, this temperature may be interpreted as "not hot"; i.e. this temperature has zero membership in the fuzzy set "hot". The orange arrow (pointing at 0.2) may describe it as "slightly warm" and the blue arrow (pointing at 0.8) "fairly cold". Therefore, this temperature has 0.2 membership in the fuzzy set "warm" and 0.8 membership in the fuzzy set "cold". The degree of membership assigned for each fuzzy set is the result of fuzzification.

#### Triangle Shaped Fuzzy Membership Functions

Fuzzy sets are often defined as triangle or trapezoid-shaped curves, as each value will have a slope where the value is increasing, a peak where the value is equal to 1 (which can have a length of 0 or greater) and a slope where the value is decreasing.

#### Sigmoid Shaped Fuzzy Membership Function

They can also be defined using a sigmoid function. One common case is the standard logistic function defined as
    $S(x)={\frac {1}{1+e^{-x}}}$

##### Mathematical Property

For the numerical optimization the existence of the derivation $S'$ in the domain is used (e.g. in gradient descent algorithm. The triangle shaped membership function is mathematical continuous by the derivation does not exist for all points in the domain.

##### Symmetry Property

which has the following symmetry property
    $S(x)+S(-x)=1$
From this it follows that
$(S(x)+S(-x))\cdot (S(y)+S(-y))\cdot (S(z)+S(-z))=1$

### Fuzzy logic operators

Fuzzy logic works with membership values in a way that mimics Boolean logic. To this end, replacements for basic operators AND, OR, NOT must be available. There are several ways to this. A common replacement is called the Zadeh operators:
| Boolean | Fuzzy |
| AND(x,y) | MIN(x,y) |
| OR(x,y) | MAX(x,y) |
| NOT(x) | 1 – x |

#### Consistency with classical Logic

For TRUE/1 and FALSE/0, the fuzzy expressions produce the same result as the Boolean expressions.
There are also other operators, more linguistic in nature, called hedges that can be applied. These are generally adverbs such as very, or somewhat, which modify the meaning of a set using a mathematical formula.[citation needed]

#### Choice Tables

However, an arbitrary choice table does not always define a fuzzy logic function. In the paper, a criterion has been formulated to recognize whether a given choice table defines a fuzzy logic function and a simple algorithm of fuzzy logic function synthesis has been proposed based on introduced concepts of constituents of minimum and maximum. A fuzzy logic function represents a disjunction of constituents of minimum, where a constituent of minimum is a conjunction of variables of the current area greater than or equal to the function value in this area (to the right of the function value in the inequality, including the function value).

#### Other AND/OR Operators

Another set of AND/OR operators is based on multiplication
$1-(1-x)*(1-y)$ comes from this:

### IF-THEN rules

IF-THEN rules map input or computed truth values to desired output truth values. Example:
Given a certain temperature, the fuzzy variable hot has a certain truth value, which is copied to the high variable.
Should an output variable occur in several THEN parts, then the values from the respective IF parts are combined using the OR operator.

### Defuzzification

The goal is to get a continuous variable from fuzzy truth values.[citation needed]
This would be easy if the output truth values were exactly those obtained from fuzzification of a given number. Since, however, all output truth values are computed independently, in most cases they do not represent such a set of numbers.[citation needed] One has then to decide for a number that matches best the "intention" encoded in the truth value. For example, for several truth values of fan_speed, an actual speed must be found that best fits the computed truth values of the variables 'slow', 'moderate' and so on. [citation needed]
There is no single algorithm for this purpose.
A common algorithm is
* For each truth value, cut the membership function at this value
* Combine the resulting curves using the OR operator
* Find the center-of-weight of the area under the curve
* The x position of this center is then the final output.

## Forming a consensus of inputs and fuzzy rules

Since the fuzzy system output is a consensus of all of the inputs and all of the rules, fuzzy logic systems can be well behaved when input values are not available or are not trustworthy. Weightings can be optionally added to each rule in the rulebase and weightings can be used to regulate the degree to which a rule affects the output values. These rule weightings can be based upon the priority, reliability or consistency of each rule. These rule weightings may be static or can be changed dynamically, even based upon the output from other rules.

## Early applications

Many of the early successful applications of fuzzy logic were implemented in Japan. The first notable application was on the subway train in Sendai, in which fuzzy logic was able to improve the economy, comfort, and precision of the ride[citation needed]. It has also been used in recognition of hand-written symbols in Sony pocket computers, flight aid for helicopters, controlling of subway systems in order to improve driving comfort, precision of halting, and power economy, improved fuel consumption for automobiles, single-button control for washing machines, automatic motor control for vacuum cleaners with recognition of surface condition and degree of soiling, and prediction systems for early recognition of earthquakes through the Institute of Seismology Bureau of Meteorology, Japan.

## Current applications
### In medical decision making

Fuzzy logic is an important concept when it comes to medical decision making. Since medical and healthcare data can be subjective or fuzzy, applications in this domain have a great potential to benefit a lot by using fuzzy logic based approaches. One of the common application areas that use fuzzy logic is computer-aided diagnosis (CAD) in medicine. CAD is a computerized set of inter-related tools which can be used to aid physicians in their diagnostic decision-making. For example, when a physician finds a lesion which is abnormal but still at a very early stage of development he/she may use a CAD approach to characterize the lesion and diagnose its nature. Fuzzy logic can be highly appropriate to describe key characteristics of this lesion. Fuzzy logic can be used in many different aspects within the CAD framework. Such aspects include in medical image analysis, biomedical signal analysis, segmentation of images or signals, and feature extraction / selection of images or signals as described, for instance, in and.
The biggest question in this application area is how much useful information can be derived when using fuzzy logic. A major challenge is how to derive the required fuzzy data. This is even more challenging when one has to elicit such data from humans (usually, patients). As it said "The envelope of what can be achieved and what cannot be achieved in medical diagnosis, ironically, is itself a fuzzy one" [Seven Challenges, 2019]. How to elicit fuzzy data, and how to validate the accuracy of the data is still an ongoing effort strongly related to the application of fuzzy logic. The problem of assessing the quality of fuzzy data is a difficult one. This is why fuzzy logic is a highly promising possibility within the CAD application area but still requires more research to achieve its full potential. Although the concepts of using fuzzy logic in CAD is exciting, there are still several challenges that fuzzy approaches face within the CAD framework.

## Logical analysis

In mathematical logic, there are several formal systems of "fuzzy logic", most of which are in the family of t-norm fuzzy logics.

### Propositional fuzzy logics

The most important propositional fuzzy logics are:
* Monoidal t-norm-based propositional fuzzy logic MTL is an axiomatization of logic where conjunction is defined by a left continuous t-norm and implication is defined as the residuum of the t-norm. Its models correspond to MTL-algebras that are pre-linear commutative bounded integral residuated lattices.
* Basic propositional fuzzy logic BL is an extension of MTL logic where conjunction is defined by a continuous t-norm, and implication is also defined as the residuum of the t-norm. Its models correspond to BL-algebras.
* Łukasiewicz fuzzy logic is the extension of basic fuzzy logic BL where standard conjunction is the Łukasiewicz t-norm. It has the axioms of basic fuzzy logic plus an axiom of double negation, and its models correspond to MV-algebras.
* Gödel fuzzy logic is the extension of basic fuzzy logic BL where conjunction is Gödel t-norm. It has the axioms of BL plus an axiom of idempotence of conjunction, and its models are called G-algebras.
* Product fuzzy logic is the extension of basic fuzzy logic BL where conjunction is product t-norm. It has the axioms of BL plus another axiom for cancellativity of conjunction, and its models are called product algebras.
* Fuzzy logic with evaluated syntax (sometimes also called Pavelka's logic), denoted by EVŁ, is a further generalization of mathematical fuzzy logic. While the above kinds of fuzzy logic have traditional syntax and many-valued semantics, in EVŁ is evaluated also syntax. This means that each formula has an evaluation. Axiomatization of EVŁ stems from Łukasziewicz fuzzy logic. A generalization of classical Gödel completeness theorem is provable in EVŁ^(citation needed).

### Predicate fuzzy logics

These extend the above-mentioned fuzzy logics by adding universal and existential quantifiers in a manner similar to the way that predicate logic is created from propositional logic. The semantics of the universal (resp. existential) quantifier in t-norm fuzzy logics is the infimum (resp. supremum) of the truth degrees of the instances of the quantified subformula.

### Decidability issues for fuzzy logic

The notions of a "decidable subset" and "recursively enumerable subset" are basic ones for classical mathematics and classical logic. Thus the question of a suitable extension of them to fuzzy set theory is a crucial one. A first proposal in such a direction was made by E.S. Santos by the notions of fuzzy Turing machine, Markov normal fuzzy algorithm and fuzzy program (see Santos 1970). Successively, L. Biacino and G. Gerla argued that the proposed definitions are rather questionable. For example, in one shows that the fuzzy Turing machines are not adequate for fuzzy language theory since there are natural fuzzy languages intuitively computable that cannot be recognized by a fuzzy Turing Machine. Then, they proposed the following definitions. Denote by Ü the set of rational numbers in [0,1]. Then a fuzzy subset s : S $\rightarrow$[0,1] of a set S is recursively enumerable if a recursive map h : S×N $\rightarrow$Ü exists such that, for every x in S, the function h(x,n) is increasing with respect to n and s(x) = lim h(x,n). We say that s is decidable if both s and its complement –s are recursively enumerable. An extension of such a theory to the general case of the L-subsets is possible (see Gerla 2006). The proposed definitions are well related with fuzzy logic. Indeed, the following theorem holds true (provided that the deduction apparatus of the considered fuzzy logic satisfies some obvious effectiveness property).
Any "axiomatizable" fuzzy theory is recursively enumerable. In particular, the fuzzy set of logically true formulas is recursively enumerable in spite of the fact that the crisp set of valid formulas is not recursively enumerable, in general. Moreover, any axiomatizable and complete theory is decidable.
It is an open question to give supports for a "Church thesis" for fuzzy mathematics, the proposed notion of recursive enumerability for fuzzy subsets is the adequate one. In order to solve this, an extension of the notions of fuzzy grammar and fuzzy Turing machine are necessary. Another open question is to start from this notion to find an extension of Gödel's theorems to fuzzy logic.

## Fuzzy databases

Once fuzzy relations are defined, it is possible to develop fuzzy relational databases. The first fuzzy relational database, FRDB, appeared in Maria Zemankova's dissertation (1983). Later, some other models arose like the Buckles-Petry model, the Prade-Testemale Model, the Umano-Fukami model or the GEFRED model by J.M. Medina, M.A. Vila et al.
Fuzzy querying languages have been defined, such as the SQLf by P. Bosc et al. and the FSQL by J. Galindo et al. These languages define some structures in order to include fuzzy aspects in the SQL statements, like fuzzy conditions, fuzzy comparators, fuzzy constants, fuzzy constraints, fuzzy thresholds, linguistic labels etc.
The knowledge graph Weaviate uses fuzzy logic to index data based on a machine learning model called the Contextionary.

## Comparison to probability

Fuzzy logic and probability address different forms of uncertainty. While both fuzzy logic and probability theory can represent degrees of certain kinds of subjective belief, fuzzy set theory uses the concept of fuzzy set membership, i.e., how much an observation is within a vaguely defined set, and probability theory uses the concept of subjective probability, i.e., frequency of occurrence or likelihood of some event or condition. The concept of fuzzy sets was developed in the mid-twentieth century at Berkeley as a response to the lacking of probability theory for jointly modelling uncertainty and vagueness.
Bart Kosko claims in Fuzziness vs. Probability that probability theory is a subtheory of fuzzy logic, as questions of degrees of belief in mutually-exclusive set membership in probability theory can be represented as certain cases of non-mutually-exclusive graded membership in fuzzy theory. In that context, he also derives Bayes' theorem from the concept of fuzzy subsethood. Lotfi A. Zadeh argues that fuzzy logic is different in character from probability, and is not a replacement for it. He fuzzified probability to fuzzy probability and also generalized it to possibility theory.
More generally, fuzzy logic is one of many different extensions to classical logic intended to deal with issues of uncertainty outside of the scope of classical logic, the inapplicability of probability theory in many domains, and the paradoxes of Dempster-Shafer theory.

## Relation to ecorithms

Computational theorist Leslie Valiant uses the term ecorithms to describe how many less exact systems and techniques like fuzzy logic (and "less robust" logic) can be applied to learning algorithms. Valiant essentially redefines machine learning as evolutionary. In general use, ecorithms are algorithms that learn from their more complex environments (hence eco-) to generalize, approximate and simplify solution logic. Like fuzzy logic, they are methods used to overcome continuous variables or systems too complex to completely enumerate or understand discretely or exactly. Ecorithms and fuzzy logic also have the common property of dealing with possibilities more than probabilities, although feedback and feed forward, basically stochastic weights, are a feature of both when dealing with, for example, dynamical systems.

## Compensatory fuzzy logic

Compensatory fuzzy logic (CFL) is a branch of fuzzy logic with modified rules for conjunction and disjunction. When the truth value of one component of a conjunction or disjunction is increased or decreased, the other component is decreased or increased to compensate. This increase or decrease in truth value may be offset by the increase or decrease in another component. An offset may be blocked when certain thresholds are met. Proponents[who?] claim that CFL allows for better computational semantic behaviors and mimic natural language.[vague]
Compensatory Fuzzy Logic consists of four continuous operators: conjunction (c); disjunction (d); fuzzy strict order (or); and negation (n). The conjunction is the geometric mean and its dual as conjunctive and disjunctive operators.

## IEEE STANDARD 1855–2016 – IEEE Standard for Fuzzy Markup Language

The IEEE 1855, the IEEE STANDARD 1855–2016, is about a specification language named Fuzzy Markup Language (FML) developed by the IEEE Standards Association. FML allows modelling a fuzzy logic system in a human-readable and hardware independent way. FML is based on eXtensible Markup Language (XML). The designers of fuzzy systems with FML have a unified and high-level methodology for describing interoperable fuzzy systems. IEEE STANDARD 1855–2016 uses the W3C XML Schema definition language to define the syntax and semantics of the FML programs.
Prior to the introduction of FML, fuzzy logic practitioners could exchange information about their fuzzy algorithms by adding to their software functions the ability to read, correctly parse, and store the result of their work in a form compatible with the Fuzzy Control Language (FCL) described and specified by Part 7 of IEC 61131.