pycvxset.common

The following functions are few additional methods provided with pycvxset that may be useful to the user.

pycvxset.common.approximate_volume_from_grid(...)

Estimate area of a two-dimensional set using a grid of given step size

pycvxset.common.is_constrained_zonotope(Q)

Check if the set is a constrained zonotope

pycvxset.common.is_ellipsoid(Q)

Check if the set is an ellipsoid

pycvxset.common.is_polytope(Q)

Check if the set is a polytope

pycvxset.common.prune_and_round_vertices(V)

Filter through the vertices to skip any point that has another point (down in the list) that is close to it in the list.

pycvxset.common.spread_points_on_a_unit_sphere(n_dim)

Spread points on a unit sphere in n-dimensional space.

pycvxset.common.approximate_volume_from_grid(set_to_compute_area_for, area_grid_step_size)[source]

Estimate area of a two-dimensional set using a grid of given step size

Parameters:
  • set_to_compute_area_for (Polytope | ConstrainedZonotope | Ellipsoid) – Set for which area is to be computed

  • area_grid_step_size (float) – Scalar step size that is constant in both dimensions

Raises:

ValueError – When set is not 2-dimensional

Returns:

Approximate area of the set

Return type:

float

Notes

This function creates a 2D grid of points with a given step size, and computes the fraction of points that lie in the set. Consequently, the computed area is an approximation of the actual area of the set. The area of the bounding box is computed using the minimum_volume_circumscribing_rectangle() method associated with the set.

pycvxset.common.is_constrained_zonotope(Q)[source]

Check if the set is a constrained zonotope

Parameters:

Q (object) – Set to check

Returns:

Returns True if the set is a constrained zonotope, False otherwise

Return type:

bool

pycvxset.common.is_ellipsoid(Q)[source]

Check if the set is an ellipsoid

Parameters:

Q (object) – Set to check

Returns:

Returns True if the set is an ellipsoid, False otherwise

Return type:

bool

pycvxset.common.is_polytope(Q)[source]

Check if the set is a polytope

Parameters:

Q (object) – Set to check

Returns:

Returns True if the set is a polytope, False otherwise

Return type:

bool

pycvxset.common.prune_and_round_vertices(V, decimal_precision=3)[source]

Filter through the vertices to skip any point that has another point (down in the list) that is close to it in the list.

Parameters:
  • V (array_like) – Matrix of vertices (N times self.dim)

  • decimal_precision (int, optional) – The decimal precision for rounding the vertices. Defaults to PLOTTING_DECIMAL_PRECISION_CDD from pycvxset.common.constants.

Returns:

The pruned and rounded array of vertices.

Return type:

numpy.ndarray

pycvxset.common.spread_points_on_a_unit_sphere(n_dim, n_points=None, cvxpy_socp_args=None, verbose=False)[source]

Spread points on a unit sphere in n-dimensional space.

Parameters:
  • n_dim (int) – The dimension of the sphere.

  • n_points (int) – The number of points to be spread on the unit sphere. Defaults to None, in which case, we choose

  • = (n_points)

  • cvxpy_socp_args (dict) – Additional arguments to be passed to the CVXPY solver. Defaults to None, in which case the function uses DEFAULT_CVXPY_ARGS_SOCP from pycvxset.common.constants.

  • verbose (bool, optional) – Whether to print verbose output. Defaults to False.

Returns:

A tuple containing three items:

# opt_locations (ndarray): The spread points on the unit sphere. # minimum_separation (float): The minimum separation between the points. # opt_locations_first_quad (ndarray): The spread points in the first quadrant.

Return type:

tuple

Raises:
  • ValueError – If n_points is less than 2 * n_dim.

  • UserWarning – If n_points - 2 * n_dim is not a multiple of 2^n_dim.

  • NotImplementedError – Unable to solve the convexified problem using CVXPY

  • NotImplementedError – Convex-concave procedure did not converge!

Notes

This function uses the CVXPY library to solve a convex optimization problem to spread the points on the unit sphere. The spread points are returned as opt_locations, the separation between the points is returned as separation, and the spread points in the first quadrant are returned as opt_locations_first_quad.

For n_dim in [1, 2], the points are available in closed-form. For n_dim >= 3, we solve the following non-convex optimization problem using convex-concave procedure:

\[\begin{split}\begin{array}{rlrl} \text{maximize} &\quad R \\ \text{subject to} &\quad R \geq 0\\ &\quad x \geq R/2\\ &\quad \|x_i - x_j\| \geq R, && 1 \leq i < j \leq n_\text{points}\\ &\quad \|x_i - e_j\| \geq R, && 1 \leq i \leq n_\text{points}, 1 \leq j \leq n_\text{dim}\\ &\quad \|x_i \| \leq 1, && 1 \leq i \leq n_\text{points}\\ &\quad \|x_i \| \geq 0.8, && 1 \leq i \leq n_\text{points}\\ \end{array}\end{split}\]

The optimization problem seeks to spread points (apart from the standard axes) in the first quadrant so that their pairwise separation is maximized, while they have a norm close to 1. The second constraint is motivated to ensure that the reflections of the points about the quadrant plane is also separated by R.