HalfspaceProjection#
- class HalfspaceProjection(a, b, relaxation=1, idx=None, proximity_flag=True, use_gpu=False)[source]#
Bases:
BasicProjectionA class used to represent a projection onto a halfspace.
- Parameters:
a (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The normal vector defining the halfspace.b (
float) – The offset value defining the halfspace.relaxation (
float) – The relaxation parameter, by default 1.idx (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None) – Subset of the input vector to apply the projection on.proximity_flag (bool, optional) – Flag to indicate whether to take this object into account when calculating proximity, by default True.
use_gpu (bool, optional) – Flag to indicate if GPU should be used, by default False.
- Attributes:
- anpt.NDArray
The normal vector defining the halfspace.
- a_normnpt.NDArray
The normalized normal vector.
- bfloat
The offset value defining the halfspace.
- 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])Generate x and y coordinates for visualization of 2D halfspaces.
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, y_fill, color])Visualize the halfspace if it is 2D on a given matplotlib Axes.
- get_xy(x=None)[source]#
Generate x and y coordinates for visualization of 2D halfspaces.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None) – The x-coordinates for which to compute the corresponding y-coordinates. If None, a default range of x values from -10 to 10 is used.- Returns:
A 2D array where the first row contains the x-coordinates and the second row contains the corresponding y-coordinates.
- Raises:
ValueError – If the halfspace 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, y_fill=None, color=None)[source]#
Visualize the halfspace 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 halfspace will be filled with the default color.
- Raises:
ValueError – If the halfspace is not 2-dimensional.