spapros.ut.plateau_penalty_kernel
- spapros.ut.plateau_penalty_kernel(var, x_min=None, x_max=None)
Return penalty function.
The kernel can be one or two sided (one-sided if either
x_min
orx_max
is None). The kernel is 1 betweenx_min
andx_max
. If one-sided it’s 1 fromx_min
or tillx_max
. Outside the defined range the kernal decays with a gaussian function with variance =var
.- Parameters:
var (Union[float, List[float]]) – Outside the defined range, the kernel decays with a gaussian function with variance =
var
.x_min (Optional[ndarray]) – Lower border above which the kernel is 1.
x_max (Optional[ndarray]) – Upper border below which the kernel is 1.
- Returns:
Penalty function.
- Return type:
Callable
Example
import numpy as np import matplotlib.pyplot as plt import spapros as sp penalty_fcts = { "left" : sp.ut.plateau_penalty_kernel(var=0.5, x_min=2, x_max=None), "right" : sp.ut.plateau_penalty_kernel(var=2, x_min=None, x_max=5), "dual" : sp.ut.plateau_penalty_kernel(var=[0.5,2], x_min=2, x_max=5), } x = np.linspace(0,10,100) _, axs = plt.subplots(nrows=1,ncols=3,figsize=(10,2)) for i, (title, penalty_fct) in enumerate(penalty_fcts.items()): axs[i].plot(x,penalty_fct(x)) axs[i].set_title(title) plt.show()