• Aucun résultat trouvé

MEMBERSHIP FUNCTIONS, FUZZIFICATION AND DEFUZZIFICATION

Dans le document FUZZY EXPERT SYSTEMS AND FUZZY REASONING (Page 190-198)

10 Simple Example Programs

10.6 MEMBERSHIP FUNCTIONS, FUZZIFICATION AND DEFUZZIFICATION

10.6.1 Membership Functions in FLOPS/

Membership functions in FLOPS are specified by thememfcommand. This permits the programmer to specify the point at which the membership function first begins to rise from zero; the point at which it first reaches 1; the point at which it first starts down from 1; and the point at which the function reaches zero again. If the function stays at 1 from -infinity until it starts to drop, the first parameter is set to21e6; if the function remains at 1 after rising from 0, the last parameter is set to 21e6. An additional parameter is the shape of the membership function; piecewise linear, piecewise quadratic, or normally distributed (Gaussian). (In the case of normal functions, the first and last parameters are the point at which the membership func-tion reaches 0.5.)

Membership functions are displayed by thedrawmemfcommand. Figure 10.1 shows a typical membership function plot.

10.6 MEMBERSHIP FUNCTIONS, FUZZIFICATION AND DEFUZZIFICATION 173

The example program drawmemf.fps illustrates the use of the drawmemf command.

:******************************************************

:DRAWMEMF.FPS - illustrates drawmemf command

:******************************************************

message "Program DRAWMEMF.FPS to illustrate the drawmemf command.";

:Specifications for the individual functions are given in the :memfunct command. The first number is the point where the :function first begins to rise from zero; the second number is :the point where the function reaches 1000. The third number is :the point where the function begins to decline from 1000; the :fourth number is the point where it reaches zero again.

:If the first number is -1e6, the function starts at 1000 for all

:values less than the third number, where it begins to decline :toward zero; the only effect of the second number is to tell :drawmemf where to start its plot.

:Similarly, if the fourth number is 1e6, the function never :declines toward zero after its initial rise to 1000 at the value :given by the second number; the only effect of the third number :is to tell drawmemf where to stop its plot.

message "First membership functions are linear." ; Figure 10.1 Output of drawmemf command to display membership functions.

declare Data size fzset (SMALL MEDIUM LARGE);

memfunct Data size linear SMALL -1e6 0 2 4

MEDIUM 2 4 4 8 LARGE 4 8 10 1e6 ; drawmemf Data size;

message "Next membership functions are s-shape." ; memfunct Data size s-shape

SMALL -1e6 0 2 4 MEDIUM 2 4 4 8 LARGE 4 8 10 1e6 ; drawmemf Data size;

message "Last membership functions are normal.";

memfunct Data size normal SMALL -1e6 0 2 4

MEDIUM 2 4 4 8 LARGE 4 8 10 1e6 ; drawmemf Data size;

message "DRAWMEMF.FPS finished." ; :exit ;

*******************************************************

10.6.2 Fuzzifying Numbers in FLOPS

Fortunately, there is only one generally accepted way of fuzzifying a number. As we have shown, fuzzifying takes place as shown in Figure 10.2.

The FLOPS commandfuzzifyis used to fuzzify a number into grades of mem-bership of a discrete fuzzy set. (A fuzzy set whose members describe a number is called alinguistic variable.)

Program fuzzify.par illustrates the use of thefuzzifycommand.

:******************************************************

:program FUZZIFY.PAR - fuzzifies

:******************************************************

thresh 1;

declare Data x flt size fzset (small medium large);

10.6 MEMBERSHIP FUNCTIONS, FUZZIFICATION AND DEFUZZIFICATION 175

memfunct Data size normal small -1e6 1 2

medium 1 2 2 3 large 2 3 1e6;

:rule r0

rule (goal Fuzzifies x into fuzzy set size) IF (in Data x = <X> AND x <= 3.5)

THEN

message ’Fuzzifying <X>\n’, fuzzify 1 size <X>,

fire block 0 off, fire block 1 on;

:Permit firing rules with zero confidence in fuzzy set member

TestFsetOff;

rule block 1 (goal Prints out results of fuzzification) IF (in Data x = <X> AND size.small = <S> AND size.medium = <M>

AND size.large = <L>) THEN

message ’<X> fuzzified: small <S> medium <M> large

<L>\n’, reset,

in 1 x = (<X> + 0.5), fire block 1 off, fire block 0 on;

Figure 10.2 Fuzzifying 2.5; Small 0.25, Medium 0.75, Large 0.

make Data ^x 0.5 ;

string = "Program fuzzify.PAR\n";

string + "We have only two rules, one to fuzzify, one to print results.\n" ;

string + "Rule r0 will fuzzify several values of an input, x, ";

string + "Into a fuzzy set size with three members\:

small,

medium, large.\n";

message "<string>";

prule r0;

fire block 1 off;

message ’Here are the membership functions for fuzzy set size:\n’;

drawmemf Data size;

message ’Ready to run\n’ ; :run ;

:message ’Fuzzification demonstration finished.\n’ ; :exit ;

:******************************************************

10.6.3 Defuzzification in FLOPS

Unlike fuzzification, there are many methods of defuzzification. FLOPS provides the popularcentroidmethod; and also theaverage maximummethod. The FLOPS defuzzify command in FLOPS makes defuzzification simple. Program defuzz.fps illustrates the defuzzification method. Because FLOPS only stores confi-dences with a resolution of one part in a thousand, the defuzzified value may differ slightly from the original fuzzified value.

:++++++++++++++++++++++++++++++++++++++++++++++++++++++

:program DEFUZZ.PAR

:++++++++++++++++++++++++++++++++++++++++++++++++++++++

message ’Compiling program DEFUZZ to fuzzify and defuz-zify height of a person\n’ ;

thresh 1 ; declare Data

height flt defuzz flt

10.6 MEMBERSHIP FUNCTIONS, FUZZIFICATION AND DEFUZZIFICATION 177

size fzset

( Short Medium Tall) ; memfunct Data size linear

Short -1e6 4 4.5 5.5 Medium 4.5 5.5 5.5 6.5 Tall 5.5 6.5 7 1e6 ;

message ’Membership functions for fuzzy set size\:\n’ ; drawmemf Data size ;

:rule r0

rule (goal Enter height data) IF ( in Data height.cf = 0 ) THEN

input "Enter person\’s height in feet\, 0 to quit\n" 1 height ;

:rule r1

rule (goal Quit on entry of zero height) IF ( in Data height 0 )

THEN

message nocancel ’Terminating program DEFUZZ\n’ , exit ;

:rule r2

rule (goal Fuzzify height into fuzzy set size) IF ( in Data height <H> AND height > 0 )

THEN

message ’Height before fuzzification: <H>\n’, fuzzify 1 size <H> ,

fire block 0 off , fire block 1 on ;

:enable firing rule with zero confidence in fuzzy set members

TestFsetOff ;

rule block 1 (goal Print fuzzy set size\, defuzzify into defuzz)

IF (in Data defuzz.cf = 0 size.Short <S> size.Medium <M>

size.Tall <T>) THEN

message ’Fuzzified height:\nShort <S> Medium <M> Tall

<T>\n’,

defuzzify 1 size maxav 1 defuzz;

rule block 1 (goal Print defuzzified value\, re-initialize program)

message ’Program DEFUZZ ready to run\n’ ; :run ;

:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

10.7 SUMMARY

Even extremely simple programs such as those in this chapter can illustrate funda-mental features of writing, running, and debugging FLOPS programs. The basic structure of these programs is typical of more complex programs: declaration of data structures; rules, commonly partitioned into numbered blocks; and creation of data bymake(or data acquisition) commands.

There is a very substantial difference between the ways in which sequential and parallel programs are executed. Suppose that we have eight rules concurrently fire-able. In sequential mode, one of these is picked for firing according to some criteria (usually called arule conflict algorithm); the rest are placed on a stack for firing if no rules are newly fireable, calledbacktracking. In parallel mode, however, all fire-able rules are fired effectively in parallel; since there are no unfired rules, there are no rules to place on a backtrack stack.

If parallel FLOPS can be used, it is much more efficient than sequential FLOPS, since systems overhead is greatly reduced. Parallel FLOPS is especially appropriate for discrete fuzzy sets, since all fuzzy set members are processed effectively simul-taneously, making the programming relatively simple and unconvoluted compared to sequential programs. In either case, FLOPS has two operational modes; run mode, in which rules are fired and their consequent instructions executed; and command mode, in which FLOPS command are executed one at a time, from the FLOPS program or from the keyboard. Executing commands from the keyboard is especially convenient for interactive debugging.

In seems to be axiomatic that newly written programs will not run, and FLOPS is not an exception. Debugging in a data-driven language is not the same as debugging a procedural program, and special techniques are required. FLOPS has the ability to

10.7 SUMMARY 179

single-step through a program using therun 1;command, or to halt the program when desired by setting rule breakpoints or using therun N;command, where N is the number of rule-firing steps to execute before reverting from run-to-command mode. Probably the two most important debug commands to use together with run 1; are prdata; for inspecting data, and prstack; for seeing which rules are newly fireable. There are a number of other very useful debug commands available that should not be neglected.

10.8 QUESTIONS

10.1 In a simple FLOPS program we have three major program sections and a run command. What are the three program sections?

10.2 In what order must these section and the run command appear in the program?

10.3 Why must the data declarations come first?

10.4 Why must rule commands precede data creation?

10.5 Three important debugging commands are (a)prstack, (b)prdata, and (c)run N. What purpose do these commands serve?

10.6 a. What is the :LOCAL stack in FLOPS?

b. In what order are the rules on the LOCAL stack listed?

c. What is the meaning of thepconfsymbol?

10.7 What are the LOCAL and PERMANENT rule stacks?

10.8 In what order are the rules on the LOCAL and PERMANENT stacks listed?

10.9 What information about the rules is presented by theprstackcommand?

10.10 What is the primary difference between serial and parallel FLOPS?

10.11 In terms of availability of information, how do we choose between serial and parallel FLOPS?

11 Running and Debugging

Dans le document FUZZY EXPERT SYSTEMS AND FUZZY REASONING (Page 190-198)