| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
Defuzzification Options in FlexBy 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 InferenceTo determine the value of the output in the above fuzzy program there are three distinct steps:
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.2Here 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 PropagationAfter 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 processAfter 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 defuzzificationDefuzzification 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
Finding the CentroidOnce 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 defuzzificationThe 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 3Option 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 MembershipWhen 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
Largest Membership + Mirror Rule + Shrinking
Mirror Rule Versus Bounded Versus InverseAs 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
Largest Membership + Bounded + Shrinking
All Memberships + Inverse + Shrinking
Shrinking Versus TruncationThe 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
Defuzzification CalculatedFor 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 = 50Thus 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.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -