|
AI::FuzzyInference - A module to implement a Fuzzy Inference System. |
AI::FuzzyInference - A module to implement a Fuzzy Inference System.
use AI::FuzzyInference;
my $s = new AI::FuzzyInference;
$s->inVar('service', 0, 10,
poor => [0, 0,
2, 1,
4, 0],
good => [2, 0,
4, 1,
6, 0],
excellent => [4, 0,
6, 1,
8, 0],
amazing => [6, 0,
8, 1,
10, 0],
);
$s->inVar('food', 0, 10,
poor => [0, 0,
2, 1,
4, 0],
good => [2, 0,
4, 1,
6, 0],
excellent => [4, 0,
6, 1,
8, 0],
amazing => [6, 0,
8, 1,
10, 0],
);
$s->outVar('tip', 5, 30,
poor => [5, 0,
10, 1,
15, 0],
good => [10, 0,
15, 1,
20, 0],
excellent => [15, 0,
20, 1,
25, 0],
amazing => [20, 0,
25, 1,
30, 0],
);
$s->addRule(
'service=poor & food=poor' => 'tip=poor',
'service=good & food=poor' => 'tip=poor',
'service=excellent & food=poor' => 'tip=good',
'service=amazing & food=poor' => 'tip=good',
'service=poor & food=good' => 'tip=poor',
'service=good & food=good' => 'tip=good',
'service=excellent & food=good' => 'tip=good',
'service=amazing & food=good' => 'tip=excellent',
'service=poor & food=excellent' => 'tip=good',
'service=good & food=excellent' => 'tip=excellent',
'service=excellent & food=excellent' => 'tip=excellent',
'service=amazing & food=excellent' => 'tip=amazing',
'service=poor & food=amazing' => 'tip=good',
'service=good & food=amazing' => 'tip=excellent',
'service=excellent & food=amazing' => 'tip=amazing',
'service=amazing & food=amazing' => 'tip=amazing',
);
$s->compute(service => 2,
food => 7);
This module implements a fuzzy inference system. Very briefly, an FIS is a system defined by a set of input and output variables, and a set of fuzzy rules relating the input variables to the output variables. Given crisp values for the input variables, the FIS uses the fuzzy rules to compute a crisp value for each of the output variables.
The operation of an FIS is split into 4 distinct parts: fuzzification, inference, aggregation and defuzzification.
In this step, the crisp values of the input variables are used to compute a degree of membership of each of the input variables in each of its term sets. This produces a set of fuzzy sets.
In this step, all the defined rules are examined. Each rule has two parts: the precedent and the consequent. The degree of support for each rule is computed by applying fuzzy operators (and, or) to combine all parts of its precendent, and generate a single crisp value. This value indicates the ``strength of firing'' of the rule, and is used to reshape (implicate) the consequent part of the rule, generating modified fuzzy sets.
Here, all implicated fuzzy sets of the fired rules are combined using fuzzy operators to generate a single fuzzy set for each of the output variables.
Finally, a defuzzification operator is applied to the aggregated fuzzy set to generate a single crisp value for each of the output variables.
For a more detailed explanation of fuzzy inference, you can check out the tutorial by Jerry Mendel at http://sipi.usc.edu/~mendel/publications/FLS_Engr_Tutorial_Errata.pdf.
Note: The terminology used in this module might differ from that used in the above tutorial.
The module has the following public methods:
new()operation()& for logical AND,
| for logical OR, or ! for logical NOT. The second
argument is used to set what method to use for the given operator.
The following values are possible:
A and B is min(A, B). This is the default.
A and B is A * B.
A or B is max(A, B). This is the default.
A or B is min(A + B, 1).
not A is 1 - A. This is the default.
The method returns the name of the method to be used for the given operation.
implication()aggregation()defuzzification()inVar()
$obj->inVar('height',
5, 8, # xmin, xmax (in feet, say)
'tall' => [5, 0,
5.5, 1,
6, 0],
'medium' => [5.5, 0,
6.5, 1,
7, 0],
'short' => [6.5, 0,
7, 1]
);
This example defines an input variable called height. The minimum possible value for height is 5, and the maximum is 8. It also defines 3 term sets associated with height: tall, medium and short. The shape of each of these triangular term sets is completely specified by the supplied anonymous array of indices.
outVar()inVar() method.
addRule()& or | indicating the fuzzy
AND and OR operations respectively. Each consequent must be a
single string. Each string has the form: var = term_set. Spaces
are completely optional. Example:
$obj->addRule('height=short & weight=big' => 'diet = necessary',
'height=tall & weight=tiny' => 'diet = are_you_kidding_me');
The first rule basically says If the height is short, and the weight is big, then diet is necessary.
compute()value() method below.
Example:
$obj->compute(x => 5,
y => 24);
Note that any subsequent call to compute() will implicitly clear out
the old computed values before recomputing the new ones. This is done
through a call to the reset() method below.
value()outVar() method),
and only returns useful results after a call to compute() has been
made.
reset()compute()
method above.
It's all in pure Perl. Just place it somewhere and point your @INC to it.
But, if you insist, here's the traditional way:
To install this module type the following:
perl Makefile.PL make make test make install
Copyright 2002, Ala Qumsieh. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Address bug reports and comments to: ala_qumsieh@yahoo.com.
|
AI::FuzzyInference - A module to implement a Fuzzy Inference System. |