BallProjection#
- class BallProjection(center, radius, relaxation=1, idx=None, proximity_flag=True, use_gpu=False)[source]#
Bases:
BasicProjectionA class used to represent a projection onto a ball.
- Parameters:
center (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The center of the ball.radius (
float) – The radius of the ball.relaxation (
float) – The relaxation parameter (default is 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:
- centernpt.NDArray
The center of the ball.
- radiusfloat
The radius of the ball.
- 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()Generate x and y coordinates for a 2D ball visualization.
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, color, edgecolor])Visualize the halfspace if it is 2D on a given matplotlib Axes.
- get_xy()[source]#
Generate x and y coordinates for a 2D ball visualization.
- Returns:
A 2x50 array where the first row contains the x coordinates and the second row contains the y coordinates of the points on the circumference of the 2D ball.
- Raises:
ValueError – If the center does not have exactly 2 dimensions.
- 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, color=None, edgecolor=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.