[Math] How to create a sigmoid-esque function with the following properties

functionsspecial functions

For a range of $x$ values between $A$ and $B$ I would like $f(x) \rightarrow x$. For values less than $A$ I would like $f(x)$ to exhibit a sigmoid-esque convergence to $A'$ where $A'$ is $A – \delta$ for some small $\delta$. Similarly, for values greater than $B$ I would like $f(x)$ to converge to $B'$ where $B'$ is $B+\delta$ for some small $\delta$.

Typical values will be $A = 0.5$, $B = 1.5$, $A' = 0.4$, $B' = 1.6$.

Best Answer

This image from Wikipedia shows several sigmoid-type functions, each with derivative 1 at the origin:

sigmoid functions

By taking any of these (choose one, and call it $g(x)$), translating, and rescaling gives you $B + \delta g((x-B)/\delta)$. This will serve as the upper end of your function. The "$B +$" is the vertical translation, the "$- B)$" is the horizontal translation, the factor of $\delta$ on the outside rescales $g$ vertically, and the factor of $\delta$ on the inside scales $g$ horizontally (making the derivative correct, so that you don't have a singular point in your piecewise function).

See this example that I typed into wolfram alpha with $g = \tanh$, $B = 1.5$, $\delta = 0.1$: http://www.wolframalpha.com/input/?i=1.5+%2B+0.1+*+tanh%28%28x-1.5%29%2F0.1%29

enter image description here

You can work out the lower end of your function analogously.

$$ f(x) = \left\{ \begin{array}{lr} A + \delta\tanh((x-A)/\delta), & x \leq A \\ x, & A < x < B \\ B + \delta\tanh((x-B)/\delta), & x \geq B \\ \end{array} \right. $$

is one such function, but you don't need to use $\tanh$. If it's unclear how I arrived at this, it could be helpful to take each of the four transformations I performed on $\tanh$ and plotting them individually to see exactly how the function changes, and how the transformations act together to give you what you need.