At the forefront of Artificial Intelligence
  Home Articles Reviews Interviews JDK Glossary Features Discussion Search
Home » Articles » Uncertainty Handling » Applications/Code

fuzzy Class Description

I created a small class called fuzzy to encompass the basics of fuzzy logic. To read about fuzzy logic, read the Generation5 essay on it.

Class Header

The class header file is as follows:
// These are only defined here to avoid conflict
// with Microsoft Windows libraries and the STL.
#define fuzmin(a, b)  (((a) < (b)) ? (a) : (b)) 
#define fuzmax(a, b)  (((a) > (b)) ? (a) : (b)) 

class fuzzy {
  public:
    fuzzy() {};
    fuzzy(float f) : m_fNum(f) {}

    fuzzy operator|(float f) 
      { return fuzzy(fuzmax(m_fNum, f)); }
    fuzzy operator&(float f) 
      { return fuzzy(fuzmin(m_fNum, f)); }
    fuzzy operator!() { return fuzzy(1 - m_fNum); }
		
    fuzzy operator+(float f) { return fuzzy(m_fNum+f); }
    fuzzy operator-(float f) { return fuzzy(m_fNum-f); }
    fuzzy operator*(float f) { return fuzzy(m_fNum*f); }
    fuzzy operator/(float f) { return fuzzy(m_fNum/f); }

    void operator|=(float f) 
      { m_fNum = fuzmax(m_fNum, f); }
    void operator&=(float f) 
      { m_fNum = fuzmin(m_fNum, f); }

    operator float() { return m_fNum; }

    bool contained(float f) { return (m_fNum <= f); }

  protected:
    float	m_fNum;
};
To clarify the comments for the min and max macros. The Windows SDK defines a min and max that will clash with the STL versions of the the function. Therefore, Microsoft supply other macros to use instead, but since portability was an issue when I programmed this, I created my own macros.

Breakdown

The class is very simple, with all the functions being inline in the header file. Note that the operators that return type fuzzy do so so that other fuzzy operations can be performed upon the result. The operator float() will provide the necessary assignment operator to convert from a fuzzy to a float. Its perhaps overly-complicated, and not the most efficient way - but it works.

Submitted: 20/12/1999

Article content copyright © James Matthews, 1999.
 Article Toolbar
Print
BibTeX entry

Search

Latest News
- Generation5 10-year Anniversary (03/09/2008)
- New Generation5 Design! (09/04/2007)
- Happy New Year 2007 (02/01/2007)
- Where has Generation5 Gone?! (04/11/2005)
- NeuroEvolving Robotic Operatives (NERO) (25/06/2005)

What's New?
- Back-propagation using the Generation5 JDK (07/04/2008)
- Hough Transforms (02/01/2008)
- Kohonen-based Image Analysis using the Generation5 JDK (11/12/2007)
- Modelling Bacterium using the JDK (19/03/2007)
- Modelling Bacterium using the JDK (19/03/2007)


All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -