Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: June 14, 2022
There are various logical approaches in computer science, and fuzzy logic is one of them.
In this tutorial, we’ll take a look at what this approach means and how it works. Then, we’ll use an example to understand fuzzy logic in a better way.
Let’s have a look at what is fuzzy logic and why we use it.
Lotfi Zadeh developed fuzzy logic after observing that, unlike computers, people have a different range of possibilities between YES and NO. Fuzzy Logic (FL) is a method of reasoning that resembles human reasoning. This approach is similar to how humans perform decision-making. It involves all intermediate possibilities between YES and NO.
Let’s answer the question “Is it cold?” using the boolean and fuzzy logic:
In general, we employ the fuzzy logic system for commercial and practical reasons:
The architecture of fuzzy logic consists of four main components:
It includes all the rules and if-then conditions proposed by experts to control the decision-making system. The current update to the fuzzy approach gives various practical methods for designing and tuning fuzzy controllers. These advancements typically reduce the number of fuzzy rules.
Here’s where the fuzzification takes place. This step converts the inputs or the crisp numbers into fuzzy sets. So, we can measure the crips inputs by sensors and pass them into the control system for further processing. The fuzzification split the input into steps: LP (Large Positive), MP (Medium Positive), S (Small), MN (Medium Negative), and LN (Large Negative).
Provides the degree of match between the fuzzy input and the rules. So, according to the input field, it will decide the rules that are to be fired. The control actions will be formed by combining the fired rules. So, from here we’ll get the fuzzy output set.
It is used to transform the fuzzy sets produced by the intelligence engine into a crisp value. There are numerous defuzzification methods available, and the most appropriate one is employed in conjunction with a certain expert system to decrease the error.
The membership function is a graph that explains how each point in the input space is assigned a membership value ranging from to
. It allows us to quantify linguistic words and graphically display a fuzzy set. A membership function for a fuzzy set
on the universe of discourse
is defined as
.
The membership function quantifies the degree of the membership of the element in to the fuzzy set
. The x-axis represents the universe of discourse whereas the y-axis represents the degrees of membership in
. There can be multiple membership functions applicable to fuzzify a numerical value:
Here are the membership functions for LP (Large Positive), MP (Medium Positive), S (Small), MN (Medium Negative), and LN (Large Negative):
The x-axis represents the membership function whereas the y-axis represents the input voltage. The triangular membership function shapes are common among various other membership function shapes. The input to different level fuzzifier (LN, MN, S, MP, LP) ranges from volts to
volts. Hence, the corresponding output also changes. So, based on these volts the value for the membership function will also change.
The fuzzy logic is often confused with probability. Let’s then take a look at the differences between them:
| Fuzzy Logic | Probability |
|---|---|
| In fuzzy logic, we basically try to capture the essential concept of vagueness | Probability is associated with events and not facts, and those events will either occur or not occur |
| Fuzzy logic captures the meaning of partial truth | Probability theory captures partial knowledge |
| Fuzzy logic takes truth degrees as a mathematical basis | Probability is a mathematical model of ignorance |
Let’s go through the applications of fuzzy logic before diving into its benefits and drawbacks.
Fuzzy logic is used in various fields, such as automotive systems, environment control, and domestic goods. Here are some of the common applications:
Same as any approach, fuzzy logic has its benefits and drawbacks. Let’s then take a look at the benefits and drawbacks of the fuzzy logic in artificial intelligence:
| Advantages | Disadvantages |
|---|---|
| The structure of fuzzy logic systems is easy and understandable | Fuzzy logic is not always accurate |
| Fuzzy logic is widely used for commercial and practical and purposes | It cannot recognize machine learning as-well-as neural network type patterns |
| It helps us to control machines and consumer products | Validation and verification of a fuzzy knowledge-based system needs extensive testing with hardware |
| It helps us to deal with the uncertainty in engineering | Setting the exact fuzzy rules and membership functions is a difficult task |
| Mostly robust as no precise inputs required | At times, fuzzy logic is confused with probability theory |
| If the feedback sensor stops working, we can program it into the situation | |
| We can easily modify to improve or alter system performance | |
| Inexpensive sensors can be used which helps us to keep the overall system cost and complexity low |
Let’s take a simple example to understand the fuzzy logic in a better way. The design of a fuzzy system starts with a set of membership functions for each input and a set for each output. A set of rules is then applied to the membership functions to yield a crisp output value.
Let’s take the example of process control. Before designing we need to understand what we are trying to control, and what data inputs we have that allow us to measure that control? Answering that will allows us to define the linguistic values for the system.
Let’s dive directly into the example for the fuzzy logic. For process control, we have temperature and fan speed. In other words, we are trying to control the speed based on the temperature. Now that we have answered the two most important questions, other things will fall in place.
We have the temperature as the input and the fan speed as the output. So, here we have created a set of membership functions for each input:
Then, we’ll create a membership function for each of these three sets of temperatures. So, for and
axis we have temperature and percent. We have three fuzzy sets: cold, normal or warm, and hot. In the next step, we’ll use the three fuzzy sets for the output. We have slow, medium, and fast:
So, for the input we have temperature and we have taken the speed as the output. That’s the fan speed.
We have defined the membership functions. Let’s now move forward to create the rules for these functions. These rules define how the membership functions will be applied to the final system. So, let’s create three rules for our system:
According to these three rules, we are comparing the input with the output. Then, we calculate the speed based on the temperature. Thus, we apply these rules to the membership functions to produce the crisp output value to drive the system:
For an input value of around degrees, we intersect the membership function. So, we are applying two rules as the intersection occurs on both functions. We can extend the intersection points to the output function to produce an intersecting point.
To obtain the best crisp output, the defuzzification procedure is applied to the fuzzy output set. There are numerous defuzzification methods, such as the centroid method, center of largest area method, and first maxima method.
In this tutorial, we’ve discussed the basic concept of fuzzy logic using an example to unlock its mechanism. We’ve also gone over the principle of fuzzy logic in artificial intelligence and how it works.