nrc.fuzzy
Class ZFunction

java.lang.Object
  |
  +--nrc.fuzzy.ZFunction
All Implemented Interfaces:
FuzzySetFunction, java.io.Serializable

public class ZFunction
extends java.lang.Object
implements FuzzySetFunction, java.io.Serializable

An implementation of the FuzzySetFunction interface to provide a class with the ability to generate a FuzzySet that is a Z-shaped curve with membership value 1 on the upper left to 0 on the lower right. This class is typically used when constructing instances of the classes RFuzzySet and LRFuzzySet. The PIFuzzySet for example is constructed using the SFunction to create its left half and the ZFunction to create its right half.

The ZFunction membership values (y values) are calculated as follows:
leftX is the lower left X value rightX is the upper right X value midpoint is the x value half way between leftX and rightX sqr is the square root function if x is <= leftX then y = 1.0 if x is between leftX and the midpoint then y = 1 - 2*sqr(((x - leftX)/(rightX - leftX))) if x is midpoint then y = 0.5 if x is between the midpoint and rightX then y = 2*sqr(((x - rightX)/(rightX - leftX))) if x is >= rightX then y = 0.0

See Also:
RFuzzySet, LRFuzzySet, PIFuzzySet, SFunction, Serialized Form

Constructor Summary
ZFunction()
          Creates an instance of a ZFunction that is used to generate Fuzzysets with a Z-shape.
ZFunction(int numPoints)
          Creates an instance of an SZFunction that is used to generate Fuzzysets with a Z-shape.
 
Method Summary
 nrc.fuzzy.FuzzySet generateFuzzySet(double leftX, double rightX)
          Creates a FuzzySet with a Z-shape such that the membership value is 1 at the leftX value and 0 at the rightX value.
 nrc.fuzzy.FuzzySet generateFuzzySet(double leftX, double rightX, int numberOfPoints)
          Creates a FuzzySet with a Z-shape such that the membership value is 1 at the leftX value and 0 at the rightX value.
protected  int returnCorrectedNumPoints(int numPoints)
          Keeps the values for the number of points in the S-shaped curve to be >= 3 and odd.
static void setDefaultNumberOfPoints(int numPoints)
          Sets the value of the zFunctionDefaultNumPoints static (class) variable.
 void setNumPoints(int numPoints)
          Sets the value of the defaultNumPoints variable.
protected static double zMembership(double x, double leftX, double flexPoint, double rightX)
          Calculates a membership value for an X value in the Z-shaped function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZFunction

public ZFunction()
Creates an instance of a ZFunction that is used to generate Fuzzysets with a Z-shape. A FuzzySet created will have a 1 value at its upper left and a 0 value at its lower right.


ZFunction

public ZFunction(int numPoints)
Creates an instance of an SZFunction that is used to generate Fuzzysets with a Z-shape. A FuzzySet created will have a 1 value at its upper left and a 1 value at its lower right. When created with this constructor a value for the number of points to be used when creating the Z-shaped fuzzy set is set (defaultNumPoints).

Parameters:
numPoints - the number of points to use when creating the Z-shaped FuzzySet.
Method Detail

generateFuzzySet

public nrc.fuzzy.FuzzySet generateFuzzySet(double leftX,
                                           double rightX)
Creates a FuzzySet with a Z-shape such that the membership value is 1 at the leftX value and 0 at the rightX value. The number of points in the generated FuzzySet is determined by the settings of the local instance variable defaultNumPoints and the static class variable zFunctionDefaultNumPoints.

Specified by:
generateFuzzySet in interface FuzzySetFunction
Parameters:
leftX - the bottom left x value of the Z-shaped curve.
rightX - the upper right x value of the Z-shaped curve.
Returns:
a FuzzySet with X values between leftX and rightX

generateFuzzySet

public nrc.fuzzy.FuzzySet generateFuzzySet(double leftX,
                                           double rightX,
                                           int numberOfPoints)
Creates a FuzzySet with a Z-shape such that the membership value is 1 at the leftX value and 0 at the rightX value. The number of points in the generated FuzzySet is determined by the the paramter numberOfPoints if it is acceptible (>= 3) or it is set to 3. If the number is even it will be set to the next higher odd value (to maintain symmetry for the S curve).

Specified by:
generateFuzzySet in interface FuzzySetFunction
Parameters:
leftX - the bottom left x value of the Z-shaped curve.
rightX - the upper right x value of the Z-shaped curve.
numberOfPoints - the number of points to be used when generating the Z-shaped curve.
Returns:
a FuzzySet with X values between leftX and rightX

zMembership

protected static double zMembership(double x,
                                    double leftX,
                                    double flexPoint,
                                    double rightX)
Calculates a membership value for an X value in the Z-shaped function. Note that it uses 1-SFunction.sMembership(...) since S and Z shapes are the complement of each other.

Parameters:
x - the x value at which we want to get the membership value
leftX - the leftmost X value of the Z-shaped curve
flexPoint - the point of flex (symmetry) for the curve
rightX - the rightmost X value of the Z-shaped curve

setNumPoints

public void setNumPoints(int numPoints)
Sets the value of the defaultNumPoints variable. This value is used to determine the number of points that will be in the Z-shaped fuzzy set generated by the generateFuzzySet(double leftX, double rightX) method, unless it has a value of < 3, in which case the value of static (class) variable, zFunctionDefaultNumPoints, will be used. This allows each instance of the ZFunction to determine its own value for the number of points to be generated. Initially it is set to have the value 0 so that the zFunctionDefaultNumPoints value is used. If the number is even it will be set to the next higher odd value (to maintain symmetry for the Z curve).


setDefaultNumberOfPoints

public static void setDefaultNumberOfPoints(int numPoints)
Sets the value of the zFunctionDefaultNumPoints static (class) variable. This value is used to determine the number of points that will be in the Z-shaped fuzzy set generated by the generateFuzzySet(double leftX, double rightX) method when the local instance variable defaultNumPoints has not been set or is < 3. Initially it is set to have the value 9. If the number is even it will be set to the next higher odd value (to maintain symmetry for the Z curve).


returnCorrectedNumPoints

protected int returnCorrectedNumPoints(int numPoints)
Keeps the values for the number of points in the S-shaped curve to be >= 3 and odd.

Parameters:
numPoints - the integer value to be constrained to be >= 3 and odd.