Introduction to Fuzzy Sets on a Real Domain
The
RealDomain
subpackage allows the user to construct and work with fuzzy subsets of the real line.
The membership function of a fuzzy subset of the real line is represented by a piecewise function with a range of [0, 1].
The
RealDomain
subpackage includes a number of constructors of fuzzy subsets of
R
which simplify the construction of fuzzy sets and set operators and routines for working with fuzzy subsets of
R
.
In general, this package tries as much as possible to treat fuzzy sets
like sets. You may take the union of two fuzzy sets like you
would take the union of two normal sets in Maple. Membership is
determined by using the
in
operator.
> 
with( FuzzySets[RealDomain] );

Warning, these protected names have been redefined and unprotected: implies, intersect, minus, plot, subset, union
Constructors
Fuzzy sets are
constructed using one of six constructor routines. The arguments
return an inert FuzzySet datastructure which may then be used in
further fuzzy set operations or functions.
Note that even though a fuzzy set is displayed like a piecewise
function, it does not intended to behave like one. It is a set,
and should be treated as such.
The fuzzy set cannot be
evaluated
at a point, as this makes no sense. Instead, you must use the
in
operator or
function to convert the fuzzy set to its associated membership function (which could be a piecewise function.)
fuzzyset type
Each of the constructors returns an object which is of type
fuzzyset
. Fuzzy values area also of type
fuzzyset
.
FuzzySet Constructor
The fuzzy set constructor
FuzzySet
is similar to the
piecewise
function, although there are some limitations.
> 
Fz := FuzzySet( x < 3, 0, x = 4, 1, x = 5, 1/2, x = 6, 1, x = 7, 0, 0 );

> 
Gz := FuzzySet( x < 3, 0, x < 4, 1/2, x = 6, 1, 1 );

> 
plot( Gz, 2..7, axes = none );

Other Constructors and Models
The constructors Gamma (
), L (
), Lambda (
), and PI (
) are named to suggest the shape of the resulting membership function.
For example, Gamma produces fuzzy sets whose functions monotonically
increasing from 0 to 1, while L produces fuzzy sets whose membership
function decreases from 1 to 0.
In words, these subsets of
R
would be described as:
1. Real numbers approximately less than a given value (
),
2. Real numbers approximately greater than a given value (
),
3. Real numbers approximately equal to a given value (
).
4. Real numbers on or close to an interval (
).
The transition from
real numbers having full membership (1) in the associated set and
having no membership (0) depends on the type of membership function
used.
The membership functions provided use standard algebraic expressions to
describe the membership of a real number within the fuzzy set, and the
type of expression (or model) used may be specified.
For example, the linear model uses a piecewise linear function to represent the transition from 0 to 1 (or 1 to 0.)
Linear
The linear model of fuzzy sets defines fuzzy sets through piecewise linear functions.
The linear model is the default for the constructors
,
,
, and
.
> 
plot( [Gamma( 1, 4 ), Lambda( 2, 3, 4 )], 0..5,
thickness=2, color = [red, blue],
legend = ["Significatly greater than 1", "Approximately 3"]
);

Quadratic
The quadratic model
defines the membership function of fuzzy sets using piecewise quadratic
functions with smooth transitions to constant regions.
> 
Gamma( 1, 4, model = 'quadratic' );

> 
plot(
[Gamma( 1, 4, model = quadratic ), Lambda( 2, 3, 4, model = quadratic )], 0..5,
thickness=2, color = [red, blue],
legend = ["Significatly greater than 1", "Approximately 3"]
);

Cubic
> 
plot(
[Gamma( 1, 4, model = cubic ), Lambda( 2, 3, 4, model = cubic )], 0..5,
thickness=2, color = [red, blue],
legend = ["Significatly greater than 1", "Approximately 3"]
);

Rational
> 
Gamma( 4, model = rational );

> 
plot(
[Gamma( 4, model = rational ), Lambda( 3, model = rational )], 0..5,
thickness=2, color = [red, blue],
legend = ["Greater than or approximately 4", "Approximately 3"]
);

A positive parameter
can be used to indicate the amount the rate at which the membership
function drops off. The default parameter value is 1.
> 
plot(
[Gamma( 4, model = rational ), Gamma( 4, model = rational[2] ), Gamma( 4, model = rational[1/2] )], 0..5,
thickness=2, color = [red, blue, black]
);

Exponential
> 
plot(
[Gamma( 4, model = exp ), Lambda( 3, model = exp )], 0..5,
thickness=2, color = [red, blue],
legend = ["Greater than or approximately 4", "Approximately 3"]
);

A positive
parameter can be used to indicate the amount the rate at which the
membership function drops off. The default parameter value is 1.
> 
plot(
[Gamma( 4, model = exp ), Gamma( 4, model = exp[2] ), Gamma( 4, model = exp[1/2] )], 0..5,
thickness=2, color = [red, blue, black]
);

Arctangent
> 
plot( Gamma( 5, model = arctan ), 0..10, 0..1,
thickness=2,
legend = ["Approximately greater than 5"]
);

A positive
parameter can be used to indicate the amount the rate at which the
membership function approaches 0 and 1. The default parameter
value is 1.
> 
plot(
[Gamma( 5, model = arctan ), Gamma( 5, model = arctan[2] ), Gamma( 5, model = arctan[1/2] )], 0..10, 0..1,
thickness=2, color = [red, blue, black]
);

Hyperbolic Tangent
> 
plot( Gamma( 5, model = tanh ), 0..10, 0..1,
thickness=2,
legend = "Approximately greater than 5"
);

A positive
parameter can be used to indicate the amount the rate at which the
membership function approaches 0 and 1. The default parameter
value is 1.
> 
plot(
[Gamma( 5, model = tanh ), Gamma( 5, model = tanh[2] ), Gamma( 5, model = tanh[1/2] )], 0..10, 0..1,
thickness=2, color = [red, blue, black]
);

The constructors Gamma (
), L (
), Lambda (
), and PI (
) are named to suggest the shape of the resulting membership function.
For example, the constructor Gamma produces fuzzy sets the membership
functions of which are monotonically increasing from 0 to 1
The
constructor is used to represent real numbers approximately greater than or equal to a given value.
The linear model takes two arguments a, b and creates a linear function which interpolates the points (a, 0), (b, 1).
The quadratic model (Zadeh's S function) interpolates the points with two quadratics which are smooth at each end point.
The cubic model interpolates the two points which a cubic
the derivative of which is 0 at each end point.
The rational model takes one argument a and creates a rational membership function
which is zero at a and approaches
as
.
It takes a parameter
which is 1 by default.
The exponential model does the same, but uses an exponential function.
It takes a parameter
which is 1 by default.
The arctangent and hyperbolic tangent models take one argument a creates a fuzzy set S such that
.
They both take parameters
.
Parameters are passed by using an index. See the examples below.
> 
plot( [
Gamma( 1, 4 ), Gamma( 1, 4, model=quadratic ), Gamma( 1, 4, model=cubic )
], 0..5, legend=["Linear", "Quadratic", "Cubic"], color=[red, blue, black] );

> 
plot( [
Gamma( 1, model=rational ), Gamma( 1, model=exp ),
Gamma( 1, model=rational[2] ), Gamma( 1, model=exp[2] )
], 2..2, color = [red, blue, black, magenta], legend=[
"Rational", "Exponential",
"Rational with parameter 2", "Exponential with parameter 2"
] );

> 
plot( [
Gamma( 1, model=arctan ), Gamma( 1, model=tanh ),
Gamma( 1, model=arctan[2] ), Gamma( 1, model=tanh[2] )
], 3..5, color = [red, blue, black, magenta], legend=[
"Arctangent", "Hyperbolic Tangent",
"Arctangent with parameter 2", "Hyperbolic Tangent with parameter 2"
] );

L
The
constructor does the same as the Gamma constructor, except it goes down from (a, 1) to (b, 0).
> 
plot( [
L( 1, 4 ), L( 1, 4, model=quadratic ), L( 1, 4, model=cubic )
], 0..5, color = [red, blue, black], legend=["Linear", "Quadratic", "Cubic"] );

> 
plot( [
L( 1, model=rational ), L( 1, model=exp ),
L( 1, model=rational[2] ), L( 1, model=exp[2] )
], 0..5, color = [red, blue, black, magenta], legend=[
"Rational", "Exponential",
"Rational with parameter 2", "Exponential with parameter 2"
] );

> 
plot( [
L( 1, model=arctan ), L( 1, model=tanh ),
L( 1, model=arctan[2] ), L( 1, model=tanh[2] )
], 3..5, color = [red, blue, black, magenta], legend=[
"Arctangent", "Hyperbolic Tangent",
"Arctangent with parameter 2", "Hyperbolic Tangent with parameter 2"
] );

The
function takes models similar to that of the
and
functions except that it is used to model an approximation to a point, so
the definitions must be appropriately adjusted.
The arctangent and hyperbolic tangent models do not apply to the
function.
> 
plot( [
Lambda( 1, 3, 5 ), Lambda( 1, 3, 5, model=quadratic ), Lambda( 1, 3, 5, model=cubic )
], 0..6, color = [red, blue, black], legend=["Linear", "Quadratic", "Cubic"] );

> 
plot( [
Lambda( 3, model=rational ), Lambda( 3, model=exp ),
Lambda( 3, model=rational[2] ), Lambda( 3, model=exp[2] )
], 0..6, color = [red, blue, black, magenta], legend=[
"Rational", "Exponential",
"Rational with parameter 2", "Exponential with parameter 2"
] );

The PI function is similar to the Lambda function except it contains an interval on which fuzzy membership is 1.
> 
plot( [
PI( 1, 3, 5, 7 ), PI( 1, 3, 5, 7, model=quadratic ), PI( 1, 3, 5, 7, model=cubic )
], 0..8, color = [red, blue, black], legend=["Linear", "Quadratic", "Cubic"] );

> 
plot( [
PI( 3, 4, model=rational ), PI( 3, 4, model=exp ),
PI( 3, 4, model=rational[2] ), PI( 3, 4, model=exp[2] )
], 0..7, color = [red, blue, black, magenta], legend=[
"Rational", "Exponential",
"Rational with parameter 2", "Exponential with parameter 2"
] );

Partition
The routine
takes a sequence of points and generates a set of
functions of each triplet of points.
> 
Partition( 3, 4, 6, 8, 9 );

> 
plot( [Partition( 3, 4, 6, 8, 9 )], 1..11, color = [red, blue, black] );

> 
plot( [Partition( 3, 5, 7, 9, 11, model = quadratic )], 1..13, color = [red, blue, black] );

> 
plot( [Partition( 3, 5, 7, 9, 11, model = cubic )], 1..13, color = [red, blue, black] );

> 
plot( [Partition( 3, 5, 7, 9, 11, model = rational[2] )], 1..13, color = [red, blue, black] );

Plotting
The
command is overridden so that if the first
argument is a fuzzy set or a set or list of fuzzy sets that they
display properly.
A second argument indicating a range should not give a variable (as a fuzzy set does not have a variable).
Alternatively, the fuzzy set
can be converted to a regular function in
by using
.
> 
plot( Gamma( 2, 4 ), 1..5 );

> 
plot( [Partition( 3, 2, 0, 1, 3, 6, 7 )], 4..8, filled=true );

> 
S := Lambda( 2, 0, 2 ):

> 
plot( f, x = 4..4, axes = none );

Operators
The operators
union
,
intersect
,
minus
,
implies
,
in
, and
subset
are overridden to work with fuzzy subsets
of the real line. This section shows how these operators work
with the three fuzzy sets
S
,
T
, and
U
.
> 
with( FuzzySets[RealDomain] );

Warning, these protected names have been redefined and unprotected: implies, intersect, minus, plot, subset, union
> 
T := Lambda( 2, 5, 8 ):

> 
plot( [S, T, U], 1..9, color = [red, blue, black], legend = ["S", "T", "U"] );

Union (union)
The union of two fuzzy sets S and T has the membership function
.
By default, this is equal to:
. This is equal to the
join
of the two membership functions.
The default snorm used to calculate the union may be changed using the
Tools[UseTNorm]
function.
> 
plot( [S, T, S union T], 1..9, thickness=[1, 1, 3], color=[red, blue, black] );

Intersection (intersect)
The intersection of two fuzzy sets S and T has the membership function
.
By default, this is equal to:
. This is equal to the
meet
of the two membership functions.
The default tnorm used to calculate the union may be changed using the
Tools[UseTNorm]
function.
> 
plot( [S, T, S intersect T], 1..9, thickness=[1, 1, 3], color=[red, blue, black] );

Implication (implies)
The amount to which
one fuzzy set implies another has numerous member functions.
According to classical logic, the definition may have the
membership function
.
By default, this is equal to:
.
The default implication used to calculate implication may be changed using the
Tools[UseImplication]
function.
> 
plot( [S, T, S implies T], 1..9, thickness=[1, 1, 3], color=[red, blue, black] );

> 
plot( [S, 0.3, S implies 0.3, 0.3 implies S], 1..9, thickness=[1, 1, 3, 3], color=[red, blue, black, cyan] );

Membership (in)
The
in
operator returns the degree of membership
of the left hand side in the given fuzzy set. The following are
equivalent for numeric
:
.
> 
plot( [S, T, U], 3..4, color = [red, blue, black] );

Set Minus (minus)
The minus operator is defined as
.
Alternatively, one may define it as
, but the
Arithmetic
subpackage may be used for this purpose. Otherwise, there would be no access to fuzzy implications through the
FuzzySets[RealDomains]
package.
> 
FuzzySets:Logic:`not`( 0.2 );

> 
plot( [S, T, S minus T], 1..9, color=[red, blue, cyan], thickness = [1, 1, 3] );

Subset (subset)
A fuzzy set S is a subset of a fuzzy set T if
for all real
.
Other Routines
A number of
routines are provided which in some way work with fuzzy sets.
Fuzzy controllers are described in a different section.
> 
with( FuzzySets[RealDomain] );

Warning, these protected names have been redefined and unprotected: implies, intersect, minus, plot, subset, union
> 
T := Lambda( 2, 5, 8 ):

> 
plot( [S, T, U], 1..9, color = [red, blue, black], legend = ["S", "T", "U"] );

Complement
The complement of a fuzzy set has the membership function
.
By default, it is defined by
.
The default complement used may be changed using the routine
UseComplement
.
> 
plot( [T, Complement( T )], 1..9, color=[red, black] );

Converting Fuzzy Sets to Piecewise Functions (
)
The
operator can be thought of as the equivalent of
.
The notation
is used throughout the literature of fuzzy sets.
Defuzzify
It is often useful to convert a fuzzy set to a single real value. This process is called
defuzzification
. The two techniques for defuzzification are listed on the
Defuzzify
help page.
> 
Defuzzify( Lambda( 0, 3, 9 ) );

> 
Defuzzify( S ); # Error

Error, (in FuzzySets:RealDomain:Defuzzify) cannot defuzzify an unbounded fuzzy set on an infinite interval
Cut
The fuzzy weak
level cut
of a fuzzy set
is defined as the fuzzy set whose membership function is:
This is the default result given by the function
Cut
.
The crisp weak
level cut
for a fuzzy set
is defined as the fuzzy set whose membership function is:
This result may be achieved through the use of the option
crisp = true
.
The strong alphalevel cut
of a fuzzy set A is defined as the fuzzy set whose membership function is:
This result may be achieved through the use of the option
strong = true
.
Both options may be used together to get a crisp set which is
whenever
.
> 
Cut( S, 0.3 ); # fuzzy and weak

> 
Cut( S, 0.3, crisp ); # crisp and weak

> 
Cut( S, 0.3, strong ); # fuzzy and strong

> 
Cut( S, 0.3, crisp, strong ); #crisp and strong

> 
plot( [S, Cut( S, 0.3 ), Cut( S, 0.3, crisp )], 2..5, color=[red, blue, black], thickness = [1, 3, 4] );

Core
The core of a fuzzy set S is the set of all points for which
.
It may be thought of as the crisp weak 1level cut of a fuzzy set.
Support
The support of a fuzzy set S is the set of all points for which
.
It may be thought of as the crisp strong 0level cut of a fuzzy set.
Height
The height of a fuzzy set is the supremum of the membership function
.
> 
Height( S intersect T );

Normalize
A fuzzy set is called
normal
if it is either the empty set (0) or there exists an element
such that
, that is,
.
The normalize routine divides the membership function of a nonzero fuzzy set by its height to produce a normal fuzzy set.
> 
Normalize( S intersect T );

> 
plot(
[S intersect T, Normalize( S intersect T )],
1..5, color=[red, blue], legend = ["U = S intersect T", "Normalize( U )"]
);

Concentrate
The routine
Concentrate
may be used to convert a fuzzy set from describing, for example, people who are
tall
to a set describing people who are
very tall
.
> 
C1 := Lambda( 3, 4, 5 );

> 
C2 := Concentrate( C1 );

> 
C3 := Concentrate( C1, 3 );

> 
plot( [C1, C2, C3], 2..6, color = [red, blue, black] );

Dilate
The routine
Dilate
may be used to convert a fuzzy set from describing, for example, people who are
tall
to a set describing people who are
sortof tall
.
> 
D1 := Lambda( 3, 4, 5 );

> 
plot( [D1, D2, D3], 2..6, color = [red, blue, black] );

Intensify
If a fuzzy set represents, for example, people who are
tall
, then the fuzzy set of people who are
positively tall
represents an increase in the contrast between those with large and small memberships.
> 
IC1 := Lambda( 3, 4, 5, model=quadratic );

> 
IC2 := Intensify( IC1 );

> 
plot([IC1, IC2], 2..6, color = [red, blue] );
