Intepolate from linear to step function, and one application for shading colors

223 Views Asked by At

I'm running after a particular function $f_\sigma : [−1,+1] \rightarrow [-1,+1]$ that could take three different forms depending on the value of its parameter $\sigma$. Could anyone help me finding/building it?

Let the critical values be $-\infty \leqslant \sigma_a < \sigma_b < \sigma_c \leqslant +\infty$, and the following specifications be respected. I need:

  • $\forall \sigma \in \bar{\mathbb{R}}:$

    • $f_\sigma(-1) = -1$
    • $f_\sigma(0) = 0\ \mbox{or indefinite}$
    • $f_\sigma(+1) = +1$
    • $f_\sigma \nearrow \mbox{(weakly)}$
    • $f_\sigma \in \mathcal{C}^1\ \mbox{except eventually in 0}$
  • $\forall x \in [-1,+1]:$

    • $\lim_{\sigma\rightarrow \sigma_a}\ f_\sigma(x) = f_a(x) = x$
    • $\lim_{\sigma\rightarrow \sigma_b}\ f_\sigma(x) = f_b(x) =$ ... I don't know, something "smooth and nice" (see below)
    • $\lim_{\sigma\rightarrow \sigma_c}\ f_\sigma(x) = f_c(x) = \left\{\begin{array}{rrr} +1 & \mbox{if} & x > 0\\ -1 & \mbox{if} & x < 0 \end{array}\right.$
    • $\sigma_a < \sigma < \sigma_c \Rightarrow \left\{\begin{array}{rrr} f_a < f_\sigma < f_c & \mbox{where} & x > 0\\ f_c < f_\sigma < f_a & \mbox{where} & x < 0 \end{array}\right.$

That is: interpolating between the identity and the sign function.

I have several "smooth and nice" candidates for $f_b(x)$ such as $\sin(\frac{\pi}{2}x)$ or $\frac{1}{2} \left(3 x-x^3\right)$, but maybe none of these will provide an actual answer..

Any idea?

[EDIT]: `Got one: $f_\sigma(x) = f_c(x) |x|^{\frac{1}{\sigma}}$ does fulfill the above requirements.. But I'm still not pleased with it: I think that my "smooth and nice" criteria may be given as :

  • $f_\sigma'(-1) = f_\sigma'(+1) = 0\quad \forall \sigma > \sigma_b$ at least

  • $f_\sigma'(0)\ finite\quad \forall \sigma < \sigma_c$

    .. but this is still work in progress..

[EDIT:] Okay, I just can't believe how close we are now.. without being actually there! Somegeekfriendofyours's function f, amazingly defined as :

$f_\alpha(x)=\frac{\left|\frac{1-\frac{2}{\pi}\arccos\left(\alpha\sin\left(\frac{\pi}{2}x\right)\right)}{1-\frac{2}{\pi}\arccos\left(\alpha\right)} \right|^{1+\alpha}}{\frac{1-\frac{2}{\pi}\arccos\left(\alpha\sin\left(\frac{\pi}{2}x\right)\right)}{1-\frac{2}{\pi}\arccos\left(\alpha\right)}}$

with $\alpha \in [0,1]$ does fulfill every single requirement of those listed above.. but it still does it in a rather.. lazy way. Let me explain myself further :

  • $f'_\alpha(0)$ is finite, but still it is.. pretty high.
  • $f'_\alpha(1)$ is null, but still it looks.. pretty hard to get there.

What I mean is : this $f$ here approaches the sign function by its vertical trait, where I would rather like it to do so by sticking to the horizontal ones. That was the very spirit of the last two requirements. I have no idea how the hell I would formalize this, so lets make it clear with a graph :

the sadly empty area

And, for I am aware all this stuff may sound a bit pointless, let's take a peep at one application of this function I am looking for. I wish to shade colors into one another, using this function to interpolate'em. If I could find what I am looking for, I could make nice blendings and tweak how spread the original colors would be within them.

Here is an example showing the reason why this "wrong-side-sticking" problem is.. a problem :P

shading colors

Any idea?

[EDIT:]

Rahul got it in the comments! I don't have the privilege to post it as wiki yet, anyone is then welcome to do so, so the question will be moved off the stack. Thank you so much! ^ ^

2

There are 2 best solutions below

0
On BEST ANSWER

Here are several equivalent definitions: $$\begin{align} f_a(x) &= \tanh(a\tanh^{-1}x) \\ &= \frac{(1+x)^a-(1-x)^a}{(1+x)^a+(1-x)^a} \\ &= \frac{\binom a1x+\binom a3x^3+\binom a5x^5+\cdots}{\binom a0+\binom a2x^2+\binom a4x^4+\cdots}. \end{align}$$

Near $\pm1$, $f$ behaves like a shifted, scaled copy of $x^a$. Also, $f'(0)=a$.

enter image description here

1
On

I played a little with your conditions and this is what I came up with:

Let $\alpha \in ]0,1[$, then: $$ f_\alpha(x)=\frac{\left|\frac{1-\frac{2}{\pi}\arccos\left(\alpha\sin\left(\frac{\pi}{2}x\right)\right)}{1-\frac{2}{\pi}\arccos\left(\alpha\right)} \right|^{1+\alpha}}{\frac{1-\frac{2}{\pi}\arccos\left(\alpha\sin\left(\frac{\pi}{2}x\right)\right)}{1-\frac{2}{\pi}\arccos\left(\alpha\right)}} $$

Which is undefined at $f_\alpha(0)$ but $\lim_{x \rightarrow 0} f_\alpha(x) = 0$ and $\lim_{x \rightarrow 0} f'_\alpha(x)$ is always finite, and $\lim_{x \rightarrow -1} f'_\alpha(x) = \lim_{x \rightarrow 1} f'_\alpha(x) = 0$

A Gnuplot script like this:

set terminal postscript eps enhanced
set output "out.eps"
set multiplot
set xrange [-2:2]
set yrange [-2:2]
f(x)=(1/(1/(1-2*acos(alpha)/pi)*(1-2*acos(alpha*sin(pi/2*x))/pi)))*abs(1/(1-2*acos(alpha)/pi)*(1-2*acos(alpha*sin(pi/2*x))/pi))**(1+alpha)
set key at 1.5,1.9
alpha=0.001
plot f(x) linecolor 1 title "{/Symbol a}=0.001"
set key at 1.5,1.75
alpha=0.5
plot f(x) linecolor 2 title "{/Symbol a}=0.5"
set key at 1.5,1.6
alpha=0.999
plot f(x) linecolor 3 title "{/Symbol a}=0.999"

Gives me this:

enter image description here

Now you just have to find a map $\alpha: [\sigma_a,\sigma_c] \longrightarrow ]0,1[$ such that:

$$ \lim_{\sigma \rightarrow \sigma_a} \alpha(\sigma) \rightarrow 0 \\ \lim_{\sigma \rightarrow \sigma_c} \alpha(\sigma) \rightarrow 1 \\ \forall \sigma: \sigma_a < \sigma < \sigma_c \implies \alpha(\sigma_a) < \alpha(\sigma) < \alpha(\sigma_c) $$

which should be rather easy.

There maybe errors but at least it seems possible to find it.