<reponame>ghazaleh-mahmoodi/-Preceptron-Implementation-without-framework
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009  <NAME>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free 
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
# 
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>. 
#

"""Realize a Z-shaped fuzzy set."""

__revision__ = "$Id: ZFunction.py,v 1.17 2010-03-28 18:44:46 rliebscher Exp $"


from fuzzy.set.SFunction import SFunction

class ZFunction(SFunction):
    r"""Realize a Z-shaped fuzzy set::
           __
             \
             |\
             | \
             | |\
             | | \__
             | a |
             |   |
            2*delta

    see also U{http://pyfuzzy.sourceforge.net/demo/set/ZFunction.png}
    
    @ivar a: center of set.
    @type a: float
    @ivar delta: absolute distance between x-values for minimum and maximum.
    @type delta: float
    """

    def __init__(self, a=0.0, delta=1.0):
        """Initialize a Z-shaped fuzzy set.

        @param a: center of set
        @type a: float
        @param delta: absolute distance between x-values for minimum and maximum
        @type delta: float
        """
        super(ZFunction, self).__init__(a, delta)


    def __call__(self, x):
        """Return membership of x in this fuzzy set.
           This method makes the set work like a function.
           
           @param x: value for which the membership is to calculate
           @type x: float
           @return: membership
           @rtype: float
           """
        return 1.0 - SFunction.__call__(self, x)
