Bryn Mawr College Home Page

Department

People

Curriculum
Research
Resources

1. FuzzyClassifier

A FuzzyClassifier is used in fuzzy logic. It contains a membership function which maps values to a floating-point value between zero and one.

There are a number of built-in types of FuzzyClassifiers which you can create:

RisingFuzzy(a,b)
FallingFuzzy(a,b)
TriangleFuzzy(a,b,c)
TrapezoidFuzzy(a,b,c,d)
GaussianFuzzy(c,s)

Each of these functions returns a different FuzzyClassifier specified by the parameters provided.

You can also create your own FuzzyClassifier by specifying a membership function and any parameters that the function will use. There are certain conventions which the membership function must follow. The function must take no arguments. The arguments to the function are all of the form x0, x1, x2... etc. Alternatively, you can use the name 'x' instead of 'x0' for the first argument. In addition, you can access a list of all the arguments using the list 'argList'. Other than that, you can use any variable names in your function.

So, here is a simple example of creating a new FuzzyClassifier:

def membershipFunction():
  """
  This function takes one argument x and compares x
  to the parameters min and max.
  """
  
  if x <= min:
    return 0.0
  elif x >= max:
    return 1.0
  else:
    return 0.5

f1 = FuzzyClassifier(membershipFunction, "SampleFuzzy", min = 0, max = 10)

When initializing the FuzzyClassifier, the first argument is a reference to the membership function; the second argument is an optional label for the function (which defaults to the function name if it is not supplied); and the remaining arguments specify any parameters which the function will need.

This classifier can now be applied to a value to get a

>>> print f1(-5)
<Fuzzy value 0.0>
>>> print f1(2)
<Fuzzy value 0.5>
>>> print f1(10)
<Fuzzy value 1.0>
>>> print f1
<FuzzyClassifier instance with parameters {'min':0, 'max':10} and membership function SampleFuzzy>

2. operators

You can also create a FuzzyClassifier with certain operations on existing ones.

The negation operator creates a FuzzyClassifier whose membership function is the inverse of the membership function of the operand:

>>> f1 = RisingFuzzy(0,5)
>>> f2 = -f1
>>> float(f1(2))
0.4
>>> float(f2(2))
0.6


ViewWiki | EditWiki | Webmaster@wiki.cs