infosapient.system
Class FzySet

java.lang.Object
  |
  +--infosapient.system.ObservableImpl
        |
        +--infosapient.system.FzySystemComponent
              |
              +--infosapient.system.FzyClauseComponent
                    |
                    +--infosapient.system.FzySet
Direct Known Subclasses:
FzySCurve, FzySolutionSet, FzyTriangle

public abstract class FzySet
extends FzyClauseComponent
implements java.lang.Cloneable, java.io.Serializable, XMLOutput

Class FzySet is the abstract class of all fuzzy set representations. A fuzzy set is a set that permits partial membership within a given set; and that membership is measured by m such that 0 <= m <= 1. Internally, mis represented by type double.

1.0 represents complete membership within the set.

0.0 represents no membership within the set.

Class FzySet is declared abstract because the initialization of the individual fuzzy set is type specific.

Version:
$Revision: 1.1.1.1 $
See Also:
FzySCurve, FzyTriangle, FzyGaussian, FzyPI, FzyBeta, FzySingleton, Serialized Form

Field Summary
private  double alfaCut
           
private  double completeMembership
          completeMembership is the DOMAIN value of the set where the range is == 1.0.
private  int curveSide
           
protected  double[] domain
           
private  boolean hasSolution
           
private  java.util.Stack hedges
           
private  double height
           
private  boolean leftShouldered
           
protected  double[] membership
           
private  FzyAttribute myAttribute
           
protected  double resolvedValue
           
private  boolean rightShouldered
           
(package private) static long serialVersionUID
           
private  int setType
           
private  boolean twoSided
           
protected  int VECMAX
           
 
Fields inherited from class infosapient.system.FzyClauseComponent
owner, text
 
Fields inherited from class infosapient.system.FzySystemComponent
DEBUG_, myID, name, pcs, serialVersionUID, trace, vcs
 
Fields inherited from class infosapient.system.ObservableImpl
arr, changed, obs, serialVersionUID
 
Constructor Summary
FzySet()
           
 
Method Summary
 void addHedge(FzyHedge ah)
          Add a hedge for future fuzzy surface modification.
abstract  java.lang.Object clone()
          Implemented by FzySet subclasses to provide deep copies of themselves.
 boolean doesContain(double aVal)
          Determine whether this set contains aVal within its domain
 double domainForMembership(double m)
          Return the mean of domain(s) that are mapped to a membership value.
 void dump()
          Used for debugging.
 java.lang.StringBuffer dumpAsStringBuffer()
          Insert the method's description here.
 double getAlphaCut()
           
 FzyAttribute getAttribute()
          Return this sets owning attribute.
 double getCmpMembership()
          The DOMAIN VALUE of complete membership within this set.
 double getDOM(double domainValue)
          Returns a membership value between 0.0 and 1.0 given a domain value contained within this set.
 double getDomain(int index)
          Return the domain specified by an index into the domain array.
 double[] getDomainArray()
          Return the domain array for this set.
 java.util.Stack getHedges()
          Return the collection of hedges to be applied to this set as a java.util.Stack.
 double getHighDomain()
          Return the current high domain value of this set.
 int getIndexForDomain(double domainValue)
           
 double getLowDomain()
          Return the current low domain value for this set.
 double getMaxHeight()
          Height is current maximum membership (typically wanted after correlation).
 double[] getMemberArray()
          Return the membership array for this set.
 double getMembership(int loc)
          Return the value for the indicated index into membership array.
 double getMinHeight()
          Height is current minimum membership (typically wanted after correlation).
 java.lang.String getQualifiedName()
          Returns the name of this set appended to the attribute that it belongs to.
 java.lang.String getSides()
           
 double getSolution()
          Return the current solution domain value of this FzySolutionSet.
 double getSolutionDOM()
          Return the solution degree of membership for this FzySolutionSet.
 int getVECMAX()
          Return the length of the membership and domain arrays.
 boolean hasSolution()
          Return true if this set has a membership and cooresponding domain computed for it yet.
 void initializeDomain(double low, double high)
          Validate the low and high domain to make sure we can do calculations.
abstract  FzySet initializeMembership()
          This method must be implemented by my subclasses.
 double integrateMbr()
          Convienence method to invoke integrateMbr on the entire length of the membership array.
 double integrateMbr(int start, int end)
          Compute the area under the curve for the index start to the index end.
 boolean isLeftShouldered()
           
 boolean isNormal()
          Returns a boolean based on whether membership is: 0.0 <= m[i] <= 1.0.
 boolean isRightShouldered()
           
 boolean isTwoSided()
          Used for quick check of whether this set is two sided or not.
 boolean lessThanOrEquals(FzySet aSet)
          A cheap comparison of sets to make sure that the sets are added to the attribute in decreasing order.
 void printOn(java.io.Writer outWriter, int nTabs)
          Used to represent this set on an outputStream.
 void reset()
          Overridden as a no op because reset is not applicable to Fuzzy Sets
protected  void setAttribute(FzyAttribute fa)
          Set the owning attribute for this set.
 void setCmpMembership(double m)
          Used to set the domain value for complete membership during set initialization.
 void setDomain(double value, int inx)
          Inject an arbitrary value into the domain array.
 void setDomainArray(double[] d)
          Sets a double array as the domain for this set.
 void setHedges(java.util.Stack hedgeStack)
          Set the hedges to be applied.
 void setHighDomain(double value)
          Sets the high domain value for this fuzzy set.
 FzySet setLeftShouldered()
          Declare this set to be left shouldered.
 void setLowDomain(double value)
          Set the low domain value of this set to be value.
 void setMembership(double value, int inx)
          Insert an arbitrary value into the membership array.
 void setMembershipArray(double[] a)
          Sets an array of double to be the membership of this fuzzy set.
 FzySet setRightShouldered()
          Declare this set to be right shouldered.
 void setSolution(double v)
          Method setSolution is implemented in FzySet rather than FzySolutionSet so as to not require frequent casting to FzySolutionSet.
 FzySet setTwoSided()
          declare this set to be two sided.
 double sumDomain(int start, int end)
          Returns the sum of all the current domain values of this fuzzy set, based on the indices start and end.
 java.lang.StringBuffer toXML(int nTabs)
          Represent this set as XML tags.
abstract  java.lang.String typeAsString()
           
 FzySet validate(double low, double high)
          Validate the low and high domain to make sure we can do calculations.
 FzySet validate(double low, double high, double m)
          Validate to make sure we can do calculations.
 
Methods inherited from class infosapient.system.FzyClauseComponent
append, append, getOwner, getText, setOwnerClause, setText, toText
 
Methods inherited from class infosapient.system.FzySystemComponent
addPropertyChangeListener, addVetoableChangeListener, equals, getID, getName, getPropertyChangeSupport, getVetoableChangeSupport, hashCode, removePropertyChangeListener, removeVetoableChangeListener, setID, setName
 
Methods inherited from class infosapient.system.ObservableImpl
addObserver, clearChanged, containsObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID

myAttribute

private FzyAttribute myAttribute

rightShouldered

private boolean rightShouldered

leftShouldered

private boolean leftShouldered

twoSided

private boolean twoSided

hasSolution

private boolean hasSolution

VECMAX

protected int VECMAX

membership

protected double[] membership

domain

protected double[] domain

curveSide

private int curveSide

setType

private int setType

alfaCut

private double alfaCut

height

private double height

resolvedValue

protected double resolvedValue

hedges

private java.util.Stack hedges

completeMembership

private double completeMembership
completeMembership is the DOMAIN value of the set where the range is == 1.0. (Before defuzzification).
Constructor Detail

FzySet

public FzySet()
Method Detail

addHedge

public void addHedge(FzyHedge ah)
Add a hedge for future fuzzy surface modification. (Hedges are applied LIFO.)
Parameters:
FzyHedge - the hedge to be applied.
Returns:
FzySet this set.

clone

public abstract java.lang.Object clone()
Implemented by FzySet subclasses to provide deep copies of themselves.
Overrides:
clone in class java.lang.Object

doesContain

public boolean doesContain(double aVal)
Determine whether this set contains aVal within its domain
Parameters:
double - aVal
Returns:
boolean contains aVal

domainForMembership

public double domainForMembership(double m)
                           throws java.lang.IllegalArgumentException,
                                  FzySystemException
Return the mean of domain(s) that are mapped to a membership value.

WARNING: This method cannot guarantee a unique solution as there may be several domain values that match the given membership. Therefore the mean is returned, intstead of a single value. If there is only one domain for a given membership, then that value is returned.

Parameters:
double - membership for the domain currently sought.
Returns:
double domain that the membership is mapped to.
Throws:
java.lang.IllegalArgumentException - thrown if membership is Double.NaN or membershipis < 0 or >1.0
FzySystemException - thrown if no membership found that matches.

dump

public void dump()
Used for debugging. Dump this sets domain and membership arrays to standard output.

dumpAsStringBuffer

public java.lang.StringBuffer dumpAsStringBuffer()
Insert the method's description here. Creation date: (2/23/00 10:10:10 AM)
Returns:
java.lang.StringBuffer

getAlphaCut

public double getAlphaCut()
Returns:
double The alpha cut domain value of this set.

getAttribute

public FzyAttribute getAttribute()
Return this sets owning attribute.
Returns:
FzyAttribute

getCmpMembership

public double getCmpMembership()
The DOMAIN VALUE of complete membership within this set.
Returns:
double The domain value of complete membership.

getDOM

public final double getDOM(double domainValue)
                    throws java.lang.IllegalArgumentException,
                           FzySystemException
Returns a membership value between 0.0 and 1.0 given a domain value contained within this set. If the domain value is less than the domain of the set, then the degree of membership for the given domain value is set to the degree of membership for the lowest domain value defined for this set. The same is true for the highest domain value.
Parameters:
double - the domain value
Returns:
double the membership of the domain value within this set.
Throws:
FzySystemException - -- when calculated offset is Double.NaN
java.lang.IllegalArgumentException - - if the domain value is Double.NaN

getDomain

public final double getDomain(int index)
                       throws java.lang.IllegalArgumentException
Return the domain specified by an index into the domain array.
Parameters:
int - the index to the domain value.
Returns:
double the domain value.
Throws:
java.lang.IllegalArgumentException - (index < 0; index >= VECMAX)

getDomainArray

public double[] getDomainArray()
Return the domain array for this set.
Returns:
double[] The domain array for this set.

getHedges

public java.util.Stack getHedges()
Return the collection of hedges to be applied to this set as a java.util.Stack. (LIFO)
Returns:
Stack the current stack of hedges to be applied to this set.

getHighDomain

public double getHighDomain()
Return the current high domain value of this set.
Returns:
double the high domain value. ( ALWAYS domain[VECMAX-1].)

getIndexForDomain

public final int getIndexForDomain(double domainValue)
                            throws java.lang.IllegalArgumentException,
                                   FzySystemException

getLowDomain

public double getLowDomain()
Return the current low domain value for this set. (domain[0])
Returns:
double the low domain value.

getMaxHeight

public double getMaxHeight()
Height is current maximum membership (typically wanted after correlation). SHOULD NEVER BE ABOVE 1.0.

getMemberArray

public double[] getMemberArray()
Return the membership array for this set.
Returns:
double[] The membership array for this set.

getMembership

public final double getMembership(int loc)
                           throws java.lang.IllegalArgumentException
Return the value for the indicated index into membership array.
Parameters:
double - loc the location in the membership.
Throws:
java.lang.IllegalArgumentException - ( loc < 0; loc >= VECMAX)

getMinHeight

public double getMinHeight()
Height is current minimum membership (typically wanted after correlation). SHOULD NEVER BE BELOW 0.0.

getQualifiedName

public java.lang.String getQualifiedName()
Returns the name of this set appended to the attribute that it belongs to.
Returns:
String the full name of this set.

getSides

public java.lang.String getSides()

getSolution

public double getSolution()
                   throws java.lang.IllegalStateException
Return the current solution domain value of this FzySolutionSet.
Returns:
double the domain value.
Throws:
java.lang.IllegalStateException - thrown if this is not an instance FzySolutionSet.

getSolutionDOM

public double getSolutionDOM()
                      throws java.lang.IllegalStateException
Return the solution degree of membership for this FzySolutionSet.
Overrides:
getSolutionDOM in class FzyClauseComponent
Returns:
double the degree of membership for the value of the domain solution.
Throws:
java.lang.IllegalStateException - thrown if this object is not an instance of FzySolutionSet.

getVECMAX

public final int getVECMAX()
Return the length of the membership and domain arrays. (They are always equal in length.)
Returns:
int the length of the arrays

hasSolution

public boolean hasSolution()
Return true if this set has a membership and cooresponding domain computed for it yet.
Overrides:
hasSolution in class FzyClauseComponent
Returns:
boolean true if a solution has been computed; false otherwise.

initializeDomain

public void initializeDomain(double low,
                             double high)
                      throws FzySystemException
Validate the low and high domain to make sure we can do calculations. Then initialize the domain to 255 steps from low to the high domain.
Parameters:
double - low - the lowdomain of this set
double - high - the highdomain of this set
Returns:
FzySet - this set
Throws:
FzySystemException - thrown if low >= high

initializeMembership

public abstract FzySet initializeMembership()
                                     throws FzySystemException
This method must be implemented by my subclasses. Initialize the membership of this set based on the type of set.
Returns:
FzySet the set.
Throws:
FzySystemException - if a computation exception occurs.

integrateMbr

public double integrateMbr()
Convienence method to invoke integrateMbr on the entire length of the membership array.
Returns:
double the summed value of the membership array.

integrateMbr

public double integrateMbr(int start,
                           int end)
Compute the area under the curve for the index start to the index end. Sum = membership(i); i = start; to end.
Parameters:
int - start the starting index.
int - end the ending index.
Returns:
double the sum of the area.
Throws:
java.lang.IllegalArgumentException - if (start < 0) or (end > VECMAX-1)

isLeftShouldered

public boolean isLeftShouldered()

isNormal

public boolean isNormal()
Returns a boolean based on whether membership is: 0.0 <= m[i] <= 1.0.

isRightShouldered

public boolean isRightShouldered()

isTwoSided

public boolean isTwoSided()
Used for quick check of whether this set is two sided or not.

lessThanOrEquals

public boolean lessThanOrEquals(FzySet aSet)
A cheap comparison of sets to make sure that the sets are added to the attribute in decreasing order. I.e. Compare ((this.lowdomain + this.highDomain + this.completeMembership)/3.0) <= ((aSet.lowdomain + aSet.highdomain + aSet.completeMembership)/3.0). Results are indeterminate if one mostly or completely overlaps the other.
Parameters:
FzySet - - the set to be compared to.
Returns:
boolean - greater than this set.

printOn

public void printOn(java.io.Writer outWriter,
                    int nTabs)
             throws java.io.IOException
Used to represent this set on an outputStream. (I.e. Save the knowledgebase after editing its properties.)
Overrides:
printOn in class FzySystemComponent
Parameters:
java.io.Writer - -- the outputWriter stream
int - -- the number of tabs to indent for pretty printing.

reset

public void reset()
Overridden as a no op because reset is not applicable to Fuzzy Sets
Overrides:
reset in class FzyClauseComponent

setAttribute

protected void setAttribute(FzyAttribute fa)
Set the owning attribute for this set.
Parameters:
FzyAttribute - -- the owning clause component for this set.

setCmpMembership

public void setCmpMembership(double m)
Used to set the domain value for complete membership during set initialization.
Parameters:
double - the DOMAIN value at which 100% membership is attained.
Returns:
FzySet this set.

setDomain

public void setDomain(double value,
                      int inx)
               throws java.lang.IllegalArgumentException
Inject an arbitrary value into the domain array.
Parameters:
double - -- the new domain value to be injected.
int - -- the index for the domain value.
Throws:
java.lang.IllegalArgumentException - -- If the index is less than zero or greater than VECMAX - 1 or Value is less than lowDomain() or greater than highDomain().

setDomainArray

public final void setDomainArray(double[] d)
Sets a double array as the domain for this set.
Parameters:
double[] - the domain array for this fuzzy set.

setHedges

public void setHedges(java.util.Stack hedgeStack)
Set the hedges to be applied. Used when constructing a FzySet with hedges manually.
Parameters:
Stack - the hedges to be applied in LIFO order.
Returns:
FzySet this set.

setHighDomain

public final void setHighDomain(double value)
Sets the high domain value for this fuzzy set.
Parameters:
double - value the high domain for this set.

setLeftShouldered

public FzySet setLeftShouldered()
Declare this set to be left shouldered. (I.e. 100%Membership <--> domain[0].)
Returns:
FzySet this set.

setLowDomain

public final void setLowDomain(double value)
Set the low domain value of this set to be value.

setMembership

public void setMembership(double value,
                          int inx)
Insert an arbitrary value into the membership array.
Parameters:
double - the new value.
int - the index into the membership array.
Returns:
FzySet this set.
Throws:
java.lang.IllegalArgumentException - If the index is less than zero or greater than VECMAX - 1 or Value is less than 0.0d or greater than 1.0d.

setMembershipArray

public final void setMembershipArray(double[] a)
Sets an array of double to be the membership of this fuzzy set.
Parameters:
double[] - the array of membership values for this set.

setRightShouldered

public FzySet setRightShouldered()
Declare this set to be right shouldered. (I.e. 100%Membership <--> domain[VECMAX-1].)
Returns:
FzySet this set.

setSolution

public void setSolution(double v)
                 throws java.lang.IllegalStateException
Method setSolution is implemented in FzySet rather than FzySolutionSet so as to not require frequent casting to FzySolutionSet. Set the current solution of this FzySolutionSet to be a double.
Parameters:
double - the computed (domain) value of this set.
Throws:
java.lang.IllegalStateException - if method is invoked on any set other than a FzySolutionSet.

setTwoSided

public FzySet setTwoSided()
declare this set to be two sided. (Shouldered.)
Returns:
FzySet this set.

sumDomain

public double sumDomain(int start,
                        int end)
                 throws java.lang.IllegalArgumentException
Returns the sum of all the current domain values of this fuzzy set, based on the indices start and end.
Parameters:
int - start -- the index within this set to start summation.
int - end -- the index within this set to end summation.
Throws:
java.lang.IllegalArgumentException - -- if start < 0 || start > end; || end > length.

toXML

public java.lang.StringBuffer toXML(int nTabs)
Represent this set as XML tags. Creation date: (1/30/00 4:53:49 PM)
Specified by:
toXML in interface XMLOutput
Returns:
java.lang.StringBuffer

typeAsString

public abstract java.lang.String typeAsString()

validate

public FzySet validate(double low,
                       double high)
                throws FzySystemException
Validate the low and high domain to make sure we can do calculations.
Parameters:
double - - the lowdomain of this set
double - - the highdomain of this set
Returns:
FzySet - this set
Throws:
FzySystemException - when low >= high

validate

public FzySet validate(double low,
                       double high,
                       double m)
                throws FzySystemException
Validate to make sure we can do calculations. (lowDomain < highDomain; lowDomain <= completeMembership <= highDomain).
Parameters:
double - - the lowdomain of this set
double - - the highdomain of this set
double - - the completeMembership of this set.
Returns:
FzySet - this set
Throws:
FzySystemException - when low >= high

License to use this program is provided under the TERMS OF THE COMMON PUBLIC LICENSE 0.5. ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.

Copyright (c) 2001, Workplace Performance Tools, All Rights Reserved