fuzzylogic icon indicating copy to clipboard operation
fuzzylogic copied to clipboard

Step function

Open schmid-mat opened this issue 2 years ago • 2 comments

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!

schmid-mat avatar Jul 12 '23 10:07 schmid-mat

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 avatar Jul 14 '23 14:07 amogorkon

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?

amogorkon avatar Jul 14 '23 16:07 amogorkon