WeightedBoxProjection#
- class WeightedBoxProjection(lb, ub, weights, relaxation=1, idx=None, proximity_flag=True, use_gpu=False)[source]#
Bases:
BasicProjectionWeightedBoxProjection applies a weighted projection on a box defined by lower and upper bounds. The idea is a “simultaneous” variant to the “sequential” BoxProjection.
- Parameters:
lb (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Lower bounds of the box.ub (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Upper bounds of the box.weights (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Weights for the projection.relaxation (
float) – 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 if proximity should be calculated, by default True.
use_gpu (bool, optional) – Flag to indicate if GPU should be used, by default False.
- Attributes:
- lbnpt.NDArray
Lower bounds of the box.
- ubnpt.NDArray
Upper bounds of the box.
- relaxationfloat
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 the coordinates for the edges of a box if it is 2D.
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])Visualize the box if it is 2D on a given matplotlib Axes.
- get_xy()[source]#
Generate the coordinates for the edges of a box if it is 2D.
This method creates four edges of a 2D box defined by the lower bounds (lb) and upper bounds (ub). The edges are generated using 100 points each.
- Returns:
A 2D array of shape (2, 400) containing the concatenated coordinates of the four edges.
- Raises:
ValueError – If the box 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, color=None)[source]#
Visualize the box 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 box will be filled with the default color.
- Raises:
ValueError – If the box is not 2-dimensional.