nrc.fuzzy
Class SFunction

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

public class SFunction
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 an S-shaped curve with membership value 0 on the lower left to 1 on the upper right. This class is typically used when constructing instances of the classes LFuzzySet 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 SFunction 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 = 0.0 if x is between leftX and the midpoint then y = 2*sqr(((x - leftX)/(rightX - leftX))) if x is midpoint then y = 0.5 if x is between the midpoint and rightX then y = 1 - 2*sqr(((x - rightX)/(rightX - leftX))) if x is >= rightX then y = 1.0

See Also:
LFuzzySet, LRFuzzySet, PIFuzzySet, ZFunction, Serialized Form

Constructor Summary
SFunction()
          Creates an instance of an SFunction that is used to generate Fuzzysets with an S-shape.
SFunction(int numPoints)
          Creates an instance of an SFunction that is used to generate Fuzzysets with an S-shape.
 
Method Summary
 nrc.fuzzy.FuzzySet generateFuzzySet(double leftX, double rightX)
          Creates a FuzzySet with an S-shape such that the membership value is 0 at the leftX value and 1 at the rightX value.
 nrc.fuzzy.FuzzySet generateFuzzySet(double leftX, double rightX, int numberOfPoints)
          Creates a FuzzySet with an S-shape such that the membership value is 0 at the leftX value and 1 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 sFunctionDefaultNumPoints static (class) variable.
 void setNumPoints(int numPoints)
          Sets the value of the defaultNumPoints variable.
protected static double sMembership(double x, double leftX, double flexPoint, double rightX)
          Calculates a membership value for an X value in the S-shaped function.
protected static double sqr(double value)
          Squares a double value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SFunction

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


SFunction

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

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

generateFuzzySet

public nrc.fuzzy.FuzzySet generateFuzzySet(double leftX,
                                           double rightX)
Creates a FuzzySet with an S-shape such that the membership value is 0 at the leftX value and 1 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 sFunctionDefaultNumPoints.

Specified by:
generateFuzzySet in interface FuzzySetFunction
Parameters:
leftX - the bottom left x value of the S-shaped curve.
rightX - the upper right x value of the S-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 an S-shape such that the membership value is 0 at the leftX value and 1 at the rightX value. The number of points in the generated FuzzySet is determined by the the paramter numberOfPoints if it is acceptable (>= 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 S-shaped curve.
rightX - the upper right x value of the S-shaped curve.
numberOfPoints - the number of points to be used when generating the S-shaped curve.
Returns:
a FuzzySet with X values between leftX and rightX

sMembership

protected static double sMembership(double x,
                                    double leftX,
                                    double flexPoint,
                                    double rightX)
Calculates a membership value for an X value in the S-shaped function.

Parameters:
x - the x value at which we want to get the membership value
leftX - the leftmost X value of the S-shaped curve
flexPoint - the point of flex (symmetry) for the curve
rightX - the rightmost X value of the S-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 S-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, sFunctionDefaultNumPoints, will be used. This allows each instance of the SFunction 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 sFunctionDefaultNumPoints value is used. If the number is even it will be set to the next higher odd value (to maintain symmetry for the S curve).


setDefaultNumberOfPoints

public static void setDefaultNumberOfPoints(int numPoints)
Sets the value of the sFunctionDefaultNumPoints static (class) variable. This value is used to determine the number of points that will be in the S-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 S curve).


sqr

protected static double sqr(double value)
Squares a double value.

Parameters:
value - the value to be squared.

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.