What Is Fuzzy Logic? | Fuzzy Logic, Part 1 - MATLAB
Video Player is loading.
Current Time 0:00
Duration 15:39
Loaded: 1.05%
Stream Type LIVE
Remaining Time 15:39
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 15:39

    What Is Fuzzy Logic? | Fuzzy Logic, Part 1

    From the series: Fuzzy Logic

    Brian Douglas

    This video introduces fuzzy logic and explains how you can use it to design a fuzzy inference system (FIS), which is a powerful way to use human experience to design complex systems. Designing a FIS does not require a model, so it works well for complex systems with underlying mechanisms that are not fully known. If you have some experience and intuition about the system, then you can develop and implement the rules.

    Published: 17 Aug 2021

    Fuzzy logic is a way to model logical reasoning where the truth of a statement is not a binary true or false like it is with classical logic. But rather it's a degree of truth that ranges from 0, which is absolutely false, to 1, which is absolutely true. Fuzzy logic allows us to design a fuzzy inference system, which is a function that maps a set of inputs to outputs using human interpretable rules rather than more abstract mathematics.

    These types of functions are popular for control applications where a reference and measurements are fed in, and then using a set of rules based on fuzzy logic, some actuating signal is produced.

    But fuzzy logic is larger than just a control technique, as it can be used for any decision making process. Like for example, a banking system that decides the risk of loaning money to a person based on a set of personal and financial information. And beyond that, fuzzy logic can be used to just answer questions, which is useful for any number of applications. For example, it can be used for detecting edges and images by answering the question, to what degree does a pixel belong to a region of uniform intensity versus an edge region?

    And something that's really cool is that developing a fuzzy inference system doesn't require a model. So it works well for complex systems whose underlying mechanisms are not fully known. As long as you have some experience and intuition about the system, then the rules can be developed and implemented. It's really powerful, super interesting, and can be applied to many different scenarios. So I hope you stick around for this brief introduction to fuzzy logic. I'm Brian, and welcome to a MATLAB Tech Talk.

    A fuzzy inference system is a form of artificial intelligence, in that it allows computers to mimic the way humans think about an approach solving problems. For example, a person might say, pretty hungry but it's almost dinnertime. In this statement, "pretty hungry" and "almost dinnertime" are two vague concepts. What does "pretty hungry" mean? And how much time precisely is there until dinner? And a person probably would have no problem parsing this statement and making a decision to wait until dinner or not. We have experience with these types of statements, and we have knowledge about hunger and meal times that we can use to help us.

    On the other hand, it would be difficult to get a computer to determine whether a person should eat based on the fuzzy ideas of "pretty hungry" and "almost dinner." At least it would be without fuzzy logic. Fuzzy logic, and ultimately a fuzzy inference system, gives us a way to encode experience-based knowledge in a way that computers can understand in the form of logical rules. And to understand what I mean by this, let's explore the decision process that a banker might do to assess the risk of a loan.

    In a very simplified world, a banker might look at credit rating, which is the input into the decision process. And then determine the overall risk of giving a person a loan, which is the output. And by the way, this example is purposefully oversimplified and not based in reality at all. I just want to give you a simple introduction to fuzzy logic so you understand the idea behind it and the context of how it's used. And then in the next video, we'll walk through a more complex example, so that you can see more of its potential.

    OK, so back to this problem where the banker's looking at credit rating and trying to determine risk. And to solve this problem, the banker might take advantage of existing knowledge and experience in the form of rules. For example, a rule might be if a person has good credit, then the applicant is deemed low risk. If they have neutral credit, then they are medium risk. And bad credit, then they are high risk.

    And so in this way, the rules themselves that have been developed over time based on experience and data are the encoding of knowledge. They are the model that can be used for prediction. In this case, the prediction of whether a person will pay back a loan or not. And so, if you want to come up with a function that can assess risk automatically, it would make sense to base it on the existing knowledge that is baked into the set of rules that people have already developed, rather than try to develop a mathematical model of something as complex as human finance.

    But there is a difficulty with this, because our experience is often encoded in vague language. For example, what does it mean that a person has good credit? Well, we could define it precisely by saying that good credit is 750 and above, and anything below 750 is neutral credit. Now we can set up an equation that compares their credit value to 750 and determine if it is good or not. This is a binary logical statement. The output is either completely true or completely false. A value of 750 is completely good credit, and a value of 749 is completely neutral credit.

    This precision that we've injected into this problem makes solving it rather easy, but the issue is that the linguistic terms that we use to describe the degree of something-- that is, how much or little it actually is-- these terms are fuzzy. Language isn't that precise. And so by making it precise, we've lost some of the intent. Not only are we saying that by improving your credit score by one point will somehow make your risk factor jump from neutral to good-- which seems like a drastic change for a single point-- but we're also claiming that there is an agreed upon definition of what good credit means, which just isn't true. A score of 750 might be considered good, very good, or neutral to different people. Or in our case, to different bankers.

    So if we want to encode the knowledge of the banking industry as a whole, we need to take into account the fuzziness, or the impreciseness of language in our logical rules. And since binary logic isn't sufficient, this is where fuzzy logic comes in. With fuzzy logic, crisp inputs with precise values-- like we have with a very specific credit rating-- these are converted to fuzzy variables in a process called fuzzification. The fuzzy logic rules can then be applied to these fuzzified variables to create new fuzzy numbers. And finally, these fuzzy numbers can be converted back to crisp, specific outputs in a process called defuzzification.

    By the way, the word "fuzzy" gets put into everything, and I kind of feel like we're in the Batman universe where common items just get appended with the word "bat," like batphone and batmobile and batarang. But don't get too distracted by the description of all of these processes. We're going to walk through them, and hopefully you'll see that despite the interesting names, this is all very intuitive.

    All right, let's get back to our banking example. Let's say that the true underlying model that maps credit score to risk is a linear line, where perfect credit of 850 is 0% risk and a credit of 300 is 100% risky. And let's say that we don't actually know this model because it's driven by really complex mechanisms, and all we have is this vague notion of bad, neutral and good credit and high, medium, and low risk. With classical logic, if we assign bad credit to high risk, neutral to medium, and good to low, we get a very discontinuous representation of the true underlying model. You can see how much error this model has in places. And these discontinuous jumps showed the result of crossing over from one set to another.

    Now let's compare this to a fuzzy logic approach, which we can think of this way. Imagine we poll 100 bankers and we ask them to assign where they think the transition is from bad to neutral credit, and the transition from neutral to good. And more than likely there are going to be different values since, again, these are vague terms. And let's assume that every banker thought 750 and above is good credit, but only half of them thought that 700 was good, and none thought that 650 was good. This traces out the particular membership function for good credit. And we could do the same for neutral credit and for bad credit. And we end up with these three overlapping membership functions.

    Now we can see that the truth of a statement doesn't have to belong to only a single set, true or false. They can belong to multiple sets based on the degree of truth. A score of 800 belongs 100% in the good credit set, but a score of 700 belongs 50% to good and 50% to neutral. It is equally true that a score of 700 is both good and neutral.

    So, what would a credit score of 660 be? Well intuitively we think, eh, it's mostly neutral. And according to our membership functions, this is what we find. 660 is 90% neutral and 10% good. Therefore, an input value of 660 becomes the fuzzy number 0, 0.9, 0.1. And this process of going from that crisp input value to a fuzzy value is called fuzzification. And if you recall, this was the first step in our process.

    With this fuzzy number we can move to the second step, inference. What can we infer from this fuzzy value, given the logical rules that we set up? Remember these three rules here? Well, let's assess them. Is credit good? Well, it's 10% good, so then risk is 10% low. Is credit neutral? Well, it's 90% neutral, so risk is 90% medium. And is credit bad? No, it's 0% bad, so risk is 0% high.

    This gives us another fuzzy variable, that just so happens to be the same numbers of 0.9 and 0.1. But this is only because of the simple rules that we set up. In general, these logical rules could create new fuzzy variables that are drastically different.

    OK, so now with inference complete, we have this new fuzzy number. We can start the process of defuzzification, or going from this fuzzy value back to a crisp output. And just like with the inputs, we could poll our 100 bankers and get a set of membership functions that indicate how the bankers would convert a vague term of low, medium, and high risk into a crisp percentage value. And for the sake of this simple example, let's say this is what these membership functions look like. Low risk is 25% and lower, and then linearly falls off up to 50%. Medium risk goes from 25% to 75%, and high risk linearly increases starting at 50% up to 75%.

    OK, for defuzzification, there are many different methods, but a popular method is as follows. We said that the output is 90% medium and 10% low, so we can chop off the top of each of these membership functions according to their percentage. And this leaves two trapezoids which we can merge into a single geometric shape. Now the defuzzified value is the x-coordinate of the centroid of this shape, which in this example is about 46%. This means that a credit score of 660 is 46% risky, and this lines up pretty nicely with our expectations that 660 is a little bit higher than what most bankers consider neutral credit. And so it is a little bit less risky than 50%.

    So, fuzzy inference is a way of doing interpolation using vague language. In our case, we were able to approximate this true function with the interpolation of these vague terms. And the key to all of this is that baked into these terms is actual knowledge from the experience of experts.

    Now, I only showed you a single point on this graph for a credit score of 660, but let's jump over to MATLAB real quick and I'll show you what the full interpolation looks like. Using the Fuzzy Logic Toolbox, I'm creating a fuzzy inference system with one input and one output, each with three membership functions. The input membership functions for credit score are bad, neutral, and good, defined the same way as we did earlier. And the output membership functions for risk are also defined similarly with low, medium, and high risk.

    The inference portion of this system, or the logical rules, are defined with these human understandable strings. If credit is bad, then risk is high. If it's neutral, then risk is medium. And good, then risk is low. And using these rules, plus the input and output membership functions, we can generate a plot of the output surface. Which in our case, is just a line that maps credit score to risk. And check this out. A credit score of 660 does in fact map to about 46% risk with this inference system.

    OK, so this was a really simple example, like I said. We only had a single input and output variable, and our logical rules were pretty basic. But fuzzy logic also works with more complex systems as well. For example, check out this output surface for a fuzzy inference system that decides the appropriate amount of tip for a meal at a restaurant based on the quality of the food and the service. This surface is already looking more complex, even though there's just two inputs. So you can imagine how complex of a model you can create with just a few logical rules and fuzzy logic.

    OK, real quick before end in this video, I just want to talk about one other benefit of fuzzy logic. And that is that we can approach the problem in the opposite direction. We can start by building a fuzzy inference system with essentially an empty framework, but no real understanding of membership functions or the rules themselves. And then we can use data to systematically learn the parameters of that inference system. In this way, we can use machine learning to tune the inference system, similar to tuning a neural network. But in the end, we've trained a model that's much easier to understand since the rules are interpretable. And this is helpful for systems where verification and certification are important.

    Now, I'm just going to leave you here thinking about that interesting statement. But we're going to come back to it throughout the next couple of videos. So, if you don't want to miss those or any other future Tech Talk videos, don't forget to subscribe to this channel. Also, if you want to check out my channel, Control System Lectures, I cover more control theory topics there as well. Thanks for watching, and I'll see you next time.