|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nrc.fuzzy.FuzzyRule
A FuzzyRule holds three sets FuzzyValues for the antecedents, conclusions and input values of a rule. A rule might be written as follows:
if antecedent1 and antecedent2 and ... antecedentn then conclusion1 and conclusion2 and ... conclusionmAttaching a set of fuzzy value inputs to the rule that correspond to actual values for the antecedents, a set of actual conclusions can be determined by executing (firing) the rule, using the FuzzyRuleExecutor that is associated with a the rule. The executor will generally implement one of the common algorithms for fuzzy inferencing such as the Mamdani min inference operator with the Max-Min composition operator.
Note that this allows only very simple rules that have only fuzzy values on the left hand side and right hand side. The fuzzy package is integrate with the Jess expert system shell and provides the ability to create much more complex rules, combining crisp and fuzzy values. It also provides a simpler way to build the rule systems.
An very simple example of Java code that implements a rule and its firing follows:
// some values used to describe fuzzy terms double xHot[] = {25, 35}; double yHot[] = {0, 1}; double xCold[] = {5, 15}; double yCold[] = {1, 0}; // A few FuzzyValues FuzzyValue fval = null; FuzzyValue fval2 = null; FuzzyValue fval3 = null; FuzzyValue fvals[] = new FuzzyValue[2]; // define our temperature fuzzy variable FuzzyVariable temp = new FuzzyVariable("temperature", 0, 100, "C"); temp.addTerm("hot", xHot, yHot, 2); temp.addTerm("cold", xCold, yCold, 2); temp.addTerm("veryHot", "very hot"); temp.addTerm("medium", "(not hot and (not cold))"); // define our pressure fuzzy variable FuzzyVariable pressure = new FuzzyVariable("pressure", 0, 10, "kilo-pascals"); pressure.addTerm("low", new ZFuzzySet(2.0, 5.0)); pressure.addTerm("medium", new PIFuzzySet(5.0, 2.5)); pressure.addTerm("high", new SFuzzySet(5.0, 8.0)); // let's try some rules --- FuzzyRule rule1 = new FuzzyRule(); fval = new FuzzyValue( temp, "hot"); fval2 = new FuzzyValue( pressure, "low or medium"); fval3 = new FuzzyValue( temp, "very medium"); rule1.addAntecedent(fval); rule1.addConclusion(fval2); rule1.addInput(fval3); // execute this simple rule with a single antecedent and // a single consequent using default rule executor -- // MamdaniMinMaxMinRuleExecutor FuzzyValueVector fvv = rule1.execute(); // show the results fvals[0] = fval; fvals[1] = fval3; System.out.println(FuzzyValue.plotFuzzyValues("*+", 0, 50, fvals)); System.out.println(fval2.plotFuzzyValue("*", 0, 10)); System.out.println(fvv.fuzzyValueAt(0).plotFuzzyValue("*", 0, 10)); // execute again with a different rule executor -- // LarsenProductMaxMinRuleExecutor fvv = rule1.execute(new LarsenProductMaxMinRuleExecutor()); // and show results System.out.println(fvv.fuzzyValueAt(0).plotFuzzyValue("*", 0, 10)); the above would produce the following graphs as output The Antecedent (hot) and the input (very medium) fuzzy values Fuzzy Value: temperature Linguistic Value: hot (*), very medium (+) 1.00 +++++++++++ **************** 0.95 0.90 * 0.85 0.80 + + * 0.75 0.70 * 0.65 + + 0.60 * 0.55 0.50 + + * 0.45 0.40 * 0.35 + + 0.30 * 0.25 + + 0.20 * 0.15 + + 0.10 + * + 0.05 + + 0.00+++++++******************* +++++++++++++++++ |----|----|----|----|----|----|----|----|----|----| 0.00 10.00 20.00 30.00 40.00 50.00 The conclusion fuzzy value. Fuzzy Value: pressure Linguistic Value: low or medium (*) 1.00************ *** 0.95 * * * 0.90 * * * 0.85 * 0.80 * * 0.75 * 0.70 * 0.65 * * 0.60 0.55 * * * 0.50 0.45 * 0.40 * * 0.35 0.30 0.25 * 0.20 0.15 * 0.10 * 0.05 * 0.00 ************** |----|----|----|----|----|----|----|----|----|----| 0.00 2.00 4.00 6.00 8.00 10.00 The output using MamdaniMinMaxMinRuleExecutor Fuzzy Value: pressure Linguistic Value: ??? (*) 1.00 0.95 0.90 0.85 0.80 0.75 0.70 0.65 0.60 0.55 0.50 0.45 0.40********************************* 0.35 0.30 0.25 * 0.20 0.15 * 0.10 * 0.05 * 0.00 ************** |----|----|----|----|----|----|----|----|----|----| 0.00 2.00 4.00 6.00 8.00 10.00 The conclusion using LarsenProductMaxMinRuleExecutor. Fuzzy Value: pressure Linguistic Value: ??? (*) 1.00 0.95 0.90 0.85 0.80 0.75 0.70 0.65 0.60 0.55 0.50 0.45 0.40************ * 0.35 *** *** *** 0.30 * * * 0.25 * * * 0.20 * * * 0.15 ** * 0.10 * 0.05 ** 0.00 *************** |----|----|----|----|----|----|----|----|----|----| 0.00 2.00 4.00 6.00 8.00 10.00
MamdaniMinMaxMinRuleExecutor
,
LarsenProductMaxMinRuleExecutor
,
FuzzyValue
,
FuzzyVariable
,
FuzzySet
,
Serialized FormConstructor Summary | |
FuzzyRule()
Create a FuzzyRule with a default FuzzyRuleExecutor. |
|
FuzzyRule(nrc.fuzzy.AntecedentCombineOperator combineOperator)
Create a FuzzyRule with a specified antecedentCombineOperator. |
|
FuzzyRule(nrc.fuzzy.FuzzyRuleExecutor exec)
Create a FuzzyRule with a specified FuzzyRuleExecutor. |
|
FuzzyRule(nrc.fuzzy.FuzzyRuleExecutor exec,
nrc.fuzzy.AntecedentCombineOperator combineOperator)
Create a FuzzyRule with a specified FuzzyRuleExecutor and an antecedentCombineOperator. |
Method Summary | |
void |
addAntecedent(nrc.fuzzy.FuzzyValue fval)
Add an antecedent FuzzyValue to the to the end of the set of antecedents for this rule. |
void |
addConclusion(nrc.fuzzy.FuzzyValue fval)
Add a conclusion FuzzyValue to the to the end of the set of conclusions for this rule. |
void |
addInput(nrc.fuzzy.FuzzyValue fval)
Add an input FuzzyValue to the to the end of the set of inputs for this rule. |
nrc.fuzzy.FuzzyValue |
antecedentAt(int i)
Get the antecedent FuzzyValue from the set of antecedents for this rule at the position indicated. |
int |
antecedentsSize()
Return the size of the set of antecedents (the number of antecedents in the rule. |
nrc.fuzzy.FuzzyValue |
conclusionAt(int i)
Get the conclusion FuzzyValue from the set of conclusions for this rule at the position indicated. |
int |
conclusionsSize()
Return the size of the set of conclusions (the number of conclusions in the rule. |
boolean |
doTestRuleMatching(double threshold,
nrc.fuzzy.FuzzyValueVector antecedents,
nrc.fuzzy.FuzzyValueVector inputs)
Does the work for the testRuleMatching methods. |
nrc.fuzzy.FuzzyValueVector |
execute()
Execute (fire) the rule. |
nrc.fuzzy.FuzzyValueVector |
execute(nrc.fuzzy.FuzzyRuleExecutor exec)
Execute (fire) the rule. |
nrc.fuzzy.FuzzyValueVector |
execute(nrc.fuzzy.FuzzyRuleExecutor exec,
nrc.fuzzy.FuzzyValueVector inputs)
Execute (fire) the rule. |
nrc.fuzzy.FuzzyValueVector |
execute(nrc.fuzzy.FuzzyValueVector inputs)
Execute (fire) the rule. |
nrc.fuzzy.AntecedentCombineOperator |
getAntecedentCombineOperator()
Get the rule's current antecedent combine operator. |
nrc.fuzzy.FuzzyValueVector |
getAntecedents()
Return the set of antecedents in a FuzyValueVector. |
nrc.fuzzy.FuzzyValueVector |
getConclusions()
Return the set of conclusions in a FuzzyValueVector. |
static nrc.fuzzy.AntecedentCombineOperator |
getDefaultAntecedentCombineOperator()
Get the default antecedent combine operator for FuzzyRules. |
static nrc.fuzzy.FuzzyRuleExecutor |
getDefaultRuleExecutor()
Get the default executor for FuzzyRules. |
nrc.fuzzy.FuzzyValueVector |
getInputs()
Return the set of inputs in a FuzyValueVector. |
nrc.fuzzy.FuzzyRuleExecutor |
getRuleExecutor()
Get the rule's current rule executor. |
nrc.fuzzy.FuzzyValue |
inputAt(int i)
Get the input FuzzyValue from the set of inputs for this rule at the position indicated. |
int |
inputSize()
Return the size of the set of inputs (the number of inputs in the rule. |
void |
insertAntecedentAt(nrc.fuzzy.FuzzyValue fval,
int i)
Insert an antecedent FuzzyValue into the set of antecedents for this rule at the position indicated. |
void |
insertConclusionAt(nrc.fuzzy.FuzzyValue fval,
int i)
Insert a conclusion FuzzyValue into the set of conclusions for this rule at the position indicated. |
void |
insertInputAt(nrc.fuzzy.FuzzyValue fval,
int i)
Insert an input FuzzyValue into the set of inputs for this rule at the position indicated. |
boolean |
isAntecedentsChanged()
Get of change status of the antecedents. |
boolean |
isAntecendentCombineOperatorChanged()
Get of change status of the antecedent combine operator. |
boolean |
isConclusionsChanged()
Get of change status of the conclusions. |
boolean |
isInputsChanged()
Get of change status of the inputs. |
void |
removeAllAntecedents()
Remove all antecedent FuzzyValues from the set of antecedents for this rule. |
void |
removeAllConclusions()
Remove all conclusion FuzzyValues from the set of conclusions for this rule. |
void |
removeAllInputs()
Remove all input FuzzyValues from the set of inputs for this rule. |
void |
removeAntecedentAt(int i)
Remove an antecedent FuzzyValue from the set of antecedents for this rule at the position indicated. |
void |
removeConclusionAt(int i)
Remove a conclusion FuzzyValue from the set of conclusions for this rule at the position indicated. |
void |
removeInputAt(int i)
Remove an input FuzzyValue from the set of inputs for this rule at the position indicated. |
void |
setAntecedentCombineOperator(nrc.fuzzy.AntecedentCombineOperator combineOperator)
Set the rule's antecedent combine operator to the one provided. |
static void |
setDefaultAntecedentCombineOperator(nrc.fuzzy.AntecedentCombineOperator combineOperator)
Set the rule's default antecedent combine operator to the one provided. |
static void |
setDefaultRuleExecutor(nrc.fuzzy.FuzzyRuleExecutor exec)
Set the rule's default executor to the one provided. |
void |
setRuleExecutor(nrc.fuzzy.FuzzyRuleExecutor exec)
Set the rule's executor to the one provided. |
boolean |
testRuleMatching()
Test to see if the rule antecedents match the rule inputs with enough overlap to ensure rule will fire with meaninful outputs. |
boolean |
testRuleMatching(double threshold)
Test to see if the rule antecedents match the rule inputs with enough overlap to ensure rule will fire with meaninful outputs. |
boolean |
testRuleMatching(double threshold,
nrc.fuzzy.FuzzyValueVector inputs)
Test to see if the rule antecedents match the rule inputs with enough overlap to ensure rule will fire with meaninful outputs. |
boolean |
testRuleMatching(nrc.fuzzy.FuzzyValueVector inputs)
Test to see if the rule antecedents match the rule inputs with enough overlap to ensure rule will fire with meaninful outputs. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public FuzzyRule()
public FuzzyRule(nrc.fuzzy.FuzzyRuleExecutor exec)
exec
- the rule executor to use with this rulepublic FuzzyRule(nrc.fuzzy.FuzzyRuleExecutor exec, nrc.fuzzy.AntecedentCombineOperator combineOperator)
exec
- the rule executor to use with this rulecombineOperator
- the operator to use to combine the match values of the
antecedent/input pairs of the rulepublic FuzzyRule(nrc.fuzzy.AntecedentCombineOperator combineOperator)
combineOperator
- the operator to use to combine the match values of the
antecedent/input pairs of the ruleMethod Detail |
public void addAntecedent(nrc.fuzzy.FuzzyValue fval)
fval
- The FuzzyValue to add.public void insertAntecedentAt(nrc.fuzzy.FuzzyValue fval, int i)
fval
- The FuzzyValue to add.i
- The index (position) at which to add the FuzzyValue (zero based).public void removeAntecedentAt(int i)
i
- The index (position) from which the FuzzyValue should be removed (zero based).public void removeAllAntecedents()
public nrc.fuzzy.FuzzyValue antecedentAt(int i)
i
- The index (position) at which to get the FuzzyValue (zero based).public int antecedentsSize()
public nrc.fuzzy.FuzzyValueVector getAntecedents()
public void addConclusion(nrc.fuzzy.FuzzyValue fval)
fval
- The FuzzyValue to add.public void insertConclusionAt(nrc.fuzzy.FuzzyValue fval, int i)
fval
- The FuzzyValue to add.i
- The index (position) at which to add the FuzzyValue (zero based).public void removeConclusionAt(int i)
i
- The index (position) from which the FuzzyValue should be removed (zero based).public void removeAllConclusions()
public nrc.fuzzy.FuzzyValue conclusionAt(int i)
i
- The index (position) at which to get the FuzzyValue (zero based).public int conclusionsSize()
public nrc.fuzzy.FuzzyValueVector getConclusions()
public void addInput(nrc.fuzzy.FuzzyValue fval)
fval
- The FuzzyValue to add.public void insertInputAt(nrc.fuzzy.FuzzyValue fval, int i)
fval
- The FuzzyValue to add.i
- The index (position) at which to add the FuzzyValue (zero based).public void removeInputAt(int i)
i
- The index (position) from which the FuzzyValue should be removed (zero based).public void removeAllInputs()
public nrc.fuzzy.FuzzyValue inputAt(int i)
i
- The index (position) at which to get the FuzzyValue (zero based).public nrc.fuzzy.FuzzyValueVector getInputs()
public int inputSize()
public boolean isAntecendentCombineOperatorChanged()
public boolean isAntecedentsChanged()
public boolean isConclusionsChanged()
public boolean isInputsChanged()
public void setRuleExecutor(nrc.fuzzy.FuzzyRuleExecutor exec)
exec
- The FuzzyRuleExecutor that will now be used to execute
the rule.public nrc.fuzzy.FuzzyRuleExecutor getRuleExecutor()
public static void setDefaultRuleExecutor(nrc.fuzzy.FuzzyRuleExecutor exec)
exec
- The FuzzyRuleExecutor that will now be used to as the
default when a rule is created and an executor is not specified.public static nrc.fuzzy.FuzzyRuleExecutor getDefaultRuleExecutor()
public void setAntecedentCombineOperator(nrc.fuzzy.AntecedentCombineOperator combineOperator)
combineOperator
- The operator that will now be used to
combine match values of the antecedent/input pairs in the rule.public nrc.fuzzy.AntecedentCombineOperator getAntecedentCombineOperator()
public static void setDefaultAntecedentCombineOperator(nrc.fuzzy.AntecedentCombineOperator combineOperator)
combineOperator
- The operator that will now be used.public static nrc.fuzzy.AntecedentCombineOperator getDefaultAntecedentCombineOperator()
public boolean testRuleMatching() throws IncompatibleRuleInputsException
IncompatibleRuleInputsException
public boolean testRuleMatching(double threshold) throws IncompatibleRuleInputsException
threshold
- The threshold for matching fuzzy values
IncompatibleRuleInputsException
public boolean testRuleMatching(nrc.fuzzy.FuzzyValueVector inputs) throws IncompatibleRuleInputsException
inputs
- The inputs to be used in the test for the rule
IncompatibleRuleInputsException
public boolean testRuleMatching(double threshold, nrc.fuzzy.FuzzyValueVector inputs) throws IncompatibleRuleInputsException
threshold
- The threshold for matching fuzzy values.inputs
- The inputs to be used in the test for the rule.
IncompatibleRuleInputsException
public boolean doTestRuleMatching(double threshold, nrc.fuzzy.FuzzyValueVector antecedents, nrc.fuzzy.FuzzyValueVector inputs) throws IncompatibleRuleInputsException
threshold
- The threshold for matching fuzzy values.antecedents
- The antecedents for the rule.inputs
- The inputs for the rule.
IncompatibleRuleInputsException
public nrc.fuzzy.FuzzyValueVector execute() throws IncompatibleRuleInputsException
IncompatibleRuleInputsException
public nrc.fuzzy.FuzzyValueVector execute(nrc.fuzzy.FuzzyRuleExecutor exec) throws IncompatibleRuleInputsException
exec
- The rule executor to use rather than the one associated with
the rule.
IncompatibleRuleInputsException
public nrc.fuzzy.FuzzyValueVector execute(nrc.fuzzy.FuzzyValueVector inputs) throws IncompatibleRuleInputsException
inputs
- The rule is executed with the specified inputs (rather than with
the inputs currently associated with the rule)
IncompatibleRuleInputsException
public nrc.fuzzy.FuzzyValueVector execute(nrc.fuzzy.FuzzyRuleExecutor exec, nrc.fuzzy.FuzzyValueVector inputs) throws IncompatibleRuleInputsException
exec
- The rule executor to use rather than the one associated with
the rule.inputs
- The rule is executed with the specified inputs (rather than with
the inputs currently associated with the rule)
IncompatibleRuleInputsException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |