Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
sarus-llm / sarus_llm / privacy.py
Size: Mime:
import typing as t
import warnings

try:
    import dp_accounting
except ModuleNotFoundError:
    warnings.warn("Dp accounting missing")
import numpy as np


def compute_epsilon(
    steps: int,
    noise_multiplier: float,
    batch_size: int,
    dataset_size: int,
    target_delta: float = 1e-5,
) -> float:
    if dataset_size * target_delta > 1.0:
        warnings.warn("Your delta might be too high.")
    q = batch_size / float(dataset_size)
    orders = list(np.linspace(1.1, 10.9, 100)) + list(range(11, 250))
    accountant = dp_accounting.rdp.RdpAccountant(orders)
    accountant.compose(
        dp_accounting.PoissonSampledDpEvent(
            q, dp_accounting.GaussianDpEvent(noise_multiplier)
        ),
        steps,
    )
    return t.cast(float, accountant.get_epsilon(target_delta))