diffprivlib.mechanisms.transforms

Transform wrappers for differential privacy mechanisms to extend their use to alternative data types.

Notes

The naming convention for new transforms is to describe the pre-transform action, i.e. the action performed on the data to be ingested by the mechanism. For transforms without a pre-transform, the post-transform action should be described.

Base class

class diffprivlib.mechanisms.transforms.DPTransformer(parent)[source]

Base class for DP transformers. DP Transformers are simple wrappers for DP Mechanisms to allow mechanisms to be used with data types and structures outside their scope.

A DPTransformer must be initiated with a DPMachine (either another DPTransformer, or a DPMechanism). This allows many instances of DPTransformer to be chained together, but the chain must terminate with a DPMechanism.

copy()

Produces a copy of the class.

Returns:

self – Returns the copy.

Return type:

class

post_transform(value)[source]

Performs no transformation on the output of the mechanism, and is returned as-is.

Parameters:

value (float or string) – Mechanism output to be transformed.

Returns:

Transformed output value.

Return type:

float or string

pre_transform(value)[source]

Performs no transformation on the input data, and is ingested by the mechanism as-is.

Parameters:

value (float or string) – Input value to be transformed.

Returns:

Transformed input value

Return type:

float or string

randomise(value)[source]

Randomise the given value using the DPMachine.

Parameters:

value (float or string) – Value to be randomised.

Returns:

Randomised value, same type as value.

Return type:

float or string

Type casting transforms

class diffprivlib.mechanisms.transforms.IntToString(parent)[source]

IntToString DP transformer, for using integer-valued data with string-valued mechanisms.

Useful when using integer-valued data with Binary or Exponential.

post_transform(value)[source]

Transforms the output of the mechanism to be integer-valued.

Parameters:

value (float or string) – Mechanism output to be transformed.

Returns:

Transformed output value.

Return type:

int

pre_transform(value)[source]

Transforms the input to be string-valued for ingestion by the mechanism.

Parameters:

value (float or string) – Input value to be transformed.

Returns:

Transformed input value

Return type:

string

randomise(value)

Randomise the given value using the DPMachine.

Parameters:

value (float or string) – Value to be randomised.

Returns:

Randomised value, same type as value.

Return type:

float or string

class diffprivlib.mechanisms.transforms.StringToInt(parent)[source]

StringToInt DP transformer, for using string-valued data with integer-valued mechanisms.

Useful when using ordered, string-valued data with Geometric.

post_transform(value)[source]

Transforms the output of the mechanism to be string-valued.

Parameters:

value (float or string) – Mechanism output to be transformed.

Returns:

Transformed output value.

Return type:

string

pre_transform(value)[source]

Transforms the input to be integer-valued for ingestion by the mechanism.

Parameters:

value (float or string) – Input value to be transformed.

Returns:

Transformed input value

Return type:

int

randomise(value)

Randomise the given value using the DPMachine.

Parameters:

value (float or string) – Value to be randomised.

Returns:

Randomised value, same type as value.

Return type:

float or string

Other transforms

class diffprivlib.mechanisms.transforms.RoundedInteger(parent)[source]

Rounded integer transform. Rounds the (float) output of the given mechanism to the nearest integer.

post_transform(value)[source]

Transforms the (float) output of the mechanism to be a rounded integer.

Parameters:

value (float) – Mechanism output to be transformed.

Returns:

Transformed output value.

Return type:

int

pre_transform(value)

Performs no transformation on the input data, and is ingested by the mechanism as-is.

Parameters:

value (float or string) – Input value to be transformed.

Returns:

Transformed input value

Return type:

float or string

randomise(value)

Randomise the given value using the DPMachine.

Parameters:

value (float or string) – Value to be randomised.

Returns:

Randomised value, same type as value.

Return type:

float or string