``````NAME
AI::Fuzzy - Perl extension for Fuzzy Logic

SYNOPSIS
use AI::Fuzzy;

my \$f = new AI::Fuzzy::Label;

for (my \$x = 0; \$x<50; \$x+=4) {
print "\$x years old => " . \$f->label(\$x) . "\n";
}

\$a = new AI::Fuzzy::Set( x1 => .3, x2 => .5, x3 => .8, x4 => 0, x5 => 1);
\$b = new AI::Fuzzy::Set( x5 => .3, x6 => .5, x7 => .8, x8 => 0, x9 => 1);
print "a is: " . \$a->as_string . "\n";
print "b is: " . \$b->as_string . "\n";

print "a is equal to b" if (\$a->equal(\$b));

\$c = \$a->complement();
print "complement of a is: " . \$c->as_string . "\n";

\$c = \$a->union(\$b);
print "a union b is: " . \$c->as_string . "\n";

\$c = \$a->intersection(\$b);
print "a intersection b is: " . \$c->as_string . "\n";

__END__

DESCRIPTION
AI::Fuzzy really consists of two modules - AI::Fuzzy::Label and
AI::Fuzzy::Set.

A fuzzy set is simply a mathematical set to which members can
*partially* belong. For example, a particular shade of gray may
partially belong to the set of dark colors, whereas black would have
full membership, and lemon yellow would have almost no membership.

A fuzzy labeler classifies a particular crisp value by examining the
degree to which it belongs to several sets, and selecting the most
appropriate. For example, it can decide whether to call water at 60
degrees Farenheight "cold", "cool", or "warm". A fuzzy label might be
one of these labels, or a fuzzy set describing to what degree each of
the labels describes the particular value in question.

Fuzzy Sets

AI::Fuzzy:Set has these methods:

\$fs = B<new> AI::Fuzzy::Set;

# here, "Bob" is unquestionably tall.. the others less so.
\$fs_tall_people = B<new> AI::Fuzzy::Set( Lester=>.34, Bob=>1.00, Max=>.86 );

# \$x will be .86
\$x = B<membership> \$fs_tall_people, "Max";

# get list of members, sorted from least membership to greatest:
@shortest_first = B<members> \$fs_tall_people;

\$fs = B<new> AI::Fuzzy::Set( x1 => .3, x2 => .5, x3 => .8, x4 => 0, x5 => 1);

B<complement>, B<union>, B<intersection>
Thesie are the fuzzy set version of the typical functions.

B<equal>
Returns true if the sets have the same elements and those elements
are all equal.

B<as_string>
Prints the set as tuples:
\$b = new AI::Fuzzy::Set( x5 => .3, x6 => .5, x7 => .8, x8 => 0, x9 => 1);
print "b is: " . \$b->as_string . "\n";
prints:
b is: x8/0, x5/0.3, x6/0.5, x7/0.8, x9/1

Fuzzy Labels

A Fuzzy::Label label has four attributes: the text of the label (it can
be any scalar, really), and three numbers: low, mid, high if you imagine
a cartesian plane (remember graph paper in algebra?) of all possible
values, the label applies to a particular range. the graph might look
something like this:

|Y               * (mid, 1)
|               /  \
|             /    \
|           /       \
|         /          \
-|-------*-------------*------- X
(low,0)      (high,0)

the Y value is applicability of the label for a given X value

the mid number is the "pure" value. eg, orange is at 0 or 360 degrees on
the color wheel. the label applies 100% at the mid point.

the low and high numbers are the two points at which the label ceases to
apply.

note that labels can overlap, and that the mid number isn't always in
the exact center, so the slope of the two sides may vary...

\$fl = new AI::FuzzyLabel;

\$fl->addlabel( "hot", 77, 80, 100 ); # what I consider hot. :) (in
Farenheit, of course!)

\$a = \$fl->applicability(\$label, \$value); # \$a is now the degree to which
\$label applies to \$value

\$l = \$fl->label (\$value); # applies a label to \$value

@l = \$fl->label(\$value); # returns a list of labels and their
applicability values

\$s = new AI::Fuzzy::Set( \$fl->label(\$value) ); # same thing, but now
it's an object

@range = \$fl->range(); # returns a list of labels, sorted by their
midpoints # eg: ("cold", "cool", "lukewarm", "warm", "hot")

AUTHOR
Tom Scanlan <tscanlan@openreach.com>, current maintainer

Michal Wallace (sabren@manifestation.com), original author