Tricks of the Windows Game Programming Gurus:Making Silicon Think with Artificial Intelligence

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

Method 2: The Fuzzy Centroid

To find the fuzzy centroid, you take the fuzzy values for each FLV in the output:

`OFF` | (0.0)
`ON HALF` | (0.14) {average}
`ON FULL` | (0.16)

Plug them into the y-axis of the FLV diagram and fill in the area for each. This is shown in Figure 12.48.

Figure 12.48 Finding the area and the centroids of the fuzzy manifold graphically.

Add the areas up and find the centroid of the resulting geometric shape. As you can see, there are two ways to add the areas up: overlap and additive. Overlapping loses a bit of information, but it’s easier sometimes. The additive technique is more accurate.

The centroids of each method have been computed and are shown in Figure 12.48. That’s great, but the computer isn’t a piece of graph paper. How do you compute the centroid?

To compute a centroid, perform a numerical integration (that’s a calculus term). All this means is that to find the center of area of this fuzzy area object you need to sum up each piece of the object and its contribution to the total and then divide by the total area:

    Domain

    Σ di * domi

    i

    _____________

    Domain

    Σ domi

    i

di is the input value for the domain, and domi is the degree of membership of that value. This is much easier to explain with real examples. In this example, the output domain is from 0.0 to 10.0. This represents the thrust level.

You need a loop variable di that loops from 0 to 10. At each interval of the loop, you’re going to compute the degree of membership that this particular di is in the merged geometry shown in Figure 12.49.

Figure 12.49 Computing the final crisp output from the fuzzy centroid.

Because each triangle has a certain height now that was cut off by the original values, you have to compute the degree of membership with a trapezoid rather than a triangle (but that’s not too bad):

`OFF` | (0.0)
`ON HALF` | (0.14)
`ON FULL` | (0.16)

Here’s the pseudo-code:

    sum        = 0.0;

    total_area = 0.0;

    for (int di = 0; di<=10; di++)

        {

        // compute next degree of membership and add to

        // total area

        total_area = total_area + degree_of_membersip(di);

        // add next contribution of the shape at position di

        sum = sum + di * degree_of_membersip(di);

        } // end for

    // finally compute centroid

    centroid = sum/total_area;

The thing to remember is that the function `degree_of_membership()` is taking the generic values (0..10) and plugging them into the merged output fuzzy manifold, which results from plugging the following fuzzy values into the output variable and finding the area of influence of each one:

OFF | (0.0)
ON HALF | (0.14)
ON FULL | (0.16)

As you can see, using the `MAX()` method sure is a lot easier, and most of the time it works just as well as the centroid.

As for computing a crisp value for the final output rather than a linear value, that’s easy. Just use the `MAX()` method and pigeonhole the output. Or you could select the output domain to be 0,1,2,3,4 and have exactly five crisp output commands. It’s all about scale.

#### Warm and Fuzzy

That about wraps up the topic of fuzzy logic. The idea of fuzzy logic is simple; it’s the actual implementation that’s detailed. There’s no demo this time, but look on the Internet. There are lots of commercial fuzzy logic experimentation programs. They’re a lot better than anything I can write in 20 minutes, which is all the time I have left to write this chapter!

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.