GRASS logo

NAME

r.fuzzy.system - Full fuzzy logic standalone classification system with few fuzzy logic families implication and defuzzification and methods.

KEYWORDS

raster, fuzzy logic

SYNOPSIS

r.fuzzy.system
r.fuzzy.system help
r.fuzzy.system [-om] maps=name [rules=name] family=string defuz=string imp=string res=integer [coors=x,y] [output=name] [--overwrite] [--verbose] [--quiet]

Flags:

-o
Print only membership values and exit
-m
Create addational fuzzy output maps for every rule
--overwrite
Allow output files to overwrite existing files
--verbose
Verbose module output
--quiet
Quiet module output

Parameters:

maps=name
Name of fuzzy variable file
rules=name
Name of rules file
family=string
Fuzzy logic family
Options: Zadeh,product,drastic,Lukasiewicz,Fodor,Hamacher
Default: Zadeh
defuz=string
Defuzzyfication method
Options: centroid,bisector,min_of_highest,max_of_highest,mean_of_highest
Default: bisector
imp=string
Implication method
Options: minimum,product
Default: minimum
res=integer
Universe resolution
Default: 100
coors=x,y
Coordinate of cell for detail data (print end exit)
output=name
Name of output file

OPTIONS

maps
A text file containing maps name and fuzzy sets connected with map definition. The input maps (indicated with % in text file) must be found in the search path. The output map name is the output name parameter. In map file output map is marked by special name _OUTPUT_ If maps are in different mapsets the name require @. Map names in database cannot contain following symbols: %,$ and #. Every map name must start with map name identifier: %. Every set definition connected with cetrain map must follow the map name and must start with set identifier : $. The set definition must be in braces { } and requires parameters separated by semicolon. Any whitespaces like spaces, tabs, empty lines are allowed and may used to visual format of rule file.
$ set_name {side; points; boundary_shape; hedge; height }

An example of fuzzy sets definiton:

$ moderate {both; 90,100,120,130; sshaped; 0; 1}
Special notes about sets definition for output map:
These sets shall be created as triangular (both sides) sets with linear boundaries, without hedge and height modifiers:
$ moderate {both; 0,20,20,40; linear; 0; 1}
rules
A text file containing rules for classification.Th typical fuzzy rule consists of one or more antecedents and one consequent:
IF elev IS high AND distance IS low THEN probability IS small

where:
antecetends: elev IS high; distance IS low
consequent: probability IS small
The rule file has his own syntax. Because module creates only one result map, the map name is ommited. Every rule starts with $ and consist of consequent name and antecedents in braces { }. All maps and sets used in atecednets must be included in the maps file. At the begining of the calculation program checks if all names and sets are included in maps file. Names of the rules must be same as sets names of the output map. The rules file use following symbols:

An example of fuzzy rules definiton:

$ small {distance = high & elev = high}

ADVANCED OPTIONS

In most cases default options shoud not be changed.
family
AND and OR operations in fuzzy logic are made with T-norms, T-conorms. T-norms, T-conorms are a generalization of the two-valued logical conjunction and disjunction used by boolean logic, for fuzzy logics. Because there is more than one possible generalisation of logial operations, r.fuzzy.system provides 6 most popular families for fuzzy operations:

Family T-NORM (AND) T CONORM (OR)
ZADEH MIN(x,y)MAX(x,y)
PRODUCT x*y x + y -x * y
DRASTIC IF MAX(x, y) == 1 THEN MIN(x, y) ELSE 0 IF (MIN(x, y) == 0) THEN MAX(x, y) ELSE 1
LUKASIEWICZ MAX((x+y-1),0) MIN((x+y),1)
FODOR IF (x+y)>1 THEN MIN(x,y) ELSE 0 IF (x+y<1) THEN MAX(x,y) ELSE 1
HAMACHER IF (x==y==0) THEN 0 ELSE (x*y)/((x+y)-x*y) (x+y)/(1+x*y)

imp: implication
Imlication determines the method of reshapening of consequents (fuzzy set) by antecedents (single value) :
defuzz: defuzzification method
Before defuzzification all consequents are agregated into one fuzzy set. Defuzzification is the process of conversion of aggregated fuzzy set into one crisp value. The r.fuzzy.system provides 5 methods of defuzzification:
res: universe resolution
The universe is an interval between the lowest and highest values of consequent and agregated fuzzy sets. The resolution provides number of elements of these fuzzy sets. The minimum and maximum for univese is taken from the minimal and maximal values of fuzzy set definition of output map Because it has strong impact on computation time and precision of defuzzification, values lower than 30 may impact on precision of final result, but values above 200 may slow down computation time.

VISUAL OUTPUT

coordinates
Coordinates of points for which output: universe, all consequents sets and agregate set. It is useful for visual presentation or detail analysis of fuzzy rules behaviour. In that cases calculations are peroforemd n=only for selected point.
membership only flag
Prints for all maps sat of values in map range (map universe) and values of fuzzy sets (linguistic values). Number of values is taken from resolution (default 100). This option is useful for visual control fuzzy set definitions for every map.

OUTPUTS

output
Map containing defuzzified values. Map is always of type FCELLS and contains values defined in output universe.
multipe output flag
This flag is used to create fuzzified maps for every rule. The name of the map consist of otput map name, '_' and rule name (for example: output=probs and rule name high, the map name: probs_high). Values of maps ranges from 0 to 1. If map with such name exists will be overwritten without warning.

NOTES

Calculation of boundary shape

Depending on type of the boundary different equation are used to determine its shape:

Linear: the membership is calculated according following equation:

value  <=  A -> x = 0
A< value > B -> x = (value-A)/(B-A)
B <= value >= C -> x = 1
C< value > D -> x = (D-value)/(D-C)
value  >=  D -> x = 0
S-shaped, G-shaped and J shaped: use following equation to sommoth boundary:
sin(x * Pi/2)^2 (for S-shaped)
tan(x * Pi/4)^2 (for J-shaped)
tan(x * Pi/4)^0.5 (for G-shaped)

where:
x current fuzzy value
A,B,C,D inflection point

Category information

Every cell has a category information showing the membership of result map in any reslut's fuzzy values: for example moderate=0.60, high=0.40 means that cell belongs to moderate class with 0.60 membership and high class with membership = 0.40. The membership is calculated based on _OUTPUT_ definition.

EXAMPLE

Fuzzy sets are sets whose elements have degrees of membership. Zadeh (1965) introduced Fuzzy sets as an extension of the classical notion of set. Classical membership of elements in a set are binary terms: an element either belongs or does not belong to the set. Fuzzy set theory use the gradual membership of elements in a set. A membership function use values in the real unit interval [0, 1]. Classical sets, are special cases of the membership functions of fuzzy sets and only take values 0 or 1. Classical sets are in fuzzy set theory usually called crisp sets. The fuzzy set theory can be used in a wide range of domains in which information is imprecise, such as most of the GIS operations.

Suppose we want to determine the flood risk on some area (Spearfish dataset) using two maps: distance to streams and elevation above streams. We can write some common sense rules:

IF elevation IS low AND distance IS near THEN risk IS very probable
IF elevation IS low OR distance IS near THEN risk IS probable
IF elevation IS high AND distance IS far THEN risk IS unprobable
In clasical boolean sense, we would taken some limits of ideas "near" "far" etc, but what about walues near the limit? The fuzzy set uses partial memberships which abolish these restrictions. In that sense to set "near" belongs all areas with distance no more than 100 m with full membership and from 100 to 200 m with partial membership greater than 0. Over 200 m we can assume that is not near. This allow to formulate fuzzy rules for distance map:
near: BELOW 100 = 1; FROM 100 TO 200 = {1 TO 0}; ABOVE 200 = 0;
To recive final map program calculate partial fuzzy set for all rules and next agregate it into one fuzzy set. These fuzzy sets are created on value sequence called universe. Every set has the number of elements equal to universe resolution. Such set cannot be stored as map so finally is defuzzified with method choosen by user.

First we need two maps created with r.stream package:

r.watershed -f elevation=elevation.10m accumulation=accum
r.mapcalc "accum_abs = abs(accum)"
r.stream.extract elevation=elevation.10m threshold=1000 \
         stream_rast=streams direction=dirs
r.stream.order stream=streams dir=dirs horton=horton
r.mapcalc "horton3 = if(horton>2,1,0)"
r.stream.distance stream=horton3 dir=dirs dem=elevation.10m \
         distance=distance elevation=elevation
Next, to perform analysis we need two files: one with definition of map used in analysis and definition of fuzzy sets for every map, and second with fuzzy rules. For this example:

MAPS Note: the raster map names are specified with a "%" character (here "%elevation" and "%distance" are the input maps and "%flood" the output map:

#flood.map
	%elevation
$ low {right; 2,4; sshaped; 0; 1}
$ moderate {both; 2,4,5,10; sshaped; 0; 1}
$ high {left; 5,10; sshaped; 0; 1}

	%distance
$ near {right; 30,70; sshaped; 0; 1}
$ medium {both; 30,70,100,150; sshaped; 0; 1}
$ far {both; 100,150,200,300; sshaped; 0; 1}
$ veryfar {left; 200,300; sshaped; 0; 1}

	%accum_abs
$ low {right; 500,5000; sshaped; 0; 1}
$ $ high {left; 500,5000; sshaped; 0; 1}

#output map

	%_OUTPUT_
$ none {both; 0,20,20,40; linear; 0;1}
$ low {both; 20,40,40,60; linear; 0;1}
$ moderate {both; 40,60,60,80; linear; 0;1}
$ high {both; 60,80,80,100; linear; 0;1}
$ veryhigh {both; 80,100,100,120; linear; 0;1}

RULES:

#flood.rul
$ none {distance = veryfar | elevation = high}
$ low {distance ~ near & accum_abs = high}
$ moderate {(distance = medium | distance = far) & (elevation = low | elevation
= moderate)}
$ high {(distance = medium & elevation = low)|(distance = near & elevation =
moderate)}
$ veryhigh {distance = near & elevation = low}
finally we need run r.fuzzy.system:
A) r.fuzzy.system maps=flood.map rules=flood.rul family=Zadeh defuz=centroid
imp=minimum res=100 output=flood_z_cent
B) r.fuzzy.system maps=flood.map rules=flood.rul family=drastic
defuz=max_of_highest imp=minimum res=100 output=flood_d_max
C) r.fuzzy.system maps=flood.map rules=flood.rul family=Hamacher
defuz=mean_of_highest imp=minimum res=100 output=flood_h_mean
Resulting map should look like this below.

SEE ALSO

r.fuzzy, r.fuzzy.logic, r.fuzzy.set, r.mapcalc

REFERENCES

Zadeh, L.A. (1965). "Fuzzy sets". Information and Control 8 (3): 338–353. doi:10.1016/S0019-9958(65)90241-X. ISSN 0019-9958.

Novák, Vilém (1989). Fuzzy Sets and Their Applications. Bristol: Adam Hilger. ISBN 0-85274-583-4.

Klir, George J.; Yuan, Bo (1995). Fuzzy sets and fuzzy logic: theory and applications. Upper Saddle River, NJ: Prentice Hall PTR. ISBN 0-13-101171-5.

Klir, George J.; St Clair, Ute H.; Yuan, Bo (1997). Fuzzy set theory: foundations and applications. Englewood Cliffs, NJ: Prentice Hall. ISBN 0133410587.

Meyer D, Hornik K (2009a). \Generalized and Customizable Sets in R." Journal of Statistical Software, 31(2), 1{27. URL http://www.jstatsoft.org/v31/i02/.

Meyer D, Hornik K (2009b). sets: Sets, Generalized Sets, and Customizable Sets. R~package version~1.0, URL http://CRAN.R-project.org/package=sets.

AUTHOR

Jarek Jasiewicz

Last changed: $Date$


Main index - raster index - Full index

© 2003-2016 GRASS Development Team