Function cont_constraint (o2scl)¶
-
inline double o2scl::cont_constraint(double x, double center, double width, double height, double tightness = 40.0, double exp_arg_limit = 50.0)¶
Constrain
xto be withinwidthof the value given bycenter.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
xfromcenter, this scales quadratically. If you are trying to constrain a function which decreases faster than quadratically by makingxfar fromcenter, 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 \).