AI-Fuzzy
view release on metacpan or search on metacpan
- fixed warning messages due to not checking "exists" for hash
values in Set.pm (union,intersection). Thanks to Richard Jelinek
for pointing this out, and a problem in the code in the docs.
0.04 Fri Dec 6 13:49:55 EST 2002
- replaced current AI::Fuzzy::Label with a new AI::Fuzzy::Axis (a container for label objects)
and changed AI::Fuzzy::Label to be concerned only about label data. This
will allow us to add new AI::Fuzzy::Label{Spline, Trapezoid, etc.} subclasses
of labels to the now independent Axis class. Axis will defer to the Label
itself to decide applicability, >,<,>=,<=, and the like.
- changed test.pl to work with the new setup
- added functions: greaterthan, greaterequal, lessthan, lessequal, and between
to AI::Fuzzy::Label
- added overriding of >,>=,<,<=, and <=> in AI::Fuzzy::Label.
0.03 Wed Oct 9 18:07:34 EDT 2002
- added functions: support, core, height, is_normal, is_subnormal
to AI::Fuzzy::Set
0.02 Wed Oct 9 16:41:29 EDT 2002
- ownership transfering to Tom Scanlan <tscanlan@openreach.com>
- added functions to AI::Fuzzy::Set for intersection, union,
complement, equal, and as_string
- made a heck of a lot of tests. use them as examples...
0.01 Mon Jul 19 19:33:46 1999
- original version; created by h2xs 1.18
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.
demo/cpu.pl
demo/fuzz.pl
Changes
Fuzzy.pm
MANIFEST
README
Makefile.PL
test.pl
lib/AI/Fuzzy/Set.pm
lib/AI/Fuzzy/Label.pm
lib/AI/Fuzzy/Axis.pm
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.
lib/AI/Fuzzy/Set.pm view on Meta::CPAN
my $item = shift;
if (defined(${$self->{members}}{$item})) {
return ${$self->{members}}{$item};
} else {
return 0;
}
}
sub members {
# returns list of members, sorted from least membership to greatest
my $self = shift;
my %l = %{$self->{members}};
return sort { $l{$a} <=> $l{$b} } keys %l;
}
sub equal {
# returns true if the argument set is equal to this one
my $self = shift;
my $otherset = shift;
use Test;
BEGIN { plan tests => 17 };
use AI::Fuzzy;
ok(1); # If we made it this far, we're ok.
$l = new AI::Fuzzy::Label;
ok(2); # If we made it this far, we're ok.
$s = new AI::Fuzzy::Set;
ok(3); # If we made it this far, we're ok.
$a = new AI::Fuzzy::Axis;
ok($a->labelvalue(50)->name, "adult");
ok($a->labelvalue(5)->name, "little kid");
$fs_tall_people = new AI::Fuzzy::Set( Lester=>34, Bob=>100, Max=>86 );
# $x will be 86
$x = $fs_tall_people->membership( "Max" );
ok($x, 86);
# get list of members, sorted from least membership to greatest:
@shortest_first = $fs_tall_people->members();
ok @shortest_first, 3, "got " . join(',', @shortest_first) . ", wanted " . join(',', qw(Lester Max Bob));
$a1 = new AI::Fuzzy::Axis;
$a1->addlabel( "cold", 32, 60, 70 );
$a1->addlabel( "warm", 60, 70, 90 );
$a1->addlabel( "hot", 77, 80, 100 );
# what I consider hot. :) (in Farenheit, of course!)
ok $a1;
# a intersection b intersection c should equal b intersection c intersection a
$abc = $sa->intersection($sb);
$abc = $abc->intersection($sc);
$bca = $sb->intersection($sc);
$bca = $bca->intersection($sa);
ok($abc->equal($bca));
# comment this to run extra output tests.
#exit 0;
$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";
#---------- test < and > -----
$f = new AI::Fuzzy::Axis;
$f->addlabel("baby", -1, 1, 2.5);
$f->addlabel("toddler", 1, 1.5, 3.5);
$f->addlabel("little kid", 2, 7, 12);
$f->addlabel("kid", 6, 10, 14);
$f->addlabel("teenager", 12, 16, 20);
$f->addlabel("young adult", 11, 27, 35);
$f->addlabel("adult", 25, 50, 75);
$f->addlabel("senior", 60, 80, 110);
( run in 0.275 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )