0

Currently, my program takes in an input and determines the output as a step function (if x >= 30, y = 100, else y=0). Another version has y=x at all times. Through both functions, y can only go from 0 to 100. I would like to have a third parameter that takes the function slowly from one to another.

One option was to just give it a weight (y=F1*alpha + F2 (1-alpha) such that alpha goes from 0 to 1 over time). However this leads to a discontinuous function which I am trying to avoid.

My ideal solution would look like a logistic function curve, but the end points have to be within 0 and 100. The step is also changing and can be anything between 0 and 100.

So is there any such function that may enable me to transition from a step function slowly to a y=x slope?

BBB
  • 1
  • I am sure the tag is wrong but I am new here and do not know what would be a better tag so please let me know if you have any suggestions – BBB May 27 '19 at 07:08

1 Answers1

2

Have you heard of the sigmoid function? You can use $$ S(x) = \frac{1}{1+e^{-x}} = \frac{1}{1+\exp{-x}} $$ to approximate a step function. Furthermore, you can modify the strength of the "jump" by replacing $x$ by $kx$ in this function. So now you could approximate the step function in your case by $$ S_1 (x) = \frac{100}{1+\exp{(-k(x-30))}} $$ for some value $k$. You should try out different values of $k$ and find one that suits you. Maybe try $k=5, 10, 20, \ldots$. Then just blend $S_1$ with the other function, $g(x) = x$. We want the final form to be something like $$ f(x) = (1-\alpha(x)) S_1(x) + \alpha(x) g(x) $$ where $\alpha(x)$ slowly grows from 0 to 1. For this, we can again use the sigmoid function! Let's set $\alpha(x) = \frac{1}{1+\exp{-x}}$. For this we would probably want another strength factor and an offset, so let's actually set $$ \alpha(x) = \frac{1}{1+\exp{(-k_2(x-x_0))}} $$ Here $x_0$ is an offset value, starting from which the blending will start. I don't know which offset value you need, but you can try different versions. I tried values $k=8$, $k_2=0.06$ and $x_0=200$ and I think it looks nice:

https://www.desmos.com/calculator/qkhrufeuym

Matti P.
  • 6,012
  • Hi Matti, I tried something similar to this as well with a logistic function (which looks to be the same as the sigmoid function you mentioned) replacing the step function. Alpha is designed to linearly evolve with time so that is good as well. My concern is that when I blend the two functions, there is a sudden jump in the result. So what I wanted to try was to find a better way to remove this non-continuity at the step point. – BBB May 27 '19 at 14:29
  • I don't understand what you mean. The result I gave is a continuous function. Does the final version of my function satisfy your requirements? – Matti P. May 28 '19 at 05:18