mpcrl.util.geometry.ConvexPolytopeUniformSampler#
- class mpcrl.util.geometry.ConvexPolytopeUniformSampler(vertices, incremental=False, disable_triangulation=False, disable_convex_hull=False, seed=None)[source]#
Bases:
objectDraws samples uniformly at random from a convex polytopic region (samples from its interior and surface are possible to obtain).
Under the hood, the convex hull and triangulation of the given polytope are performed (see
scipy.spatial.ConvexHullandscipy.spatial.Delaunay). To sample uniformly from the interior, for each sample a triangulation simplex is selected with probability proportional to its volume, and a point is drawn uniformly from that simplex via a Dirichlet distribution. Likewise, to sample from its surface, a facet is instead selected at random with probability proportional to its surface.- Parameters:
- verticesarray-like of shape (n, d)
The vertices of the polytope, where
nis the number of vertices anddis the dimension of the space.- incrementalbool, optional
Allows adding new points incrementally to the convex hull and triangulation. This takes up some additional resources.
- disable_triangulationbool, optional
Whether to disable the triangulation. This is useful when only surface samples are desired. By default,
False.- disable_convex_hullbool, optional
Whether to disable the convex hull computation. This is useful when only interior samples are desired. By default,
False.- seedint, sequence of int, seed or
numpy.random.Generator, optional The seed or random number generator to use for sampling.
Methods
add_points(points[, restart])Processes a set of additional new points.
close()Finishes the incremental processing.
sample_from_interior([size])Sample uniformly from the interior of the polytope defined by the given vertices.
sample_from_surface([size])Sample uniformly from the surface of the polytope defined by the given vertices.
seed([seed])Resets the RNG engine.
- add_points(points, restart=False)[source]#
Processes a set of additional new points. See also
scipy.spatial.Delaunay.add_points.- Parameters:
- verticesarray-like of shape (n, d)
New points to add, where
nis the number of new points anddis the dimension of the space.- restartbool, optional
Whether to restart processing from scratch, rather than adding points incrementally.
- Return type:
- sample_from_interior(size=())[source]#
Sample uniformly from the interior of the polytope defined by the given vertices.
- Parameters:
- sizeint or tuple of ints, optional
The size of the sample array to draw. By default, one sample is drawn.
- Returns:
- array of shape (size1, size2, …, d)
The samples drawn from the polytope.
- Raises:
- RuntimeError
Raised if the triangulation is disabled.
- Return type:
- sample_from_surface(size=())[source]#
Sample uniformly from the surface of the polytope defined by the given vertices.
- Parameters:
- sizeint or tuple of ints, optional
The size of the sample array to draw. By default, one sample is drawn.
- Returns:
- array of shape (size1, size2, …, d)
The samples drawn from the polytope.
- Raises:
- RuntimeError
Raised if the convex hull is disabled.
- Return type:
- seed(seed=None)[source]#
Resets the RNG engine.
- Parameters:
- seeedint, sequence of int, seed or
numpy.random.Generator, optional The seed or random number generator to use for sampling.
- seeedint, sequence of int, seed or
- Returns:
- array of shape (size1, size2, …, d)
The samples drawn from the simplex.
- Raises:
- ValueError
Raised if the vertices are not
d+1in number.
- Return type: