Introduction to Fuzzy Jess Toolkit

Fuzzy Variable, Fuzzy Set and Fuzzy Value

Fuzzy concepts are represented using fuzzy variables, fuzzy sets and fuzzy values in the Fuzzy Java toolkit.
    ;; FuzzyVariable : Java class
    ;;      Jess globle variables are used to hold Java objects

    (import nrc.fuzzy.*)
    (defglobal ?*tempFvar* = (new FuzzyVariable "temperature" 0.0 100.0 "C"))
    (defglobal ?*pressFvar* = (new FuzzyVariable "pressure" 0.0 10.0 "kilo-pascals"))

    ;; using an array of (x,y) values to define a Fuzzy set

    (bind ?xHot  (create$ 25.0 35.0))
    (bind ?yHot  (create$ 0.0 1.0))
    (bind ?xCold (create$ 5.0 15.0))
    (bind ?yCold (create$ 1.0 0.0))
    (?*tempFvar* addTerm "hot" ?xHot ?yHot 2)
    (?*tempFvar* addTerm "cold" ?xCold ?yCold 2)

    Show

    ;; using already defined terms of fuzzy variables and linguistic expressions

    (load-package nrc.fuzzy.jess.FuzzyFunctions)

    (?*tempFvar* addTerm "veryHot" "very hot")
    (?*tempFvar* addTerm "medium" "not hot and (not cold)")

    ;; assert a fuzzy fact.
    ;; FuzzyValue : Java class

    (assert (theTemp (new FuzzyValue ?*tempFvar* "very medium")))

    Show

Fuzzy Sets

Fuzzy Set Hierarchy

    (load-package nrc.fuzzy.jess.FuzzyFunctions)
    (?*fcnFvar* addTerm "trapezoid" (new TrapezoidFuzzySet 3.0 3.8 6.5 7.0))
    (?*fcnFvar* addTerm "rectangle" (new RectangleFuzzySet 3.8 6.5))
    (?*fcnFvar* addTerm "triangle"  (new TriangleFuzzySet 3.0 5.4 7.0))
    (?*fcnFvar* addTerm "pi"        (new PIFuzzySet 4.7 2.0))
    (?*fcnFvar* addTerm "s"         (new SFuzzySet 1.0 9.0))
    (?*fcnFvar* addTerm "z"         (new ZFuzzySet 1.0 9.0))

Plot

 (printout t (call (new FuzzyValue ?*fcnFvar* "trapezoid")
                    plotFuzzyValue "*") crlf)
  1. TrapezoidFuzzySet
  2. RectangleFuzzySet
  3. TriangleFuzzySet
  4. PIFuzzySet
  5. SFuzzySet
  6. ZFuzzySet
    (defglobal ?*rlf* = (new RightLinearFunction))
    (?*fcnFvar* addTerm "right" (new RFuzzySet 0.0 5.0 ?*rlf*))

    (defglobal ?*llf* = (new LeftLinearFunction))
    (?*fcnFvar* addTerm "left"  (new LFuzzySet 5.5 7.0 ?*llf*))

Plot

  1. RFuzzySet
  2. LFuzzySet

Fuzzy Rules

A Fuzzy rule holds three sets of fuzzy values representing the antecedents, conclusions and input values of a rule.
    ;; the rule 'if temperature hot then pressure low or medium'
    (defrule temp-hot-press-lowOrMedium
        (theTemp ?t&:(fuzzy-match ?t "hot"))
        =>
        (assert (thePress (new FuzzyValue ?*pressFvar* "low or medium")))
    )

When a temperature fact is asserted that has a FuzzyValue in it, the fuzzy-match will compare the FuzzyValue in the fact to the FuzzyValue hot.

Certainty Factor

In Jess the User Function, fuzzy-rule-similarity provides the same value that FuzzyCLIPS would for a fuzzy-crisp rule's Certainty Factor for the crisp facts to be asserted. The other function, fuzzy-rule-match-score, uses a different measure of similarity, the degree of matching between the fuzzy values.
    (defrule identify-tall-people "determine strength of tallness for a person"
        (person (name ?n) (height ?ht&:(fuzzy-match ?ht "tall")))
        =>
        (printout t ?n " is tall with degree (similarity) " (fuzzy-rule-similarity) crlf)
        (printout t ?n " is tall with degree (match) " (fuzzy-rule-match-score) crlf)
    )

Examples

  1. Temperature -> Pressure: TempPres.clp (Demo)  (jess source)
  2. Temperature -> Pressure with global contribution: TempPres2.clp (Demo)  (jess source)
  3. Similarity and Match-score: height.clp (Demo)  (jess source)

Fuzzy Jess Console

Fuzzy Java/Jess Document

Reference: