Skip to main content

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, or BOTH) with explicit upper/lower bound semantics.
  • FFT convolution for linearly spaced grids.
  • GEOM convolution for geometrically spaced positive grids.
  • Subsampling amplification directly on PLD representations.
  • Interop helpers for dp_accounting PMF 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 a dp_accounting PrivacyLossDistribution.
  • numerical_allocation_epsilon(params, config, direction, bound_type): computes epsilon for params.delta.
  • numerical_allocation_delta(params, config, direction, bound_type): computes delta for params.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

  • sigma must be positive and finite.
  • tail_truncation must be in (0, 1).
  • loss_discretization controls the accuracy/runtime tradeoff; smaller values are tighter but slower and larger-memory.
  • max_grid_FFT and max_grid_mult cap grid sizes; too-small budgets can invalidate a run.
  • bound_type=DOMINATES is pessimistic (upper bound), IS_DOMINATED is optimistic (lower bound).
  • Adaptive queries treat any negative target_accuracy as a convenience default:
    • epsilon query: target_accuracy = 0.01 * Poisson-estimated epsilon
    • delta query: target_accuracy = 0.01 * Poisson-estimated delta
  • Adaptive initialization now starts from a Poisson-subsampled Gaussian guess with:
    • sampling probability num_selected / num_steps
    • composition count num_selected * num_epochs

Running Tests

From repository root:

pytest -q

With coverage:

./tests/run_tests.sh --coverage

Build a wheel/sdist:

python -m build

Examples

  • usage_example.py includes direct epsilon queries.
  • usage_example.py includes PLD construction and repeated epsilon lookups.
  • usage_example.py includes adaptive random-allocation queries through PLD_accounting.random_allocation_api.
  • usage_example.py includes 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

pld_accounting-0.1.0.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pld_accounting-0.1.0-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

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

Hashes for pld_accounting-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6af427d7bc7e99b74c4ffada1591ec96837435cb5d93cc229f4f93faca5ed36b
MD5 adf3287f42617aaf3b27dc4a77a0663c
BLAKE2b-256 9edf9bd9d82f972ad9c8735f2a4f874d76cef567e0f73a6278b4cf524e4f3c6c

See more details on using hashes here.

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

Hashes for pld_accounting-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6259b4fe061f1344307dbee1dc3f1fb7b1e7326d23f420288040c4eb4bd728a6
MD5 b0996ef581a0b1523db81abd7270ca2f
BLAKE2b-256 7dab2a5f1f9687785940e00d47298a2b6b58f405cfb195be223bcc6c2e74b974

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page