I have this interesting piece of code:
def get_unit_sigmoid_func(alpha: float) -> Callable[[float], float]:
return lambda x, alpha=alpha: 1. / (1 + (1 / np.where(x == 0, 0.01, x) - 1) ** alpha)
I just don't understand what the point of this is. Why wouldn't they write something like:
def get_unit_sigmoid_func(alpha,x):
return 1 / (1+(1/np.where(x==0,0.01,x)-1)**alpha)
Is there any advantage to the way it's written in the first way?
The function
def get_unit_sigmoid_func(alpha: float) -> Callable[[float], float]:
return lambda x, alpha=alpha: 1. / (1 + (1 / np.where(x == 0, 0.01, x) - 1) ** alpha)
returns a function that accepts a float value and an alpha. This function sets a default alpha value, so you don't need to specify it. This is useful when you need a function with a specific signature (e.g., takes one argument), but there are some parameters you want to set first (like alpha).
The function
def get_unit_sigmoid_func(alpha,x):
return 1 / (1+(1/np.where(x==0,0.01,x)-1)**alpha)
returns the value, but notice that it takes an alpha parameter and a float.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With