nrc.fuzzy.jess
Class FuzzyFunctions.FuzzyRuleMatchScore

java.lang.Object
  |
  +--nrc.fuzzy.jess.FuzzyFunctions.FuzzyRuleMatchScore
All Implemented Interfaces:
jess.Userfunction
Enclosing class:
FuzzyFunctions

public class FuzzyFunctions.FuzzyRuleMatchScore
extends java.lang.Object
implements jess.Userfunction

Userfunction class:

Implements the Jess user function (fuzzy-rule-match-score)

The function returns a value between 0.0 and 1.0 which indicates the overall fuzzy match scores of the patterns that matched on the left hand side (LHS) of a rule, if the function is called from the right hand side (RHS) of a rule. If not called from the RHS of a rule it will always return 0.0. The value is determined by calcualting the minimum (or product -- depends on the current rule's antecedentCombineOperator) of all of the fuzzy matches that were made on the LHS of the rule. If there were no fuzzy matches on the LHS of the rule a value of 1.0 is returned. A fuzzy-match score is the maximum value of the intersection of the 2 fuzzy values. This is different than the fuzzy-similarity of 2 fuzzy values, which provides a more complex (and possibly more useful) measure of the similarity of 2 fuzzy values.

This is used in Jess rules to determine the minimum match score with which fuzzy patterns on LHS matched. This can serve as the basis for a certainty factor or degree of confidence for fuzzy facts asserted on the RHS of a rule (as in FuzzyCLIPS) or for other user defined purposes. Consider the simple example below.

 ;; A simple example to test a complete FuzzyJess program (no Java code at all).
 ;;
 ;;
 ;; Note: future versions (beyond 5.0a5) of Jess will allow us to use --
 ;;
 ;;             (new FuzzyValue ... )
 ;;       etc.
 ;;
 ;;       will no longer always need to fully qualify the classes!
 ;;
 ;; Example as shown will give result ...
 ;;
 ;; Jack is tall with degree (similarity) 0.5363321799307958
 ;; Jack is tall with degree (match) 0.588235294117647
 ;; Randy is tall with degree (similarity) 1.0
 ;; Randy is tall with degree (match) 1.0
 ;; Ralph is tall with degree (similarity) 0.4117647058823532
 ;; Ralph is tall with degree (match) 0.49999999999999994
 
 
 (defglobal ?*heightFvar* = (new nrc.fuzzy.FuzzyVariable "height" 0.0 10.0 "feet"))
 
 (defglobal ?*rlf* = (new nrc.fuzzy.RightLinearFunction))
 (defglobal ?*llf* = (new nrc.fuzzy.LeftLinearFunction))
 
 (deftemplate person
    (slot name)
    (slot height)
 )
 
 (defrule init
    (declare (salience 100))
   =>
    (load-package nrc.fuzzy.jess.FuzzyFunctions)
    (?*heightFvar* addTerm "short" (new nrc.fuzzy.RFuzzySet 0.0 5.0 ?*rlf*))
    (?*heightFvar* addTerm "medium" (new nrc.fuzzy.TrapezoidFuzzySet 4.0 4.8 5.5 6.0))
    (?*heightFvar* addTerm "tall" (new nrc.fuzzy.LFuzzySet 5.5 6.0 ?*llf*))
 
    (assert (person (name "Ralph")
                 (height (new nrc.fuzzy.FuzzyValue ?*heightFvar*
                              (new nrc.fuzzy.PIFuzzySet 5.7 0.1)))
         )
         (person (name "Timothy")
                 (height (new nrc.fuzzy.FuzzyValue ?*heightFvar*
                              (new nrc.fuzzy.PIFuzzySet 4.0 0.1)))
         )
         (person (name "Randy")
                 (height (new nrc.fuzzy.FuzzyValue ?*heightFvar*
                              (new nrc.fuzzy.PIFuzzySet 6.5 0.1)))
         )
         (person (name "Jack")
                 (height (new nrc.fuzzy.FuzzyValue ?*heightFvar*
                              (new nrc.fuzzy.PIFuzzySet 5.75 0.1)))
         )
     )
 )

 (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)
 )
 

Note that the similar function 'fuzzy-rule-similarity' returns the overall similarity score between patterns on the RHS of the rule (depends on the rule's antecedentCombineOperator -- minimum or product of the values). In fuzzyCLIPS this value would be used as the certainty factor for non-fuzzy (crisp) facts asserted on the RHS of rules, and the fuzzy-rule-match-score would be used as the certainty factor for fuzzy facts asserted on the RHS of rules.


Constructor Summary
FuzzyFunctions.FuzzyRuleMatchScore()
           
 
Method Summary
 jess.Value call(jess.ValueVector vv, jess.Context context)
           
 java.lang.String getName()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FuzzyFunctions.FuzzyRuleMatchScore

public FuzzyFunctions.FuzzyRuleMatchScore()
Method Detail

getName

public java.lang.String getName()
Specified by:
getName in interface jess.Userfunction
Returns:
String the name of the Jess function

call

public jess.Value call(jess.ValueVector vv,
                       jess.Context context)
                throws jess.JessException
Specified by:
call in interface jess.Userfunction
Parameters:
vv - a ValueVector with the function arguments (0 arguments)
context -
Returns:
Value the match score for the rule.
Throws:
jess.JessException