BandProjection#
- class BandProjection(a, lb, ub, relaxation=1, idx=None, proximity_flag=True, use_gpu=False)[source]#
Bases:
BasicProjectionA class used to represent a projection onto a band.
- Parameters:
a (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal vector defining the halfspace.lb (
float) – The lower bound of the band.ub (
float) – The upper bound of the band.idx (npt.NDArray or None) – Subset of the input vector to apply the projection on.
relaxation (
float) – The relaxation parameter, by default 1.idx – Subset of the input vector to apply the projection on.
- Attributes:
- anpt.NDArray
The normal vector defining the halfspace.
- a_normnpt.NDArray
The normalized normal vector.
- lbfloat
The lower bound of the band.
- ubfloat
The upper bound of the band.
- relaxationfloat
The relaxation parameter for the projection.
- proximity_flagbool
Flag to indicate whether to take this object into account when calculating proximity.
- idxnpt.NDArray
Subset of the input vector to apply the projection on.
Methods
get_xy([x])Calculate the x and y coordinates for the lower and upper bounds of a 2D band.
project(x)Perform the (possibly relaxed) projection of input array 'x' onto the constraint.
proximity(x, proximity_measures)Calculate proximity measures of point x to the set.
step(x)Perform the (possibly relaxed) projection of input array 'x' onto the constraint.
visualize([ax, x, color])Visualize the band if it is 2D on a given matplotlib Axes.
- get_xy(x=None)[source]#
Calculate the x and y coordinates for the lower and upper bounds of a 2D band.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None) – The x-coordinates at which to evaluate the bounds. If None, a default range from -10 to 10 with 100 points is used.- Returns:
A tuple containing two numpy arrays: - The first array represents the x and y coordinates for the lower bound. - The second array represents the x and y coordinates for the upper bound.
- Raises:
ValueError – If the band is not 2-dimensional.
- project(x)#
Perform the (possibly relaxed) projection of input array ‘x’ onto the constraint.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The input array to be projected.- Return type:
ndarray- Returns:
The (possibly relaxed) projection of ‘x’ onto the constraint.
- proximity(x, proximity_measures)#
Calculate proximity measures of point x to the set.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Input array for which the proximity measure is to be calculated.- Return type:
float- Returns:
The proximity measures of the input array x.
- step(x)#
Perform the (possibly relaxed) projection of input array ‘x’ onto the constraint.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The input array to be projected.- Return type:
ndarray- Returns:
The (possibly relaxed) projection of ‘x’ onto the constraint.
- visualize(ax=None, x=None, color=None)[source]#
Visualize the band if it is 2D on a given matplotlib Axes.
- Parameters:
ax (
Axes|None) – The matplotlib Axes to plot on. If None, a new figure and axes are created.color (str or None, optional) – The color to fill the box with. If None, the band will be filled with the default color.
- Raises:
ValueError – If the band is not 2-dimensional.