Function cont_constraint (o2scl)

O2scl : Function List

inline double o2scl::cont_constraint(double x, double center, double width, double height, double tightness = 40.0, double exp_arg_limit = 50.0)

Constrain x to be within width of the value given by center.

Defining \( c= \) center, \( w= \) width, \( h= \) height, \( t= \) tightness, and \( \ell= \) exp_arg_limit, this returns the value

\[ h \left(\frac{x-c}{w}\right)^2 \left[ 1+ e^{t\left(x-c+w\right)\left(c+w-x\right)/w^2} \right]^{-1} \]

This function is continuous and differentiable. Note that if \( x=c \) , then the function returns zero.

The exponential is handled gracefully by assuming that anything smaller than \( \exp(-\ell) \) is zero. This creates a small discontinuity which can be removed with the sufficiently large value of \( \ell \).

It is important to note that, for large distances of x from center, this scales quadratically. If you are trying to constrain a function which decreases faster than quadratically by making x far from center, then a minimizer may ignore this constraint.

In the limit \( t \rightarrow \infty \), this function converges towards the squared value of constraint(), except exactly at the points \( x=c-w \) and \( x=c+w \).