Fuzzy_C
Transcript of Fuzzy_C
-
8/9/2019 Fuzzy_C
1/6
-
8/9/2019 Fuzzy_C
2/6
Conventional Membership Functions
FCL Fuzz-C
FUNCTION_BLOCK function_block_name (C module)
VAR_INPUT
variable_name: data_type;
END_VAR
FUZZIFY variable_name
TERM term_name:= (pair), (pair)
END_FUZZIFY
LINGUISTIC variable_nameTYPE data_type
{
MEMBER member_name{point,point,point};
}
VAR_OUTPUT Output
variable_name: data_type;
END_VAR
DEFUZZIFY variable_name
TERM term_name:= crisp;
METHOD method;
END_DEFUZZIFY
CONSEQUENCE variable_nameTYPE data_type
DEFUZZ method
{
MEMBER member_name{ singleton_point};
}
RULEBLOCK block_name
(operator definition; see below)
(activation method; see below)
(accumulation method; see below)
RULE number: IF conditionTHEN
conclusion
[WITH weight];
END_RULEBLOCK
FUZZY block_name
{
IF conditionTHEN conclusion;
}
VAR
variable_name: data_type;
END_VAR
(typical C variable declarations)
data_typeidentifier;
END_FUNCTION_BLOCK (C module)
The following sections give details about the differences between FCL and Fuzz-C
notation.
Conventional Membership Functions
In 61131-7, variable TERMs are described with a list of Cartesian points, pairing a crispinput figure with a degree of membership value between 0 and 1.
TERM hot := (20, 0), (30, 1), (40, 0);
Fuzz-C employs a convention to abbreviate the description of membership functions.This simplifies the definition of membership functions and makes understanding them
much easier. Fuzz-C MEMBER declarations require only a series of crisp values. The
appropriate degree-of-membership values are imputed:
Moving from FCL to Fuzz-C2
-
8/9/2019 Fuzzy_C
3/6
Fuzzy Operators: Aggregation
Values Envelope Example Diagram
1 Threshold MEMBER { 30 }"Threshold
member"
0x20 - - - 0x30 - - - 0x40
Fuzzy 1
Fuzzy 0
2 Range MEMBER { 25, 35 }
"Rangemember"
0x20 - - - 0x30 - - - 0x40
Fuzzy 1
Fuzzy 0
3 Triangle MEMBER { 20, 30, 40 }
"Trianglemember"
0x20 - - - 0x30 - - - 0x40
Fuzzy 1
Fuzzy 0
4 Trapezoid MEMBER { 20, 25, 30, 40 }
"Trapezoidmember"
0x20 - - - 0x30 - - - 0x40
Fuzzy 1
Fuzzy 0
2+ Table
MEMBER { (10,0),(20, 0.25),(30, 0.77),(40, 0), }
0x20 - - - 0x30 - - - 0x40
"Tablemember"
Fuzzy 1
Fuzzy 0
Table 1: Conventional membership function notation
A singleton envelope can be specified using a range envelope, with the two crisp values
set to be the same. Most fuzzy sets are triangular or trapezoidal, having three or fourimportant points, so this notation reduces code size.
Fuzzy sets more complex than these can be specified using a pair notation very similar to
FCL.
Fuzzy Operators: AggregationFCL specifies three ways to define the fuzzy ANDand ORoperators:
Description Key. AND Key. OR
Zadeh Operators MIN min(x, y) MAX max(x, y)
Probabilistic Product/Sum PROD x y ASUM x + y x y
BoundedIntersection/Union
BDIF max(0, x + y - 1) BSUM min(1, x + y)
These are used in theAggregationphase of fuzzy inference.
Byte Craft Limited 3
-
8/9/2019 Fuzzy_C
4/6
Fuzzy Rules: Activation and Accumulation
In Fuzz-C, fuzzy ANDand ORare defined as macros in a standard header file (fuzz-c.h):
By default, the Zadeh operators are compiled in. We have found theoverwhelming majority of fuzzy logic programs use the Zadeh operators.
The Bounded Intersection/Union routines and Probabilistic Product and Sum
methods can be implemented using C macros. Instead of using constants 0 and 1,the macros F_ZEROand F_ONEcan be used; these correspond with the underlying
degree of membership dynamic range.
Fuzzy Rules: Activation and AccumulationIn Fuzz-C, rules are not labeled with rule numbers. All rules are evaluated at once, andthere is no facility to change program flow or make other reference to individual rules.
TheActivationandAccumulationmethods for fuzzy inference are explicitly declared in
the RULEBLOCKin FCL. In contrast, Fuzz-C uses calculations for similar purposes from the
defuzzification templates. This is an example of the accumulation portion of a DEFUZZ
template, named fm to cause it to be expanded once per CONSEQUENCEmember invoked.
fm // Code to be executed each time a consequence function is called
/* fm section */
fc_@CONSNAME += @CONSVOL;
fa_@CONSNAME += (@CONSVOL * (@CONSPOINT));
;;
Weighting (the FCL WITHclause) is accomplished differently as well. Where in FCLexplicit weights are assigned to the action of different rules and activate them, in
Fuzz-C weighting can be accomplished more naturally through the crisp values given in
CONSEQUENCEmembers. Adding a rule multiple times to give it extra weight is a quick but
unattractive alternative and suggests a design problem.
Even when there are only two possible outcomes, it is useful to declare many differentconsequence members. Doing so allows the fuzzy rules to be more intuitive and makesthe effect of combining several rules more pronounced. Weighting the output
CONSEQUENCEmembers in effect weights the rules, but within the concepts expressedthrough linguistic variables (and not as arbitrary values).
In the following PID controller process, the manipulated variable (the output) is likely a
single port bit, to be taken from the MSB of ManVar. With the CONSEQUENCErange centeredon 0, this is a direct copying operation, but in the fuzzy system the rules are weighted by
large and small positive and negative values. With a large result, it is far more likely that
the bit will be switched; this is useful behaviour for large errors.
CONSEQUENCE ManVar TYPE int MIN -20 MAX 20 DEFUZZ cg{
MEMBER LNegative { -18 }
MEMBER SNegative { -6 }
MEMBER SPositive { 6 }
MEMBER LPositive { 18 }
}
FUZZY pid
{
Moving from FCL to Fuzz-C4
-
8/9/2019 Fuzzy_C
5/6
Defuzzification Methods
/* large moves for large proportional errors */
IF Error IS LNegative THEN ManVar IS LPositive
IF Error IS LPositive THEN ManVar IS LNegative
/* small moves for changes in error */
IF Error IS normal AND DeltaError IS Positive
THEN ManVar IS SNegative
IF Error IS normal AND DeltaError IS NegativeTHEN ManVar IS SPositive
/* small moves for large sums of accumulated error */
IF Error IS close AND SumError IS LPos
THEN ManVar IS SNegative
IF Error IS close AND SumError IS LNeg
THEN ManVar IS SPositive
}
Defuzzification MethodsDefuzzification methods are pre-defined in the FCL standard. In contrast, Fuzz-C uses a
user-defined defuzzification template that allows any type of defuzzification. Several pre-written templates ship with Fuzz-C.
Defuzzification Technique FCL METHOD Keyword Fuzz-C DEFUZZ name
Centre of Gravity COG CG
Centre of Gravity for
Singletons
COGS CG
Centre of Area COA
Maximum MAX
Maximum Average MAXAVE
Left Most Maximum LM MAXLEFT
Right Most Maximum RM MAXRIGHT
Middle of the Maximum MIDMAX
Fuzz-C performs an intermediate centre of gravity calculation on CONSEQUENCE(output)members having more than two crisp points. This simplifies consequence calculations on
resource-limited hardware and does not materially affect the outcome.
A default crisp output value can be declared with the DEFAULTstatement. In Fuzz-C, a
similar DEFAULTsetting can define a default output (crisp) value or invoke error handlingroutines or other side-effects.
Additional FeaturesFuzz-C includes some features not reflected in FCL:
Byte Craft Limited 5
-
8/9/2019 Fuzzy_C
6/6
Summary
Moving from FCL to Fuzz-C6
Hedge functions. Functions like NEARLYor ROUGHLYcan add extra detail to a fuzzycondition, effectively adding an additional transformation to the membershipfunction.
Membership functions based on fuzzy conditions. This is useful when onemember describes a useful fuzzy set and other members can be derived from that
set.Fuzz-C can accept membership functions such as the following:
LINGUISTIC hours TYPE char MIN 0 MAX 240
{
MEMBER day { 55 , 65 , 175 , 185 }
MEMBER night {FUZZY { hours IS NOT day }}
MEMBER morning {50, 60 , 80 , 90 }
MEMBER evening { 160 ,170 ,190 , 200 }
MEMBER nightsetback {
FUZZY { hours IS night AND hours IS NOT evening }}
}
Ad-hoc fuzzy comparisons. These are essentially anonymous membership
functions:IF F_EQ(variable, crisp, delta) THEN
The function compares the variableto a triangular membership function, centeredat crispand declining to deltaon both sides. The function returns full equality
(DOM of F_ONE) when temperature and crisp are identical, and declining DOM
until variableexceeds delta.
SummaryTranslating FCL fuzzy logic code to Fuzz-C source is straightforward; there is an almostone-to-one correspondence between the two for the most commonly used fuzzy logic
constructions.
ReferencesIEC: International Electrotechnical Commission, http://www.iec.ch/index.html.
IEC 61131-7: International Electrotechnical Commission (IEC). Technical committee no.
65: Industrial process measurement and control. Sub-committee 65b: Devices. IEC 61131
Programmable ControllersPart 7: Fuzzy control programming.
Fuzz-C: Byte Craft Limited, http://www.bytecraft.com/Fuzz-C.
Byte Craft Limited
A2-490 Dutton DriveWaterloo, Ontario, Canada
N2L 6H7
www.bytecraft.com
http://www.iec.ch/index.htmlhttp://www.bytecraft.com/Fuzz-Cmailto:[email protected]:[email protected]://www.bytecraft.com/Fuzz-Chttp://www.iec.ch/index.html