Numerical privacy accounting for random allocation and subsampling using PLDs.
Project description
PLD_accounting
Numerical privacy accounting for random allocation and subsampling using Privacy Loss Distributions (PLDs).
What This Repository Provides
- End-to-end numerical accounting for random allocation privacy guarantees.
- Direction-aware accounting (
REMOVE,ADD, orBOTH) with explicit upper/lower bound semantics. FFTconvolution for linearly spaced grids.GEOMconvolution for geometrically spaced positive grids.- Subsampling amplification directly on PLD representations.
- Interop helpers for
dp_accountingPMF objects.
Repository Structure
PLD_accounting/: core library code (types, discretization, convolution, accounting, subsampling).tests/: unit and integration tests.usage_example.py: executable usage examples for common workflows.
Installation
From PyPI (Recommended)
pip install PLD_accounting
From Source
Clone the repository and install:
git clone https://github.com/moshenfeld/PLD_accounting.git
cd PLD_accounting
pip install .
Development Installation
For local development with editable installation:
pip install -e .
Install with test extras:
pip install -e ".[test]"
Install with development dependencies:
pip install ".[dev]"
Requirements
- Python >= 3.10
- numpy >= 1.23
- scipy >= 1.10
- numba >= 0.58
- dp-accounting >= 0.4.3
All dependencies are automatically installed with the package.
Quick Start
from PLD_accounting import (
PrivacyParams,
AllocationSchemeConfig,
Direction,
BoundType,
numerical_allocation_epsilon,
)
params = PrivacyParams(
sigma=1.0,
num_steps=1000,
num_selected=10,
num_epochs=1,
delta=1e-6,
)
config = AllocationSchemeConfig(
loss_discretization=0.02,
tail_truncation=1e-8,
max_grid_FFT=1_000_000,
)
eps = numerical_allocation_epsilon(
params=params,
config=config,
direction=Direction.BOTH,
bound_type=BoundType.DOMINATES,
)
print(eps)
Direct import from the dedicated random-allocation API module:
from PLD_accounting.random_allocation_api import (
allocation_PLD,
numerical_allocation_epsilon_range,
numerical_allocation_epsilon,
)
from PLD_accounting.types import AllocationSchemeConfig, BoundType, Direction, PrivacyParams
params = PrivacyParams(
sigma=3.0,
num_steps=200,
num_selected=10,
delta=1e-6,
)
config = AllocationSchemeConfig(
loss_discretization=0.05,
tail_truncation=1e-7,
)
eps = numerical_allocation_epsilon(
params=params,
config=config,
direction=Direction.BOTH,
bound_type=BoundType.DOMINATES,
)
pld = allocation_PLD(
params=params,
config=config,
direction=Direction.BOTH,
bound_type=BoundType.DOMINATES,
)
epsilon_upper, epsilon_lower = numerical_allocation_epsilon_range(
sigma=3.0,
num_steps=200,
delta=1e-6,
num_selected=10,
epsilon_accuracy=-1, # any negative value resolves to 1% of the Poisson guess
)
print(epsilon_upper, epsilon_lower)
Main API
allocation_PLD(params, config, direction, bound_type): returns adp_accountingPrivacyLossDistribution.numerical_allocation_epsilon(params, config, direction, bound_type): computesepsilonforparams.delta.numerical_allocation_delta(params, config, direction, bound_type): computesdeltaforparams.epsilon.numerical_allocation_epsilon_range(sigma, num_steps, delta, ...): adaptively refines resolution and returns(upper_bound, lower_bound)for epsilon.numerical_allocation_delta_range(sigma, num_steps, epsilon, ...): adaptively refines resolution and returns(upper_bound, lower_bound)for delta.subsample_PLD(pld, sampling_probability, bound_type): applies subsampling amplification to an existing PLD.
Important Parameter Notes
sigmamust be positive and finite.tail_truncationmust be in(0, 1).loss_discretizationcontrols the accuracy/runtime tradeoff; smaller values are tighter but slower and larger-memory.max_grid_FFTandmax_grid_multcap grid sizes; too-small budgets can invalidate a run.bound_type=DOMINATESis pessimistic (upper bound),IS_DOMINATEDis optimistic (lower bound).- Adaptive queries treat any negative
target_accuracyas a convenience default:- epsilon query:
target_accuracy = 0.01 *Poisson-estimated epsilon - delta query:
target_accuracy = 0.01 *Poisson-estimated delta
- epsilon query:
- Adaptive initialization now starts from a Poisson-subsampled Gaussian guess with:
- sampling probability
num_selected / num_steps - composition count
num_selected * num_epochs
- sampling probability
Running Tests
From repository root:
pytest -q
With coverage:
./tests/run_tests.sh --coverage
Build a wheel/sdist:
python -m build
Examples
usage_example.pyincludes direct epsilon queries.usage_example.pyincludes PLD construction and repeated epsilon lookups.usage_example.pyincludes adaptive random-allocation queries throughPLD_accounting.random_allocation_api.usage_example.pyincludes a subsampling + composition workflow.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pld_accounting-0.1.0.tar.gz.
File metadata
- Download URL: pld_accounting-0.1.0.tar.gz
- Upload date:
- Size: 31.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6af427d7bc7e99b74c4ffada1591ec96837435cb5d93cc229f4f93faca5ed36b
|
|
| MD5 |
adf3287f42617aaf3b27dc4a77a0663c
|
|
| BLAKE2b-256 |
9edf9bd9d82f972ad9c8735f2a4f874d76cef567e0f73a6278b4cf524e4f3c6c
|
File details
Details for the file pld_accounting-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pld_accounting-0.1.0-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6259b4fe061f1344307dbee1dc3f1fb7b1e7326d23f420288040c4eb4bd728a6
|
|
| MD5 |
b0996ef581a0b1523db81abd7270ca2f
|
|
| BLAKE2b-256 |
7dab2a5f1f9687785940e00d47298a2b6b58f405cfb195be223bcc6c2e74b974
|