FUZZY LOGIC TUTORIAL

Introduction
Fuzzy logic has rapidly become one of the most successful of today's technologies for developing sophisticated control systems. The reason for which is very simple. Fuzzy logic addresses such applications perfectly as it resembles human decision making with an ability to generate precise solutions from certain or approximate information. It fills an important gap in engineering design methods left vacant by purely mathematical approaches (e.g. linear control design), and purely logic-based approaches (e.g. expert systems) in system design.

While other approaches require accurate equations to model real-world behaviors, fuzzy design can accommodate the ambiguities of real-world human language and logic. It provides both an intuitive method for describing systems in human terms and automates the conversion of those system specifications into effective models.

What does it offer?
The first applications of fuzzy theory were primaly industrial, such as process control for cement kilns. However, as the technology was further embraced, fuzzy logic was used in more useful applications. In 1987, the first fuzzy logic-controlled subway was opened in Sendai in northern Japan. Here, fuzzy-logic controllers make subway journeys more comfortable with smooth braking and acceleration. Best of all, all the driver has to do is push the start button! Fuzzy logic was also put to work in elevators to reduce waiting time. Since then, the applications of Fuzzy Logic technology have virtually exploded, affecting things we use everyday.
Take for example, the fuzzy washing machine . A load of clothes in it and press start, and the machine begins to churn, automatically choosing the best cycle. The fuzzy microwave, Place chili, potatoes, or etc in a fuzzy microwave and push single button, and it cooks for the right time at the proper temperature. The fuzzy car, manuvers itself by following simple verbal instructions from its driver. It can even stop itself when there is an obstacle immedeately ahead using sensors. But, practically the most exciting thing about it, is the simplicity involved in operating it.



Background

Ancient Greece

The success of modern mathematics is largely due to the efforts of Aristotle and the philosophers who preceded him. In their efforts to devise a concise theory of logic, and later mathematics, the so-called "Laws of Thought" were invented. One of these, the "Law of the Excluded Middle," stated that every proposition must either be True or False, A or not-A, either this or not this. For example, a typical rose is either red or not red. It cannot be red and not red. Every statement or sentence is true or false or has the truth value 1 or 0. Even then, there already were strong and immediate objections to this proposal.
In fact, almost two centuries earlier, Buddha saw the world filled with contradictions, that things could be a certain degree true and a certain degree false at the same time. However, it was Plato who laid the foundation for what would become fuzzy logic, indicating that there was a third region (beyond True and False) where these opposites "tumbled about.

The world's getting fuzzier

In the early 1900s, Lukasiewicz came and proposed a systematic alternative to the bi-valued logic(bivalence) of Aristotle. He described a three-valued logic, which can best be translated as the term `possible', and assigned it a numeric value between True and False. Knuth, a former student of Lukasiewicz proposed a three-valued logic apparently missed by Lukasiewicz, whiched used an integral range [-1, 0 +1] rather than [0, 1, 2]. Nonetheless, this alternative failed to gain acceptance, and has passed into relative obscurity.

It's heeere
It was not until relatively recently that the theory of fuzzy logic was discovered. Lotfi A. Zadeh, a professor of UC Berkeley in California, soon to be known as the founder of fuzzy logic observed that conventional computer logic was incapable of manipulating data representing subjective or vague human ideas such as "an atractive person" or "pretty hot". Fuzzy logic, hence was designed to allow computers to determine the distinctions among data with shades of gray, similar to the process of human reasoning. In 1965, Zadeh published his seminal work "Fuzzy Sets" which described the mathematics of fuzzy set theory, and by extension fuzzy logic. This theory proposed making the membership function (or the values False and True) operate over the range of real numbers [0.0, 1.0]. Fuzzy logic was now introduced to the world.
Although, the technology was introduced in the United States, the scientist and researchers there, ignored it mainly because of its unconventional name. They refused to take something which sounded so child-like seriously. Some mathematicians argued that fuzzy logic was merely probability in disguise. Only stubborn scientists or ones who worked in discrete continued researching it.

While the US and certain parts of Europe ignored it, fuzzy logic was excepted with open arms in Japan, China and most Oriental countries. It may be suprising to some that the world's largest number of fuzzy researchers are in China with over 10,000 scientists. Japan, though currently positioned at the leading edge of fuzzy studies falls second in manpower, followed by Europe and the USA. Hence, it can
be said that the popularity of fuzzy logic in the Orient reflects the fact that Oriental thinking more easily accepts the concept of "fuzziness". And because of this, the US, by some estimates, trail Japan by at least ten years in this forefront of modern technology.



Fuzzy Sets and Operations

What do ya mean fuzzy ??!!

Before illustrating the mechanisms which make fuzzy logic machines work, it is important to realize what fuzzy logic actually is. Fuzzy logic is a superset of conventional(Boolean) logic that has been extended to handle the concept of partial truth- truth values between "completely true" and "completely false". As its name suggests, it is the logic underlying modes of reasoning which are approximate rather than exact. The importance of fuzzy logic derives from the fact that most modes of human reasoning and especially common sense reasoning are approximate in nature.
The essential characteristics of fuzzy logic as founded by Zader Lotfi are as follows.

  • In fuzzy logic, exact reasoning is viewed as a limiting case of approximate reasoning.
  • In fuzzy logic everything is a matter of degree.
  • Any logical system can be fuzzified
  • In fuzzy logic, knowledge is interpreted as a collection of elastic or, equivalently , fuzzy constraint on a collection of variables
  • Inference is viewed as a process of propagation of elastic constraints.
The third statement hence, define Boolean logic as a subset of Fuzzy logic.

Fuzzy Sets

Fuzzy Set Theory was formalised by Professor Lofti Zadeh at the University of California in 1965. What Zadeh proposed is very much a paradigm shift that first gained acceptance in the Far East and its successful application has ensured its adoption around the world.

A paradigm is a set of rules and regulations which defines boundaries and tells us what to do to be successful in solving problems within these boundaries. For example the use of transistors instead of vacuum tubes is a paradigm shift - likewise the development of Fuzzy Set Theory from conventional bivalent set theory is a paradigm shift.

Bivalent Set Theory can be somewhat limiting if we wish to describe a 'humanistic' problem mathematically. For example, Fig 1 below illustrates bivalent sets to characterise the temperature of a room.


The most obvious limiting feature of bivalent sets that can be seen clearly from the diagram is that they are mutually exclusive - it is not possible to have membership of more than one set ( opinion would widely vary as to whether 50 degrees Fahrenheit is 'cold' or 'cool' hence the expert knowledge we need to define our system is mathematically at odds with the humanistic world). Clearly, it is not accurate to define a transiton from a quantity such as 'warm' to 'hot' by the application of one degree Fahrenheit of heat. In the real world a smooth (unnoticeable) drift from warm to hot would occur.

This natural phenomenon can be described more accurately by Fuzzy Set Theory. Fig.2 below shows how fuzzy sets quantifying the same information can describe this natural drift.

The whole concept can be illustrated with this example. Let's talk about people and "youthness". In this case the set S (the universe of discourse) is the set of people. A fuzzy subset YOUNG is also defined, which answers the question "to what degree is person x young?" To each person in the universe of discourse, we have to assign a degree of membership in the fuzzy subset YOUNG. The easiest way to do this is with a membership function based on the person's age.

young(x) = { 1, if age(x) <= 20,

(30-age(x))/10, if 20 < age(x) <= 30,

0, if age(x) > 30 }

A graph of this looks like:


Given this definition, here are some example values:

Person    Age    degree of youth
---------------------------------------
Johan     10        1.00 
Edwin     21        0.90
Parthiban 25        0.50
Arosha    26        0.40
Chin Wei  28        0.20
Rajkumar  83        0.00 

So given this definition, we'd say that the degree of truth of the statement "Parthiban is YOUNG" is 0.50.

Note: Membership functions almost never have as simple a shape as age(x). They will at least tend to be triangles pointing up, and they can be much more complex than that. Furthermore, membership functions so far is discussed as if they always are based on a single criterion, but this isn't always the case, although it is the most common case. One could, for example, want to have the membership function for YOUNG depend on both a person's age and their height (Arosha's short for his age). This is perfectly legitimate, and occasionally used in practice. It's referred to as a two-dimensional membership function. It's also possible to have even more criteria, or to have the membership function depend on elements from two completely different universes of discourse.

Fuzzy Set Operations.

Union

The membership function of the Union of two fuzzy sets A and B with membership functions and respectively is defined as the maximum of the two individual membership functions. This is called the maximum criterion.

The Union operation in Fuzzy set theory is the equivalent of the OR operation in Boolean algebra.

Intersection

The membership function of the Intersection of two fuzzy sets A and B with membership functions and respectively is defined as the minimum of the two individual membership functions. This is called the minimum criterion.

The Intersection operation in Fuzzy set theory is the equivalent of the AND operation in Boolean algebra.

Complement

The membership function of the Complement of a Fuzzy set A with membership function is defined as the negation of the specified membership function. This is caleed the negation criterion.

The Complement operation in Fuzzy set theory is the equivalent of the NOT operation in Boolean algebra.

The following rules which are common in classical set theory also apply to Fuzzy set theory.

De Morgans law

,

Associativity

Commutativity

Distributivity

Glossary

Universe of Discourse
The Universe of Discourse is the range of all possible values for an input to a fuzzy system.

Fuzzy Set
A Fuzzy Set is any set that allows its members to have different grades of membership (membership function) in the interval [0,1].

Support
The Support of a fuzzy set F is the crisp set of all points in the Universe of Discourse U such that the membership function of F is non-zero.

Crossover point
The Crossover point of a fuzzy set is the element in U at which its membership function is 0.5.

Fuzzy Singleton
A Fuzzy singleton is a fuzzy set whose support is a single point in U with a membership function of one.



Fuzzy Rules and Fuzzy Contol

Fuzzy Rules

Human beings make descisions based on rules. Although, we may not be aware of it, all the descisions we make are all based on computer like if-then statements. If the weather is fine, then we may decide to go out. If the forecast says the weather will be bad today, but fine tommorow, then we make a descision not to go today, and postpone it till tommorow. Rules associate ideas and relate one event to another.
Fuzzy machines, which always tend to mimic the behaviour of man, work the same way. However, the descision and the means of choosing that descision are replaced by fuzzy sets and the rules are replaced by fuzzy rules. Fuzzy rules also operate using a series of if-then statements. For instance, if X then A, if y then b, where A and B are all sets of X and Y. Fuzzy rules define fuzzy patches, which is the key idea in fuzzy logic.
A machine is made smarter using a concept designed by Bart Kosko called the Fuzzy Approximation Theorem(FAT). The FAT theorem generally states a finite number of patches can cover a curve as seen in the figure below. If the patches are large, then the rules are sloppy. If the patches are small then the rules are fine.


Fuzzy Patches
In a fuzzy system this simply means that all our rules can be seen as patches and the input and output of the machine can be associated together using these patches. Graphically, if the rule patches shrink, our fuzzy subset triangles gets narrower. Simple enough? Yes, bcause even novices can build control systems that beat the best math models of control theory. Naturally, it is math-free system.

Fuzzy Control
Fuzzy control, which directly uses fuzzy rules is the most important application in fuzzy theory. Using a procedure originated by Ebrahim Mamdani in the late 70s, three steps are taken to create a fuzzy controlled machine:

1)Fuzzification(Using membership functions to graphically describe a situation)
2)Rule evaluation(Application of fuzzy rules)
3)Defuzzification(Obtaining the crisp or actual results)
As a simple example on how fuzzy controls are constructed, consider the following classic situation: the inverted pendulum. Here, the problem is to balance a pole on a mobile platform that can move in only two directions, to the left or to the right. The angle between the platform and the pendulum and the angular velocity of this angle are chosen as the inputs of the system. The speed of the platform hence, is chosen as the corresponding output.

Step 1
First of all, the different levels of output (high speed, low speed etc.) of the platform is defined by specifying the membership functions for the fuzzy_sets. The graph of the function is shown below

Similary, the different angles between the platform and the pendulum and...

the angular velocities of specific angles are also defined

Note: For simplicity, it is assumed that all membership functions are spreaded equally. Hence, this explains why no actual scale is included in the graphs.

Step 2
The next step is to define the fuzzy rules. The fuzzy rules are mearly a series of if-then statements as mentioned above. These statements are usually derived by an expert to achieve optimum results. Some examples of these rules are:
i) If angle is zero and angular velocity is zero then speed is also zero. ii) If angle is zero and angular velocity is low then the speed shall be low.
The full set of rules is summarised in the table below. The dashes are for conditions, which have no rules ascociated with them. This is don eto simplify the situation.


-----
Speed Angle
------------ negative high negative low zero positive low positive high
v negative high ------------ ----------- negative high --------- ---------
e negative low --------- --------- negative low zero --------
l zero negative high negative low zero positive low positive high
o positive low --------- zero low ----------- ---------
c--------- --------- high ---------- --------- ----------

An application of these rules is shown using specific values for angle and angular velocities. The values used for this example are 0.75 and 0.25 for zero and positive-low angles, and 0.4 and 0.6 for zero and negative-low angular velocities. These points sre on the graphs below.

Consider the rule "if angle is zero and angular velocity is zero, the speed is zero". The actual value belongs to the fuzzy set zero to a degree of 0.75 for "angle" and 0.4 for "angular velocity". Since this is an AND operation, the minimum criterion is used , and the fuzzy set zero of the variable "speed" is cut at 0.4 and the patches are shaded up to that area. This is illustrated in the figure below.

Similarly, the minimum criterion is used for the other three rule. The following figures show the result patches yielded by the rule "if angle is zero and angular velocity is negative low, the speed is negative low", "if angle is positive low and angular velocity is zero, then speed is positive low" and "if angle is positive low and angular velocity is negative low, the speed is zero".


The four results overlaps and is reduced to the following figure

Step 3: The result of the fuzzy controller as of know is a fuzzy set (of speed). In order to choose an appropriate representative value as the final output(crisp values), defuzzification must be done. There are numerous defuzzification methods, but the most common one used is the center of gravity of the set as shown below.



Case Study: Fuzzy Traffic Light Controller

This part of the report describes the design procedures of a real life application of fuzzy logic: A Smart Traffic Light Controller. The controller is suppose to change the cycle time depending upon the densities of cars behind green and red lights and the current cycle time.

Background
In a conventional traffic light controller, the lights change at constant cycle time, which is clearly not the optimal solution. It would be more feasible to pass more cars at the green interval if there are fewer cars waiting behind the red lights. Obviously, a mathematical model for this decision is enormously difficult to find. However, with fuzzy logic, it is relatively much easier.
Fuzzy Design
First, eight incremental sensors are put in specific positions as seen in the diagram below.

The first sensor behind each traffic light counts the number cars coming to the intersection and the second counts the cars passing the traffic lights. The amount of cars between the traffic lights is determined by the difference of the reading of the two sensors. For example, the number of cars behind traffic light North is s7-s8.
The distance D, chosen to be 200ft., is used to determine the maximum density of cars allowed to wait in a very crowded situation. This is done by adding the number of cars between to paths and dividing it by the total distance. For instance, the number of cars between the East and West street is (s1-s2)+(s5-s6)/400.
Next comes the fuzzy descision process which uses the three step mentioned above(fuzzyification, rule evaluation and defuzzification).
Step 1
As before, firstly the inputs and outputs of the design has to be determined. Assuming red light is shown to both North and South streets and distance D is constant, the inputs of the model consist of :
1) Cycle Time
2)Cars behind red light
3) Cars behind green light
The cars behind the light is the maximum number of cars in the two directions. The corresponding ouput parameter is the probabilty of change of the current cycle time. Once this is done, the input and output parameters are divided into overlapping member fuctions, each function corresponding to different levels. For inputs one and two the levels and their corresponding ranges are zero(0,1), low(0,7), medium(4,11), high(7,18), and chaos(14,20). For input 3 , the levels are ver short(0,14), short(0,34), medium(14,60), long(33,88), very long(65,100), limit(85,100). The levels of output are no(0), probably no(0.25), maybe(0.5), probably yes (o.75), and yes(1.0). Note: For the output, one value(singleton position) is asosciated to each level instead of a range of values. The corresponding graphs for each of these membersip function is drawn in the similar way above.
Step 2
The rules, as before are formulated using a series of if-then statements, combined with AND/OR opearotors. Ex: if cycle time is medium AND Cars Behind Red is low AND Cars Behind Green is medium, then change is Probably Not. With three inputs, each having 5,5,and 6 membership functions, there are a combination of 150 rules. However using the minimum or maximum criterion some rules are combined to a total of 86.
Step 3
This process, also mentioned above converts the fuzzy set output to real crisp value. The method used for this system is center of gravity:

Crisp Output={Sum(Membership Degree*Singleton Position)}/(Membership degree) For example, if the output membership degree, after rule evaluation are:
Change Probability Yes=0, Change Probability Probably Yes=0.6, Change Probability Maybe=0.9, Change Probability Probably No= 0.3, Change Probability No=0.1
then the crisp value will be: Crisp Output=(0.1*0.00) +(0.3*0.25)+(0.9*0.50)+(0.6*0.75)+(0*1.00)/0.1+0.3+0.9+0.6+0 =0.51

Is Fuzzy Controller better ?
Testing of the controller
The fuzzy controller has been tested under seven different kinds of traffic conditions from very heavy traffic to very lean traffic. 35 random chosen car densities were grouped according to different periods of the day representing those traffic conditions.
Performance evaluation
The performace of the controller was compared with that of a conventional controller and a human expert. The criteria used for comparison were number of cars allowed to pass at one time and average waiting time. A performance index which maximises the traffic flow and reduces the average waiting time was developed. A means of calculating the average waiting time was also developed, however, a detailed calculation of this evaluation is beyond the scope of this article. All three traffic controller types were compared and can be summarized with the following graph of performance index in all seven traffic categories.

Performance Index for 7 different traffic catagories

Conclusion
The fuzzy controller passed through 31% more cars, with an average waiting time shorter by 5% than the theoretical minimum of the conventional controller. The performance also measure 72% higher. This was expected. However, in comparison with a human expert the fuzzy controller passed through 14% more cars with 14% shorter waiting time and 36% higher performance index. Result: Machine beats Man!!!!

In conclusion, as Man gets hungry in finding new ways of improving our way of life, new, smarter machines must be created. Fuzzy logic provides a simple and efficient way to meet these demands and the future of it is limitless.



Adaptive Fuzzy Systems

Background
As of now the "smartness" of our fuzzy machines are dependent on the rules given. The greater the number of rules, the "smarter" the machine gets. However, this means that the performance of the fuzzy machines is restricted by the capabilities of the human brain. Therefore, how do we make the machines think for themselves and come up with rules of its own?

Consider the way the human beings learn. We all learn through experience and through experience we become smarter. Whether, it is the smell of lime, or the picture of our mother, we remember things as it is given to us. With memory, we improve on our actions or thoughts and by defintion become smarter. Fuzzy logic can be applied the same way. Instead, of depending on humans to put specifc fuzzy rules to deal with every situation, the machine should be able to produce its own rules through experience. This can be done with the Data In Rules Out(DIRO) method.

Data In Rule Out
The DIRO method is simple, put data in through a black box and rules come out as shown in the figure below.


Data In Rules Out

Nueral networks, which fill the black box is beyond the scope of this article. However, it is important to note that it is neural networks, which acts like the eyes and ears of an adaptive fuzzy system whose rule changes with experience. The adaptive fuzzy system tunes its rules as it samples new data. At first the rules change fast. This lets the fuzzy system find a working set of fuzzy rules. Then with more samples, the rules change and fine tunes itself and as the saying goes practice makes perfect.

Simple Case Study: An Adaptive Fuzzy Air Conditioner
As an example, consider an air-conditioner controller, which controls the speed of its motor according the the temperature of the surrounding. Fuzzy subsets and member functions are written for this application in the similar way as before. The two subsets used are the temperature of the surrounding as inputs and speed of the motor as outputs. As usual the two sets overlap to produce fuzzy patches. Because at first, five rules are defined, there are five patches. Each patch will cover data which are represented here as points. Using an expert, we can place logical data points on each patch of the system. The expert adjusts the speed of the motor according to what temperature of the room she or he feels appropriate.

The nueral nets used in this example are called the adaptive vector quantizers (AVQ) which are suppose to come up with rules by itself. Each web of nueron in the system is defined as AVQ points. As data comes in, the AVQ point tries to move closer to it. The nuerons then "compete" with each other and "wins" if its AVQ point is closest to the data. How the AVQ points move about is again beyond the scope of this report.
The whole system can be seen in the figure below. The big black dots represent the AVQ point and the small dots represent the data points.


Adaptive Fuzzy System

The number of rules taken now, simply depends on the number of AVQ points in the rule cells. If a cell has an AVQ point, the that rule is added add to our list of rules. Some cells which have more than one rule in it, are used more often making them more inportant. Note: It is more feasible usually to have not more than two rules per cell as this cuts down on bad rules. With more data the expert is no longer needed as the system starts generating its own rules. With practise the system may enventually win over the expert.

Conclusions
This method is just one of the many methods used to generate rules in an adaptive sytem. Thougha simple example was used to illustrate the system, it is important to realize how powerful this system is. In Japan, research is currently being made to use adaptive systems to model events in politics, history, medicine and even military planning. Imagine in the future, we may even have a Fuzzy British Prime Minister !!



How far can fuzzy logic go???

Just from the examples given previously, it is clear that fuzzy logic can be used in numerous applications. It can appear almost anyplace where computers and modern control theory are overly precise as well as in tasks requiring delicate human intuition and experience-based knowledge. What does the future hold? Consider, the example below which is currently undergoing intensive research in OMRON Research Center, Japan.

It may seem obvious that babies nowadays don't drink the way it is described in child care books. They may drink a little or a lot depending on their physical condition, mood, and other factors. But if a fuzzy-logic program can be created that would recommend how much to feed the baby, mothers would have an easier time raising the child. The basis of the research is to develop a program to determine the appropriate amount of milk to feed the child according to a knowledge base that includes the child's personality, physical condition, and some environmental factors. This can prevent the child from being fed unnecessarily. Now although adapting fuzzy logic to babies may seem silly, one can easily imagine using it to control the feeding of animals in captivity, for instance.

Wanna see more. Well, here are some of the future fuzzy uses as predicted by Professor Bart Kosko from UC Southern California:

Vast expert decision makers , theoretically able to distill the wisdom of every document ever witten.
Sex robots with a humanlike repertoire of behaviour,
Computers that understand and respond to normal human language.
Machines that write interesting norvels and screenplays in a selected style , such as Hemingway's.
Molecule-sized soldiers of health that will roam the blood-stream, killing cancer cells and slowing the aging process.

Hence, it can be seen that with the enormous reseach currently being done in Japan and many other countries whose eyes have opened, the future of fuzzy logic is undetermined. There is no limit to where it can go.
The future is bright. The future is fuzzy.





Previous page click here
Return to main page click here

Hosted by www.Geocities.ws

1