home Forums # Technical Support What FCL version does Fuzzylite use?

This topic contains 7 replies, has 3 voices, and was last updated by Juan Rada-Vilela Juan Rada-Vilela 1 year, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1015

    asho
    Participant

    I am trying to load FCL files created by fuzzyLite utility in jFuzzyLogic but it generates several syntax errors while both jFuzzyLogic (IEC 61131 part 7) and fuzzyLite are using FCL. Which version of FCL do you use and which other fuzzy library is compatible with it?

    And please let me know if any fuzzyLite.dll usable in .Net is exist somewhere

    Best Regards

    #1016
    Juan Rada-Vilela
    Juan Rada-Vilela
    Keymaster

    Hi asho,

    Could you post the example you want to import into fuzzylite?

    FCL is defined only to use discrete terms, and anything additional to that is not an official extension to the FCL. fuzzylite covers the standard FCL, but also extends it with its set of terms and other properties such as locks (refer to the ). I think jFuzzyLogic covers the standard too, like fuzzylite, but also extends it in its own particular way. For example, in fuzzylite a Triangle term is expressed as Triangle (0.0, 1.0, 2.0) (parenthesis and commas are optional), whereas in jFuzzyLogic I think it is expressed as trian (0.0, 1.0, 2.0). The definition of a triangle in FCL is expressed as a set of discrete points as (0.0, 0.0) (1.0, 1.0) (2.0, 0.0), which you can do in fuzzylite using the Discrete term. Thus, fuzzylite and jFuzzyLogic extend the basic FCL in different ways that the official FCL did not cover, which renders the extensions of FCL incompatible between both libraries, but the basic FCL should be compatible.

    In fuzzylite, the only difference from the standard FCL is that the accumulation method is defined within the Defuzzify block, whereas the standard FCL defines it within the RuleBlock. Such a difference is intentional and corresponds to the design of fuzzylite, which I could argue provides a better design. In addition, multiline comments (e.g. /* */) are not supported in fuzzylite.

    As for .Net, I have not replied because I have no information about it. I hope someone else has managed to make it work and be kind enough to share the information.

    #1019

    asho
    Participant

    Hi Juan

    Thank you for your reply. For using Fuzzylite in .Net, I finally managed to convert your Java version to a DLL using IKVMC utility.. I think this can be advised to other .Net developers. It seems working and it was much easier than transforming c++ version. My next question is, if you are consideingr using lookuptable or memoization or similar techniques to increase performance in intensive computation and if any considerations are ther for a parallel processing environment. Here is a sample of jFuzzyLogic FCL files.

    Best Regards

    // Block definition (there may be more than one block per file)
    FUNCTION_BLOCK tipper

    // Define input variables
    VAR_INPUT
    service : REAL;
    food : REAL;
    END_VAR

    // Define output variable
    VAR_OUTPUT
    tip : REAL;
    END_VAR

    // Fuzzify input variable ‘service’
    FUZZIFY service
    TERM poor := (0, 1) (4, 0) ;
    TERM good := (1, 0) (4,1) (6,1) (9,0);
    TERM excellent := (6, 0) (9, 1);
    END_FUZZIFY

    // Fuzzify input variable ‘food’
    FUZZIFY food
    TERM rancid := (0, 1) (1, 1) (3,0) ;
    TERM delicious := (7,0) (9,1);
    END_FUZZIFY

    // Defzzzify output variable ‘tip’
    DEFUZZIFY tip
    TERM cheap := (0,0) (5,1) (10,0);
    TERM average := (10,0) (15,1) (20,0);
    TERM generous := (20,0) (25,1) (30,0);
    // Use ‘Center Of Gravity’ defuzzification method
    METHOD : COG;
    // Default value is 0 (if no rule activates defuzzifier)
    DEFAULT := 0;
    END_DEFUZZIFY

    RULEBLOCK No1
    // Use ‘min’ for ‘and’ (also implicit use ‘max’
    // for ‘or’ to fulfill DeMorgan’s Law)
    AND : MIN;
    // Use ‘min’ activation method
    ACT : MIN;
    // Use ‘max’ accumulation method
    ACCU : MAX;

    RULE 1 : IF service IS poor OR food IS rancid
    THEN tip IS cheap;

    RULE 2 : IF service IS good
    THEN tip IS average;

    RULE 3 : IF service IS excellent AND food IS delicious
    THEN tip is generous;
    END_RULEBLOCK

    END_FUNCTION_BLOCK

    • This reply was modified 3 years ago by  asho.
    #1022
    Juan Rada-Vilela
    Juan Rada-Vilela
    Keymaster

    Hi Asho,

    In order to import your FCL controller to fuzzylite, you need to perform the following changes:

    (1) Change comments indicators // to # (this is a temporary fix until next version).
    (2) ACCU : MAX; goes in Defuzzify tip instead of RULEBLOCK (as mentioned before)
    (3) Each rules needs to be presented in a single line (not across multiple lines)
    (4) In rules, change the case of the keywords if, then, with to lower case.

    These changes will let you import your FCL into fuzzylite. However, please have in mind that you should also specify:

    (1) The range of input and output variables (standard in FCL). By default, fuzzylite will assume (-inf .. inf)
    (2) Explicitly define the Disjunction operator (OR) in Ruleblock. If not defined, fuzzylite will take NULL as operator, and since you use or within the rules, fuzzylite will remind you to select one during its operation.

    The following is the FCL code of your engine exported using fuzzylite. Have in mind that ENABLED is an extension to FCL which gives you the option to disable a variable or rule block (useful for testing purposes).

    FUNCTION_BLOCK tipper
    
    VAR_INPUT
      service: REAL;
      food: REAL;
    END_VAR
    
    VAR_OUTPUT
      tip: REAL;
    END_VAR
    
    FUZZIFY service
      ENABLED : TRUE;
      RANGE := (-inf .. inf);
      TERM poor := (0.000, 1.000) (4.000, 0.000);
      TERM good := (1.000, 0.000) (4.000, 1.000) (6.000, 1.000) (9.000, 0.000);
      TERM excellent := (6.000, 0.000) (9.000, 1.000);
    END_FUZZIFY
    
    FUZZIFY food
      ENABLED : TRUE;
      RANGE := (-inf .. inf);
      TERM rancid := (0.000, 1.000) (1.000, 1.000) (3.000, 0.000);
      TERM delicious := (7.000, 0.000) (9.000, 1.000);
    END_FUZZIFY
    
    DEFUZZIFY tip
      ENABLED : TRUE;
      RANGE := (-inf .. inf);
      TERM cheap := (0.000, 0.000) (5.000, 1.000) (10.000, 0.000);
      TERM average := (10.000, 0.000) (15.000, 1.000) (20.000, 0.000);
      TERM generous := (20.000, 0.000) (25.000, 1.000) (30.000, 0.000);
      METHOD : COG;
      ACCU : MAX;
      DEFAULT := 0.000;
    END_DEFUZZIFY
    
    RULEBLOCK  No1
      ENABLED : TRUE;
      AND : MIN;
      ACT : MIN;
      RULE 1 : if service is poor or food is rancid then tip is cheap
      RULE 2 : if service is good then tip is average
      RULE 3 : if service is excellent and food is delicious then tip is generous
    END_RULEBLOCK
    
    END_FUNCTION_BLOCK

    Although I do prefer the FuzzyLite Language (FLL):

    Engine: tipper
    InputVariable: service
      enabled: true
      range: -inf inf
      term: poor Discrete 0.000 1.000 4.000 0.000
      term: good Discrete 1.000 0.000 4.000 1.000 6.000 1.000 9.000 0.000
      term: excellent Discrete 6.000 0.000 9.000 1.000
    InputVariable: food
      enabled: true
      range: -inf inf
      term: rancid Discrete 0.000 1.000 1.000 1.000 3.000 0.000
      term: delicious Discrete 7.000 0.000 9.000 1.000
    OutputVariable: tip
      enabled: true
      range: -inf inf
      accumulation: Maximum
      defuzzifier: Centroid 200
      default: 0.000
      lock-valid: false
      lock-range: false
      term: cheap Discrete 0.000 0.000 5.000 1.000 10.000 0.000
      term: average Discrete 10.000 0.000 15.000 1.000 20.000 0.000
      term: generous Discrete 20.000 0.000 25.000 1.000 30.000 0.000
    RuleBlock:  No1
      enabled: true
      conjunction: Minimum
      disjunction: none
      activation: Minimum
      rule: if service is poor or food is rancid then tip is cheap
      rule: if service is good then tip is average
      rule: if service is excellent and food is delicious then tip is generous
    #1023
    Juan Rada-Vilela
    Juan Rada-Vilela
    Keymaster

    Oh, as for performance optimization, the only place (I can think of right now) that is worth parallelizing is the Integral defuzzifiers (e.g. Centroid, Bisector, etc). While it should be straightforward to do that, it involves using external libraries (e.g. Intel’s Building Blocks) that I have no plans to make fuzzylite dependant upon. Nonetheless, I will eventually make the defuzzifiers work in parallel if the library is available via MACRO definitions.

    #1024

    asho
    Participant

    Thank you.

    #1936

    lalitpendhare
    Participant

    VAR_INPUT // Define input variables
    sent_len : REAL;
    term_fq : REAL;
    them_wd :REAL;
    END_VAR
    VAR_OUTPUT // Define output variable
    important : REAL;
    END_VAR
    FUZZIFY sent_len
    TERM short := (0, 0) (0,1) (0.5, 0);
    TERM normal := (0.14,0) (0.5, 1) (0.83, 0);
    TERM long := (0.5, 0) (1,1) (1, 0);
    END_FUZZIFY
    FUZZIFY term_fq
    TERM low := (0, 0) (0,1) (0.5, 0);
    TERM high := (0.14,0) (0.5, 1) (0.83, 0);
    TERM Vhigh := (0.5, 0) (1,1) (1, 0);
    END_FUZZIFY
    FUZZIFY them_wd // Fuzzify input variable ‘them_wd': { ‘lessimp’, ‘moreimp’ }
    TERM lessimp := 1.0;
    TERM moreimp := 4.0;
    END_FUZZIFY

    DEFUZZIFY important
    TERM cheap :=trian 0.75 1 1;
    TERM average :=trian -1 -0.75 -0.5;
    TERM generous :=trian 2 2.5 3;
    METHOD : COG; // Use ‘Center Of Gravity’ defuzzification method
    DEFAULT := 0; // Default value is 0 (if no rule activates defuzzifier)
    END_DEFUZZIFY
    RULEBLOCK No1
    AND : MIN; // Use ‘min’ for ‘and’ (also implicit use ‘max’ for ‘or’ to fulfillDeMorgan’s Law)
    ACT : MIN; // Use ‘min’ activation method
    ACCU : MAX; // Use ‘max’ accumulation method
    Rule 1: IF sent_len IS normal AND term_fq IS low AND them_wd IS lessimp THEN important IS cheap;
    Rule 2: IF sent_len IS long AND term_fq IS high AND them_wd IS lessimp THEN important IS average;
    Rule 3: IF sent_len IS short AND term_fq IS Vhigh AND them_wd IS moreimp THEN important IS generous;
    Rule 4: IF sent_len IS short OR term_fq IS low OR them_wd IS lessimp THEN important IS cheap;
    END_RULEBLOCK
    END_FUNCTION_BLOCK

    Please someone explain this file, I have seminar for summarization of text that used this file but I don’t know how it is implemented.

    Experts please explain this file.

    #1946
    Juan Rada-Vilela
    Juan Rada-Vilela
    Keymaster

    Hi,

    FuzzyLite uses the FCL standard, but rule keywords are written in lowercase (if is and or then). In addition, trian is not part of the FCL standard, but rather the approach of jFuzzyLogic (I think). In FuzzyLite, please use Triangle.

    Cheers.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.