This documentation is for an old version of OpenDP.

The current release of OpenDP is v0.11.1.

Source code for opendp.accuracy

# Auto-generated. Do not edit.
from opendp._convert import *
from opendp._lib import *
from opendp.mod import *
from opendp.typing import *

__all__ = [
    "laplacian_scale_to_accuracy",
    "accuracy_to_laplacian_scale",
    "gaussian_scale_to_accuracy",
    "accuracy_to_gaussian_scale"
]


[docs] def laplacian_scale_to_accuracy( scale, alpha, T: RuntimeTypeDescriptor = None ) -> Any: """Convert a laplacian scale into an accuracy estimate. :param scale: Laplacian noise scale. :param alpha: Statistical significance, level-alpha, or (1. - alpha)100% confidence. Must be within (0, 1]. :param T: Data type of scale and alpha :type T: RuntimeTypeDescriptor :return: Accuracy estimate at a level-alpha. :rtype: Any :raises AssertionError: if an argument's type differs from the expected type :raises UnknownTypeError: if a type-argument fails to parse :raises OpenDPException: packaged error from the core OpenDP library """ # Standardize type arguments. T = RuntimeType.parse_or_infer(type_name=T, public_example=scale) # Convert arguments to c types. scale = py_to_c(scale, c_type=ctypes.c_void_p, type_name=T) alpha = py_to_c(alpha, c_type=ctypes.c_void_p, type_name=T) T = py_to_c(T, c_type=ctypes.c_char_p) # Call library function. function = lib.opendp_accuracy__laplacian_scale_to_accuracy function.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p] function.restype = FfiResult return c_to_py(unwrap(function(scale, alpha, T), AnyObjectPtr))
[docs] def accuracy_to_laplacian_scale( accuracy, alpha, T: RuntimeTypeDescriptor = None ) -> Any: """Convert a desired accuracy into a laplacian noise scale. :param accuracy: Desired accuracy. :param alpha: Statistical significance, level-alpha, or (1. - alpha)100% confidence. Must be within (0, 1). :param T: Data type of accuracy and alpha :type T: RuntimeTypeDescriptor :return: Laplacian noise scale that meets the accuracy requirement at a level-alpha. :rtype: Any :raises AssertionError: if an argument's type differs from the expected type :raises UnknownTypeError: if a type-argument fails to parse :raises OpenDPException: packaged error from the core OpenDP library """ # Standardize type arguments. T = RuntimeType.parse_or_infer(type_name=T, public_example=accuracy) # Convert arguments to c types. accuracy = py_to_c(accuracy, c_type=ctypes.c_void_p, type_name=T) alpha = py_to_c(alpha, c_type=ctypes.c_void_p, type_name=T) T = py_to_c(T, c_type=ctypes.c_char_p) # Call library function. function = lib.opendp_accuracy__accuracy_to_laplacian_scale function.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p] function.restype = FfiResult return c_to_py(unwrap(function(accuracy, alpha, T), AnyObjectPtr))
[docs] def gaussian_scale_to_accuracy( scale, alpha, T: RuntimeTypeDescriptor = None ) -> Any: """Convert a gaussian scale into an accuracy estimate. :param scale: Gaussian noise scale. :param alpha: Statistical significance, level-alpha, or (1. - alpha)100% confidence. Must be within (0, 1]. :param T: Data type of scale and alpha :type T: RuntimeTypeDescriptor :return: Accuracy estimate at a level-alpha. :rtype: Any :raises AssertionError: if an argument's type differs from the expected type :raises UnknownTypeError: if a type-argument fails to parse :raises OpenDPException: packaged error from the core OpenDP library """ # Standardize type arguments. T = RuntimeType.parse_or_infer(type_name=T, public_example=scale) # Convert arguments to c types. scale = py_to_c(scale, c_type=ctypes.c_void_p, type_name=T) alpha = py_to_c(alpha, c_type=ctypes.c_void_p, type_name=T) T = py_to_c(T, c_type=ctypes.c_char_p) # Call library function. function = lib.opendp_accuracy__gaussian_scale_to_accuracy function.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p] function.restype = FfiResult return c_to_py(unwrap(function(scale, alpha, T), AnyObjectPtr))
[docs] def accuracy_to_gaussian_scale( accuracy, alpha, T: RuntimeTypeDescriptor = None ) -> Any: """Convert a desired accuracy into a gaussian noise scale. :param accuracy: Desired accuracy. :param alpha: Statistical significance, level-alpha, or (1. - alpha)100% confidence. Must be within (0, 1). :param T: Data type of accuracy and alpha :type T: RuntimeTypeDescriptor :return: Gaussian noise scale that meets the accuracy requirement at a level-alpha. :rtype: Any :raises AssertionError: if an argument's type differs from the expected type :raises UnknownTypeError: if a type-argument fails to parse :raises OpenDPException: packaged error from the core OpenDP library """ # Standardize type arguments. T = RuntimeType.parse_or_infer(type_name=T, public_example=accuracy) # Convert arguments to c types. accuracy = py_to_c(accuracy, c_type=ctypes.c_void_p, type_name=T) alpha = py_to_c(alpha, c_type=ctypes.c_void_p, type_name=T) T = py_to_c(T, c_type=ctypes.c_char_p) # Call library function. function = lib.opendp_accuracy__accuracy_to_gaussian_scale function.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p] function.restype = FfiResult return c_to_py(unwrap(function(accuracy, alpha, T), AnyObjectPtr))