I have a function which consists of 3 linear functions, and looks like that:
The function is defined this way:
t0 = 0.0
t1 = 0.069 #lowest threshold
t2 = 0.17 #highest threshold
t3 = 1.0
y0 = 0.0
y1 = 0.7
y2 = 2.8
y3 = 4
tt = np.linspace(0, 1.0)
yy = np.select(
condlist=[tt < t1, tt < t2, tt < t3],
choicelist=[(tt - t0) / (t1 - t0) * (y1 - y0) + y0,
(tt - t1) / (t2 - t1) * (y2 - y1) + y1
, (tt - t2) / (t3 - t2) * (y3 - y2) + y2],
default=y3,
)
and the dashed red lines are t1,t2.
Now, I want to create a sigmoid function, that will behave very much like these linear functions, i.e., I want it to:
- be flat and start the exponential part, before t1.
- be very steep between t1,t2
- at around t2, change the slope and be more flat, until the end
So far, I have succeeded to create this function:
But I still didn't find a good way to bind t2 to the sigmoid function, so it will behave more like the linear functions. For example, I want that if t2 will be 0.4, the sigmoid exponential slope will be somewhere between t1=0.07 and t2=0.4. Also, I want the slope after t2 to be more gradual (i.e. converge to the value 4 slower) Any ideas on how to include t2 in my sigmoid function and adjust it to my needs?
import matplotlib.pyplot as plt
import numpy as np
import math
t0 = 0.0
t1 = 0.07 #lowest bucket threshold
t2 = 0.18 #highest bucket threshold
t3 = 1.0
####################################### sigmoid ###########################
fig, ax = plt.subplots()
k = 40 #### the bigger it is, the more steep the function is
x0 = 0.12 #### the bigger it is, the later the steep increase will begin (it takes the sigmoid more to the right)
c = 4
x = np.linspace(0, 1, 100)
z1 = c * 1 / (1 + np.exp(-k*(x-x0)))
plt.plot(x, z1)
for b in [t1, t2]:
ax.axvline(b, color="red", linestyle='--')
################################### linear functions #####################
y0 = 0.0
y1 = 0.7
y2 = 2.8
y3 = 4
tt = np.linspace(0, 1.0)
yy = np.select(
condlist=[tt < t1, tt < t2, tt < t3],
choicelist=[(tt - t0) / (t1 - t0) * (y1 - y0) + y0,
(tt - t1) / (t2 - t1) * (y2 - y1) + y1
, (tt - t2) / (t3 - t2) * (y3 - y2) + y2],
default=y3,
)
fig.set_size_inches(8, 6)
ax.plot(tt, yy)
xposition = [0.084, 0.106]
plt.show()
For example, I want the slope to be more gradual at point t2 (see dark blue painting) (but that it will be a part of the function, so if t2 moves, so does the function changes)