wmpy.sampling.rejection.RejectionSampler

class RejectionSampler(polytope, polynomial, seed=None)[source]

Bases: object

This class implements rejection sampling from a polynomial distribution with convex support.

Default constructor.

Parameters:
  • polytope (Polytope) – convex integration bounds

  • polynomial (Polynomial) – the target distribution

  • seed (Optional[int]) – the seed number (optional)

Methods

sample

Draws a sample from a N-dimensional convex polytope using two-phases rejection.

sample(n_samples, max_iterations=1)[source]

Draws a sample from a N-dimensional convex polytope using two-phases rejection.

Initially, samples are uniformly sampled in the enclosing axis-aligned bounding box of the polytope. The first rejection phase discards points that are outside the polytope. Then, the second rejection phase ensures that samples are drawn from the target polynomial distribution.

The procedure tries to sample n_samples points up to max_iterations, returning M <= n_samples points.

Parameters:
  • n_samples (int) – desired sample size

  • max_iterations (int) – maximum number of attempts (default: 1)

Return type:

ndarray

Returns:

A numpy array with shape (M, N).