nrc.fuzzy
Class FuzzyVariable

java.lang.Object
  |
  +--nrc.fuzzy.FuzzyVariable
All Implemented Interfaces:
java.io.Serializable

public class FuzzyVariable
extends java.lang.Object
implements java.io.Serializable

This class defines a FuzzyVariable, which consists of a name (for example, temperature) the units of the variable if required (for example, degrees C), the universe of discourse for the variable (for example a range from 0 to 100), and a set of fuzzy terms that will be used when describing the fuzzy variable. The fuzzy terms are described using a term name such as hot, along with a FuzzySet that represents that term. The fuzzy variable terms along with a set of fuzzy modifiers, the operators 'and' and 'or' (fuzzy set intersection and union respectively) and the left and right parentheses provide the basis for a grammar that allows one to write fuzzy linguistic expressions that describe fuzzy concepts in an english-like manner. For example,

     (very hot or warm) and slightly cold
 
consists of the terms hot, warm and cold, along with the fuzzy modifiers very and slightly.

A FuzzyVariable is normally used in the creation of a FuzzyValue which associates a FuzzySet with a FuzzyVariable. This allows the FuzzySets to be described using the linguistic expressions definable with the FuzzyVaraible terms and restricted by the universe of discourse for the variable.

NOTE: linguistic expressions are case insensitive!!

NOTE ALSO: All names for terms must not have spaces, ) or ( in them. They must also not be AND or OR. They might be the same as some existing modifier and then would override the modifier (not generally a good thing to do).

The following incomplete set of code shows a simple example of creating a FuzzyVariable and a FuzzyValue:


    double xHot[] = {25, 35};
    double yHot[] = {0, 1};
    double xCold[] = {5, 15};
    double yCold[] = {1, 0};
    FuzzyValue fval = null;
    ...
    FuzzyVariable temp = new FuzzyVariable("temperature", 0, 100, "C");
    ...
    temp.addTerm("hot", xHot, yHot, 2);
    temp.addTerm("cold", xCold, yCold, 2);
    // note: once a term is added it can be used to define other terms
    temp.addTerm("medium", "not hot and not cold");
    ...
    fval = new FuzzyValue(temp, "very hot or cold");
    System.out.println(fval);
 
The output from this would be:

 FuzzyVariable         -> temperature [ 0.0, 100.0 ] C
 Linguistic Expression -> very hot or cold
 FuzzySet              -> { 1/5 0/15 0/25 0.01/26 0.04/27 0.09/28 0.16/29 0.25/30
                            0.36/31 0.49/32 0.64/33 0.81/34 1/35  } 
 

See Also:
FuzzyValue, FuzzySet, Modifiers, ModifierFunction, FuzzyScanner, FuzzyValue, Serialized Form

Constructor Summary
FuzzyVariable(java.lang.String n, double UODlower, double UODupper)
          Create a FuzzyVariable (with no Fuzzy Terms) not specifying the units (defaults to empty string)
FuzzyVariable(java.lang.String n, double UODlower, double UODupper, java.lang.String u)
          Create a FuzzyVariable (with no Fuzzy Terms) specifying units
FuzzyVariable(java.lang.String n, double UODlower, double UODupper, java.lang.String[] terms, nrc.fuzzy.FuzzySet[] fuzzySets, int numTerms)
          Create a FuzzyVariable (with Fuzzy Terms) not specifying the units (defaults to empty string)
FuzzyVariable(java.lang.String n, double UODlower, double UODupper, java.lang.String u, java.lang.String[] terms, nrc.fuzzy.FuzzySet[] fuzzySets, int numTerms)
          Create a FuzzyVariable (with Fuzzy Terms) specifying units
 
Method Summary
 nrc.fuzzy.FuzzyValue addTerm(java.lang.String term, double[] x, double[] y, int numPoints)
          Add a term description to the FuzzyVariable.
 nrc.fuzzy.FuzzyValue addTerm(java.lang.String term, nrc.fuzzy.FuzzySet fset)
          Add a term description to the FuzzyVariable.
 nrc.fuzzy.FuzzyValue addTerm(java.lang.String term, nrc.fuzzy.SetPoint[] setPoints, int numPoints)
          Add a term description to the FuzzyVariable.
 nrc.fuzzy.FuzzyValue addTerm(java.lang.String term, java.lang.String linguisticExpr)
          Add a term description to the FuzzyVariable.
 nrc.fuzzy.FuzzyValue findTerm(java.lang.String term)
          Return the fuzzy value that represents a fuzzy term for the fuzzy variable.
 java.util.Enumeration findTermNames()
          Return an enumeration that contains the names of the terms of the fuzzy variable.
 java.util.Enumeration findTerms()
          Return an enumeration that contains the set of fuzzy values that represent the fuzzy terms of the fuzzy variable.
 double getMaxUOD()
          Retrieve the maximum value of the Universe of Discourse of the FuzzyVariable
 double getMinUOD()
          Retrieve the minimum value of the Universe of Discourse of the FuzzyVariable
 java.lang.String getName()
          Retrieve the FuzzyVariable's name.
 java.lang.String getUnits()
          Retrieve the FuzzyVariable's Units string
 nrc.fuzzy.FuzzyValue removeTerm(java.lang.String term)
          Removes the fuzzy term identified by the term name from the fuzzy variable.
 void removeTerms()
          Remove all terms from the fuzzy variable.
 java.lang.String toString()
          Returns the String representation of the FuzzyVariable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FuzzyVariable

public FuzzyVariable(java.lang.String n,
                     double UODlower,
                     double UODupper,
                     java.lang.String u)
              throws InvalidFuzzyVariableNameException,
                     InvalidUODRangeException
Create a FuzzyVariable (with no Fuzzy Terms) specifying units

Parameters:
n - the name of the fuzzy variable (such as temperature)
UODlower - the lower limit of the Universe of Discourse
u - the units for the variable (such as Degrees C)
Throws:
InvalidFuzzyVariableNameException
InvalidUODRangeException

FuzzyVariable

public FuzzyVariable(java.lang.String n,
                     double UODlower,
                     double UODupper)
              throws InvalidFuzzyVariableNameException,
                     InvalidUODRangeException
Create a FuzzyVariable (with no Fuzzy Terms) not specifying the units (defaults to empty string)

Parameters:
n - the name of the fuzzy variable (such as temperature)
UODlower - the lower limit of the Universe of Discourse
Throws:
InvalidUODRangeException
InvalidFuzzyVariableNameException

FuzzyVariable

public FuzzyVariable(java.lang.String n,
                     double UODlower,
                     double UODupper,
                     java.lang.String u,
                     java.lang.String[] terms,
                     nrc.fuzzy.FuzzySet[] fuzzySets,
                     int numTerms)
              throws InvalidFuzzyVariableNameException,
                     InvalidUODRangeException,
                     XValueOutsideUODException,
                     InvalidFuzzyVariableTermNameException
Create a FuzzyVariable (with Fuzzy Terms) specifying units

Parameters:
n - the name of the fuzzy variable (such as temperature)
UODlower - the lower limit of the Universe of Discourse
u - the units for the variable (such as Degrees C)
terms - array of names of terms to be added to the FuzzyVariable
fuzzySets - array of FuzzySets of terms to be added to the FuzzyVariable
numTerms - number of terms to be added
Throws:
InvalidFuzzyVariableNameException
InvalidUODRangeException
XValueOutsideUODException
InvalidFuzzyVariableTermNameException

FuzzyVariable

public FuzzyVariable(java.lang.String n,
                     double UODlower,
                     double UODupper,
                     java.lang.String[] terms,
                     nrc.fuzzy.FuzzySet[] fuzzySets,
                     int numTerms)
              throws InvalidFuzzyVariableNameException,
                     InvalidUODRangeException,
                     XValueOutsideUODException,
                     InvalidFuzzyVariableTermNameException
Create a FuzzyVariable (with Fuzzy Terms) not specifying the units (defaults to empty string)

Parameters:
n - the name of the fuzzy variable (such as temperature)
UODlower - the lower limit of the Universe of Discourse
terms - array of names of terms to be added to the FuzzyVariable
fuzzySets - array of FuzzySets of terms to be added to the FuzzyVariable
numTerms - number of terms to be added
Throws:
InvalidUODRangeException
InvalidFuzzyVariableNameException
XValueOutsideUODException
InvalidFuzzyVariableTermNameException
Method Detail

getName

public java.lang.String getName()
Retrieve the FuzzyVariable's name.


getUnits

public java.lang.String getUnits()
Retrieve the FuzzyVariable's Units string


getMinUOD

public double getMinUOD()
Retrieve the minimum value of the Universe of Discourse of the FuzzyVariable


getMaxUOD

public double getMaxUOD()
Retrieve the maximum value of the Universe of Discourse of the FuzzyVariable


findTerm

public nrc.fuzzy.FuzzyValue findTerm(java.lang.String term)
Return the fuzzy value that represents a fuzzy term for the fuzzy variable.

Parameters:
term - the term name to be accessed (eg hot)
Returns:
the FuzzyValue that represents the term or null if not a term

findTerms

public java.util.Enumeration findTerms()
Return an enumeration that contains the set of fuzzy values that represent the fuzzy terms of the fuzzy variable.

Returns:
an enumeration of FuzzyValues that represent the terms of the FuzzyVariable

findTermNames

public java.util.Enumeration findTermNames()
Return an enumeration that contains the names of the terms of the fuzzy variable.

Returns:
an enumeration of Strings that contain the names of the terms of the FuzzyVariable

removeTerm

public nrc.fuzzy.FuzzyValue removeTerm(java.lang.String term)
Removes the fuzzy term identified by the term name from the fuzzy variable.

Parameters:
term - the term name to be accessed (eg hot)
Returns:
the FuzzyValue that represents the term that was removed or null if not a term

removeTerms

public void removeTerms()
Remove all terms from the fuzzy variable.


addTerm

public nrc.fuzzy.FuzzyValue addTerm(java.lang.String term,
                                    nrc.fuzzy.FuzzySet fset)
                             throws XValueOutsideUODException,
                                    InvalidFuzzyVariableTermNameException
Add a term description to the FuzzyVariable. The description consists of a term name and a fuzzy set. If a term with the same name already exists it will replace that term with this new one.

Parameters:
term - the name of the term being added
fset - the FuzzySet that represents the term
Throws:
XValueOutsideUODException
InvalidFuzzyVariableTermNameException

addTerm

public nrc.fuzzy.FuzzyValue addTerm(java.lang.String term,
                                    double[] x,
                                    double[] y,
                                    int numPoints)
                             throws XValuesOutOfOrderException,
                                    YValueOutOfRangeException,
                                    XValueOutsideUODException,
                                    InvalidFuzzyVariableTermNameException
Add a term description to the FuzzyVariable. The description consists of a term name and a fuzzy set described by 2 arrays. If a term with the same name already exists it will replace that term with this new one.

Parameters:
term - the name of the term being added
x - the x values of a FuzzySet that represents the term
y - the y values of a FuzzySet that represents the term
numPoints - the number of points in these x and y arrays
Throws:
XValuesOutOfOrderException
YValueOutOfRangeException
XValueOutsideUODException
InvalidFuzzyVariableTermNameException

addTerm

public nrc.fuzzy.FuzzyValue addTerm(java.lang.String term,
                                    nrc.fuzzy.SetPoint[] setPoints,
                                    int numPoints)
                             throws XValuesOutOfOrderException,
                                    YValueOutOfRangeException,
                                    XValueOutsideUODException,
                                    InvalidFuzzyVariableTermNameException
Add a term description to the FuzzyVariable. The description consists of a term name and a fuzzy set described by an array of (x,y) points. If a term with the same name already exists it will replace that term with this new one.

Parameters:
term - the name of the term being added
numPoints - the number of points in the setPoints arrays
Throws:
XValuesOutOfOrderException
YValueOutOfRangeException
XValueOutsideUODException
InvalidFuzzyVariableTermNameException
See Also:
SetPoint

addTerm

public nrc.fuzzy.FuzzyValue addTerm(java.lang.String term,
                                    java.lang.String linguisticExpr)
                             throws InvalidLinguisticExpressionException,
                                    InvalidFuzzyVariableTermNameException
Add a term description to the FuzzyVariable. The description consists of a term name and a fuzzy set described by a linguistic expression. If a term with the same name already exists it will replace that term with this new one.

Parameters:
term - the name of the term being added
linguisticExpr - the english-like string that specifies a fuzzy value. Uses the existing defined terms of the FuzzyVariable along with defined fuzzy modifiers and the operators 'and' and 'or'.
Throws:
InvalidLinguisticExpressionException
InvalidFuzzyVariableTermNameException
See Also:
Modifiers

toString

public java.lang.String toString()
Returns the String representation of the FuzzyVariable.

For example:

 FuzzyVariable -> temperature [ 0.0, 100.0 ] C
 Terms:
   hot -> { 0/25 1/35 }
   medium -> { 0/5 1/15 1/25 0/35 }
   cold -> { 1/5 0/15 }
   
 
 

Overrides:
toString in class java.lang.Object
Returns:
the String representation of the FuzzyVariable