Function with simple formula that looks like cubic Bezier curve

424 Views Asked by At

I need a function that I can to evaluate it at arbitrary values of x. I want to control the shape of that function by two endpoints and two directions. A simple cubic polynomial fits that requirement, but is significantly more "rigid" than a 2D Cubic Bezier curve.

2D cubic Bezier curve is a parametric curve described by two cubic polynomials: $$x(t) = X_0*(1-t)^3 + X_1*3t(1-t)^2 + X_2*3t^2(1-t) + X_3*t^3$$ $$y(t) = Y_0*(1-t)^3 + Y_1*3t(1-t)^2 + Y_2*3t^2(1-t) + Y_3*t^3$$

If $X_0 \le X_1 \le X_2 \le X_3$ (and not $X_0 = X_1 = X_2$ or $X_1 = X_2 = X_3$) then the curve is a function $y(x)$.

However the symbolical formula for $y(x)$ is big and hard to use due to $t(x)$ being a solution to a cubic equation.

I want to find a function with simple representation such that it's graph is similar to the 2D cubic bezier graph. The function should be mainly parametrized by two endpoints ($X_0$, $Y_0$, $X_3$, $Y_3$) and two "directions" ($X_1 - X_0$, $Y_1 - Y_0$, $X_3 - X_2$, $Y_3 - Y_2$). It's OK to have some additional parameter if necessary.

Some Bezier properties that I like:

  • "Monotonicity" - Does not introduce as much extra local minima as Fourier or high-order polynomial approximations
  • The range of Y values between endpoints is easily bounded: $min(Y_i) \le min(y(x)) \le max(y(x)) \le max(Y_i)$
  • Infinite derivatives are possible at end points

Use case: I want to use a parametrized function $f(x)$ to approximate some regions of other functions ($tanh$, $exp(x)$, $log(x)$, $max(0, exp(x))$, $1/x$, $max(0, x)$, etc) with continuous transformation between them. This is needed to represent trainable neural network activation functions.

2

There are 2 best solutions below

0
On

I wrote a smooth transition between linear functions in a previous answer that you could use https://math.stackexchange.com/q/2496273 . It is simply a cubic polynomial.

That said, Bezier curves have the property that they are stable with respect to affine transformation, which means that the transform of a Bezier curve is the Bezier curve of the transforms of the control points. This property will most likely not be available for "simpler" curves.

8
On

What you're asking about is just classical approximation of real-valued functions. There are decades of research devoted to this problem. You can start learning here.

For software that does this for you, a good choice is the Chebfun system. It does a very good job of approximating pretty much any continuous functions using polynomial or rational functions.

To approximate special functions like the ones you listed, people often use the CORDIC algorithms.