A python Library for Deterministic sampling based on Projected Cumulative Distribution
Original paper: https://ieeexplore.ieee.org/abstract/document/9086228
If you wish to use the lib in your project, run: uv add git+https://github.com/KIT-ISAS/PCD_sampling_py.git
To run the tests, simply install test dependencies:
uv sync --extra testand then run the tests with:
uv run pytestIn order to use PCD sampling in your project you must:
- Create an iunstance of config data object
- Create an instance of sampling PCD class with config injected.
- Create a Gaussian Mixture to sample from.
- Use sample method on the class to get the samples from the GM.
torch.manual_seed(42) # for reproducibility
# Create a Gaussian mixture parameters
weights=torch.tensor([0.5, 0.5])
means=torch.tensor([[0.0, 0.0], [0.0, 0.0]])
covariances=torch.tensor([[[3.0, 2.8], [2.8, 3.0]], [[3.0, -2.8], [-2.8, 3.0]]])
sampling_config = PCDSamplingConfig(number_samples=40, dim=2, number_unit_vectors=100, threshold=0.0001, steps=100, sorting=True) # Create a config
sampler = PCDSamplingStrategy(sampling_config) # Inject config into the sampling class
samples = sampler.sample(weighs, means, covariances) # SampleWhen you first call sample pytorch compiles it, which takes relatively long time. So it is advised to warm up first by sampling a dummy GM.