At the forefront of Artificial Intelligence
  Home Articles Reviews Interviews JDK Glossary Features Discussion Search
Home » Articles » Uncertainty Handling » Artificial Inference

Defuzzification Options in Flex

By Clive Spenser & Charles Langley

Consider the following (partial) fuzzy logic program in Flex:

% fuzztest.ksl

% (1) Fuzzy set definitions
fuzzy_variable input1 ;
  ranges from 0 to 100 ;
  fuzzy_set small is \ shaped and linear at 0, 50 ;
  fuzzy_set medium is /\ shaped and linear at 25, 50, 75 ;
  fuzzy_set large is / shaped and linear at 50, 100 ;

fuzzy_variable input2 ;
  ranges from 0 to 100 ;
  fuzzy_set small is \ shaped and linear at 0, 50 ;
  fuzzy_set medium is /\ shaped and linear at 25, 50, 75 ;
  fuzzy_set large is / shaped and linear at 50, 100 ;

fuzzy_variable output ;
  ranges from 0 to 100 ;
  fuzzy_set small is \ shaped and linear at 0, 50 ;
  fuzzy_set medium is /\ shaped and linear at 25, 50, 75 ;
  fuzzy_set large is / shaped and linear at 50, 100 ;

  defuzzify using all memberships
    and mirror rule
    and shrinking .

% (2) Fuzzy Rule definitions
fuzzy_rule d_1 if input1 is small and input2 is small then
  output is small.
fuzzy_rule d_2 if input1 is small and input2 is medium then
  output is small.
fuzzy_rule d_3 if input1 is small and input2 is large then
  output is small.
fuzzy_rule d_4 if input1 is medium and input2 is small then
  output is medium.
fuzzy_rule d_5 if input1 is medium and input2 is medium then
  output is medium.
fuzzy_rule d_6 if input1 is medium and input2 is large then
  output is large.
fuzzy_rule d_7 if input1 is large and input2 is small then
  output is small.
fuzzy_rule d_8 if input1 is large and input2 is medium then
  output is medium.
fuzzy_rule d_9 if large is small and input2 is large then
  output is large.

Fuzzy Inference

To determine the value of the output in the above fuzzy program there are three distinct steps:
  1. fuzzify the values of the two input variables
  2. propagate the rules to determine the fuzzy value of the output variable
  3. defuzzify the output variable.
Fuzzifying the value of a variable is straightforward, simply determining the degree of membership that the value has (between 0 and 1) for each of the variable’s component fuzzy sets according to their shapes (membership functions).

For example, let us suppose that the value of input1 is 40 and the value of input 2 is 60. We might intuitively say that input1 is somewhat small and somewhat medium but not at all large whilst input2 is somewhat medium and somewhat large and not at all small.

If we set the fuzzy_trace mechanism on, this is what we see at the fuzzification stage:

Mem. : UPDATE     : (input1 is small) = 0.2
Mem. : UPDATE     : (input1 is medium) = 0.6
Mem. : UPDATE     : (input1 is large) = 0
Mem. : FUZZIFY    : input2 = 60
Mem. : UPDATE     : (input2 is small) = 0
Mem. : UPDATE     : (input2 is medium) = 0.6
Mem. : UPDATE     : (input2 is large) = 0.2
Here we see that input1 has been assigned the possibility values of 0.2 for small, 0.6 for medium and 0 for large. This is its degree of membership of these three sets.

Rule Propagation

After fuzzification the rules are propagated. First d_1. Since input1 is partially small but input2 is not at all small we get:
fuzzy_rule d_1 if input1 is small and input2 is small then
  output is small.

Mem. : TRY        : d_1
Mem. : LOOKUP     : (input1 is small) = 0.2
Mem. : LOOKUP     : (input2 is small) = 0
Mem. : AND        : 0.2 + 0 -> 0
Mem. : UPDATE     : (output is small) = 0
Mem. : FIRED      : d_1
At this point the possibility value for output is small is 0, but since input2 is partially medium, rule d_2 will update this as follows:
fuzzy_rule d_2 if input1 is small and input2 is medium then
  output is small.

Mem. : TRY        : d_2
Mem. : LOOKUP     : (input1 is small) = 0.2
Mem. : LOOKUP     : (input2 is medium) = 0.6
Mem. : AND        : 0.2 + 0.6 -> 0.2
Mem. : LOOKUP     : (output is small) = 0
Mem. : CONFIRMS   : 0 + 0.2 -> 0.2
Mem. : UPDATE     : (output is small) = 0.2
Mem. : FIRED      : d_2
Since input1 is partially small and input2 is partially large, the rule d_3 will give the following result:
fuzzy_rule d_3 if input1 is small and input2 is large then
  output is small.

Mem. : TRY        : d_3
Mem. : LOOKUP     : (input1 is small) = 0.2
Mem. : LOOKUP     : (input2 is large) = 0.2
Mem. : AND        : 0.2 + 0.2 -> 0.2
Mem. : LOOKUP     : (output is small) = 0.2
Mem. : CONFIRMS   : 0.2 + 0.2 -> 0.2
Mem. : UPDATE     : (output is small) = 0.2
Mem. : FIRED      : d_3
The last two rules have both updated the value of output is small to 0.2. This process of updating continues throughout the ruleset until the final update for membership of each of output's three fuzzy sets.

The Defuzzification process

After rule propagation comes deffuzzification to provide a crisp value for Output.
Mem. : DE-FUZZIFY : centroid(all_memberships,mirror_rule,shrinking) @ output
Mem. : LOOKUP     : (output is small) = 0.2
Mem. : LOOKUP     : (output is medium) = 0.6
Mem. : LOOKUP     : (output is large) = 0.2
Mem. : DE-FUZZIFI : output = 50
Output = 50

Two steps of defuzzification

Defuzzification takes place in two distinct steps. First the membership functions are scaled according to their possibility values, secondly the scaled membership functions are used to obtain the centroid of the joint fuzzy sets.

Scaling

Since the possibility values for the fuzzy variable output are small=0.2, medium=0.6, large=0.2, the above diagram shows how the membership functions are scaled.

Finding the Centroid

Once scaling has taken place, the centroid can be found by calculating the balance point of the conjoined scaled functions. A useful analogy given by Hopgood (Intelligent Systems for Engineers and scientists, p.81, ISBN 0-8493-0456-3, CRC Press) invites us to see the scaled functions as overlapping pieces of stiff cardboard. Imagine them glued together and then find the point on this surface where the card could be balanced on a pin. The position of this point on the horizontal axis is the resulting crisp defuzzified value for the variable.

Options in defuzzification

The program we are considering uses three fuzzy variables, input1, input2 and output. The definition of the output variable contains three options for how the variable is defuzzified:
defuzzify using all memberships           <--- Option 1
  and mirror rule                         <--- Option 2
  and shrinking .                         <--- Option 3
Option 1 can be all memberships or largest membership
Option 2 can be mirror rule or bounded or inverse
Option 3 can be shrinking or truncation

Let us look at these options in turn.

All Memberships versus Largest Membership

When the value of a fuzzy variable is defuzzified, a choice exists as to which of its memberships of its component fuzzy sets should be taken into account. Taking into account membership of all fuzzy sets is the normal behaviour, but it is possible to only use the fuzzy set of which it has the largest membership. This results in an output which is much like the step-wise function typical of non-fuzzy production rule inference as in the second of the two diagrams below:

All Memberships + Mirror Rule + Shrinking


figure 1

Largest Membership + Mirror Rule + Shrinking


figure 2

Mirror Rule Versus Bounded Versus Inverse

As can be seen in the definition of the fuzzy variable output, the two sets at the extremes are small and large which (before scaling) have the shapes \ and / respectively.

Whenever we have such shapes at the extremes of the fuzzy graph we have a problem finding the balance point since the extreme functions continue indefinitely to the left and to the right respectively.

There are various ways of overcoming this problem. One is by considering these extreme functions to be mirrored symmetrically at the boundaries of their ranges, another is to simply treat all values beyond the boundaries as being the same value as at the boundaries. The former method is known as the mirror rule and the latter as the bounded range method.

Both previous graphs show defuzzified outputs using the mirror rule. Figures 3 and 4 below show what they would look like if we had used the bounded parameter instead. Note that this means that the defuzzified values of the variable can never reach the extremes of their ranges (0 and 100 in our case).

All Memberships + Bounded Range + Shrinking


figure 3

Largest Membership + Bounded + Shrinking


figure 4

The final method for dealing with defuzzification at the extremes is inverse. The range of outputs acheived using it is shown in figure 5.

All Memberships + Inverse + Shrinking


figure 5

This somewhat bizarre shape shows the effect of the following rule: for the extreme sets, look up the value that would fuzzify to the membership and use this value instead of the individual centroids of the sets in finding the overall centroid.

Shrinking Versus Truncation

The final defuzzification option we have is shrinking versus truncation. The distinction here is one of how we scale the membership functions as opposed to how we obtain the centroid. The truncation method of scaling is the first of the two diagrams below, the shrinking method is the second.

Truncation

Shrinking

Graphs of the output derived using the truncation parameter are virtually indistinguishable from those we showed above for this example using shrinking.

Defuzzification Calculated

For completeness we will now show how the defuzzified value of the output variable is calculated using Larsen’s product operation rule. The example uses All Memberships + Mirror Rule + Shrinking as the defuzzification options.

We need to know two things, the final possibility values for output after all fuzzy rules have fired and the centre points of the base of each of the triangular fuzzy sets which make up the fuzzy variable output.

Running the trace with inputs at 40 and 60 we get the following:

Mem. : DE-FUZZIFY : centroid(all_memberships,mirror_rule,shrinking) @ output
Mem. : LOOKUP     : (output is small) = 0.2
Mem. : LOOKUP     : (output is medium) = 0.6
Mem. : LOOKUP     : (output is large) = 0.2
Mem. : DE-FUZZIFI : output = 50
C = 50
Thus the possibility values are 0.2, 0.6, 0.2. Let us call these P1, P2, P3.

The three sets have the midpoints along their bases at 0, 50 100 (after the mirror rule is applied). Call these C1, C2, C3.

The calculation is:

     Sum( (Pi * Ci ) )
     ------------------
     Sum( Pi )

=    (0.2 * 0) + (0.6 * 50) + (0.2 * 100)
      -------------------------------------------
     (0.2 + 0.6 + 0.2)

= 0 + 30 + 20 --------------- = 50 1
Note that we are able to use the midpoints of the triangle's bases as Ci here because the triangles are all equilateral. Had they not been then we would have to use their respective areas instead.

Submitted: 29/06/2004

Article content copyright © Clive Spenser & Charles Langley, 2004.
 Article Toolbar
Print
BibTeX entry

Search

Latest News
- Generation5 10-year Anniversary (03/09/2008)
- New Generation5 Design! (09/04/2007)
- Happy New Year 2007 (02/01/2007)
- Where has Generation5 Gone?! (04/11/2005)
- NeuroEvolving Robotic Operatives (NERO) (25/06/2005)

What's New?
- Back-propagation using the Generation5 JDK (07/04/2008)
- Hough Transforms (02/01/2008)
- Kohonen-based Image Analysis using the Generation5 JDK (11/12/2007)
- Modelling Bacterium using the JDK (19/03/2007)
- Modelling Bacterium using the JDK (19/03/2007)


All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -