Python-Fuzzylogic / fuzzylogic

Fuzzy Logic and Fuzzy Inference for Python 3
MIT License
123 stars 26 forks source link

Step function #41

Closed schmid-mat closed 3 months ago

schmid-mat commented 1 year ago

Hi, is there the possibility to implement a step function (like on/off)? I tried it by manipulation the function R. Unfortunately, the R and S functions ignore a decimal input, like: R(0.45, 0.5), to approximate a jump.

Thanks!

amogorkon commented 1 year ago

Actually great idea, I'll make one. How should it behave at the x-value of the jump? Is it like (-inf, x] (x, inf) or (-inf, x) [x, inf)?

amogorkon commented 1 year ago
def step(x, /, *, no_m=0, c_m=1):
    """A step function.

    >>> f = step(2)
    >>> f(1)
    0
    >>> f(2)
    1
    """
    assert 0 <= no_m < c_m <= 1

    @njit
    def f(x):
        return c_m if x >= x else no_m

    return f

would that do the trick?