interactive_measurements#
Measurements that allow interactively submitting queries to a private dataset.
Functions#
Returns a measurement to launch a |
- create_adaptive_composition(input_domain, input_metric, d_in, privacy_budget, output_measure)#
Returns a measurement to launch a
DecoratedQueryable
.Returned
DecoratedQueryable
allows transforming the private data and answering non-interactiveMeasurementQuery
s as long as the cumulative privacy budget spent does not exceedprivacy_budget
.- Parameters:
input_domain (tmlt.core.domains.base.Domain) – Domain of input datasets.
input_metric (tmlt.core.metrics.Metric) – Distance metric for input datasets.
d_in (Any) – Input metric value for inputs.
privacy_budget (tmlt.core.measures.PrivacyBudgetInput) – Total privacy budget across all measurements.
output_measure (Union[tmlt.core.measures.PureDP, tmlt.core.measures.ApproxDP, tmlt.core.measures.RhoZCDP]) – Distance measure for measurement’s output.
- Return type:
Classes#
Base class for Queryables. |
|
Contains a Measurement and the |
|
Contains a Transformation and the |
|
Contains the index of measurement to be answered. |
|
Query for retiring a RetirableQueryable. |
|
Wraps another Queryable and allows retiring all descendant Queryables. |
|
Answers interactive measurement queries sequentially. |
|
Answers index queries on partitions. |
|
Returns answer obtained from a non-interactive measurement. |
|
Allows modifying the query to and the answer from a Queryable. |
|
Creates a |
|
Creates a |
|
Creates a |
|
Creates a |
|
All possible states for a |
|
An interface for adaptively composing measurements across transformed datasets. |
- class Queryable#
Bases:
abc.ABC
Base class for Queryables.
Note
All subclasses of Queryable should have exactly one public method: __call__.
- abstract __call__(query)#
Returns answer to given query.
- Parameters:
query (Any)
- Return type:
Any
- class MeasurementQuery#
Contains a Measurement and the
d_out
it satisfies.Note
The
d_in
is known by the Queryable.Used by
- measurement: tmlt.core.measurements.base.Measurement#
The measurement to answer.
- d_out: Any | None = None#
The output measure value satisfied by measurement.
It is only required if the measurement’s
privacy_function()
raisesNotImplementedError
.
- class TransformationQuery#
Contains a Transformation and the
d_out
it satisfies.Note
The
d_in
is known by the Queryable.Used by
- transformation: tmlt.core.transformations.base.Transformation#
The transformation to apply.
- d_out: Any | None = None#
The output metric value satisfied by the transformation.
It is only required if the transformations’s
Transformation.stability_function()
raisesNotImplementedError
.
- class IndexQuery#
Contains the index of measurement to be answered.
Used by
- class RetireQuery#
Query for retiring a RetirableQueryable.
Used by
- class RetirableQueryable(queryable)#
Bases:
Queryable
Wraps another Queryable and allows retiring all descendant Queryables.
A RetirableQueryable can be initialized with any instance of
Queryable
and can be in one of two internal states: “active” or “retired”.All descendant
Queryable
s of a RetirableQueryable are instances of RetirableQueryable. The__call__
method on RetirableQueryable accepts a specialRetireQuery
query that retires itself and all descendantQueryable
s.Submitting a query
q
to a RetirableQueryableRQ
has the following behavior:If
q
is aRetireQuery
,RQ
submits aRetireQuery
to each childRetirableQueryable
, changes its state to “retired”, and returnsNone
.If
q
is not aRetireQuery
andRQ
is “active”, it obtains an answerA
by submittingq
to its inner Queryable.If
A
is not a Queryable,RQ
returnsA
.Otherwise,
RQ
constructs and returns a new RetirableQueryable withQueryable
A
.
If
q
is not aRetireQuery
andRQ
is “retired”, an error is raised.
- Parameters:
queryable (Queryable)
- __init__(queryable)#
Constructor.
- Arg:
queryable:
Queryable
to be wrapped.
- Parameters:
queryable (Queryable)
- __call__(query)#
Answers query.
If
query
isRetireQuery
, this queryable and all descendant queryables are retired. Otherwise, thequery
is routed to the wrapped queryable.- Parameters:
query (Any)
- Return type:
Any
- class SequentialQueryable(input_domain, input_metric, d_in, output_measure, privacy_budget, data)#
Bases:
Queryable
Answers interactive measurement queries sequentially.
All interactions with a Queryable obtained from answering an interactive measurement must be completed before a second interactive measurement can be answered.
- Parameters:
input_domain (tmlt.core.domains.base.Domain)
input_metric (tmlt.core.metrics.Metric)
d_in (Any)
output_measure (Union[tmlt.core.measures.PureDP, tmlt.core.measures.ApproxDP, tmlt.core.measures.RhoZCDP])
privacy_budget (tmlt.core.measures.PrivacyBudgetInput)
data (Any)
- __init__(input_domain, input_metric, d_in, output_measure, privacy_budget, data)#
Constructor.
- Parameters:
input_domain (
Domain
) – Domain of data being queried.input_metric (
Metric
) – Distance metric forinput_domain
.d_in (
Any
) – Input metric value for inputs.output_measure (
Union
[PureDP
,ApproxDP
,RhoZCDP
]) – Distance measure on output.privacy_budget (
Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
,Tuple
[Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
],Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
]]]) – Total privacy budget across all queries.data (
Any
) – Data to be queried.
- __call__(query)#
Answers the query.
- Parameters:
query (Union[MeasurementQuery, TransformationQuery])
- Return type:
Optional[RetirableQueryable]
- class ParallelQueryable(data, measurements)#
Bases:
Queryable
Answers index queries on partitions.
- Parameters:
data (List)
measurements (List[tmlt.core.measurements.base.Measurement])
- __init__(data, measurements)#
Constructor.
- Parameters:
data (
List
) – Data being queried.measurements (
List
[Measurement
]) – List of measurements to be answered on each list element.
- __call__(query)#
Answers
IndexQuery
s.- Parameters:
query (IndexQuery)
- Return type:
Any
- class GetAnswerQueryable(measurement, data)#
Bases:
Queryable
Returns answer obtained from a non-interactive measurement.
- Parameters:
measurement (tmlt.core.measurements.base.Measurement)
data (Any)
- __init__(measurement, data)#
Constructor.
- Parameters:
measurement (Measurement)
data (Any)
- __call__(query)#
Returns answer.
- Parameters:
query (None)
- Return type:
Any
- class DecoratedQueryable(queryable, preprocess_query, postprocess_answer)#
Bases:
Queryable
Allows modifying the query to and the answer from a Queryable.
The privacy guarantee for
DecoratedQueryable
depends on the passed functionpostprocess_answer
satisfying certain properties. In particular,postprocess_answer
should not use distinguishing pseudo-side channel information, and should be well-defined on its abstract domain. See Postprocessing udfs and pseudo-side channel information.- Parameters:
queryable (Queryable)
preprocess_query (Callable[[Any], Any])
postprocess_answer (Callable[[Any], Any])
- __init__(queryable, preprocess_query, postprocess_answer)#
Constructor.
- Parameters:
preprocess_query (
Callable
[[Any
],Any
]) – Function to preprocess queries to thisDecoratedQueryable
.postprocess_answer (
Callable
[[Any
],Any
]) – Function to postprocess answers from thisDecoratedQueryable
.
- __call__(query)#
Answers query.
- Parameters:
query (Any)
- Return type:
Any
- class DecorateQueryable(measurement, preprocess_query, postprocess_answer)#
Bases:
tmlt.core.measurements.base.Measurement
Creates a
DecoratedQueryable
.This class allows preprocessing queries to a
Queryable
launched by another interactive measurement as well as post-processing answers produced by theQueryable
.- Parameters:
measurement (tmlt.core.measurements.base.Measurement)
preprocess_query (Callable[[Any], Any])
postprocess_answer (Callable[[Any], Any])
- property measurement: tmlt.core.measurements.base.Measurement#
Returns wrapped
Measurement
.- Return type:
- property preprocess_query: Callable[[Any], Any]#
Returns function to preprocess queries.
- Return type:
Callable[[Any], Any]
- property postprocess_answer: Callable[[Any], Any]#
Returns function to postprocess answers.
- Return type:
Callable[[Any], Any]
- property input_domain: tmlt.core.domains.base.Domain#
Return input domain for the measurement.
- Return type:
- property input_metric: tmlt.core.metrics.Metric#
Distance metric on input domain.
- Return type:
- property output_measure: tmlt.core.measures.Measure#
Distance measure on output.
- Return type:
- __init__(measurement, preprocess_query, postprocess_answer)#
Constructor.
- Parameters:
measurement (
Measurement
) – Interactive measurement to decorate.preprocess_query (
Callable
[[Any
],Any
]) – Function to preprocess queries submitted to the Queryable obtained by running this measurement.postprocess_answer (
Callable
[[Any
],Any
]) – Function to process answers produced by the Queryable returned by this measurement.
- privacy_function(d_in)#
Returns the smallest d_out satisfied by the measurement.
- Parameters:
d_in (Any)
- Return type:
Any
- __call__(data)#
Returns a
DecoratedQueryable
.- Parameters:
data (Any)
- Return type:
- privacy_relation(d_in, d_out)#
Return True if close inputs produce close outputs.
See the privacy and stability tutorial (add link?) for more information.
- Parameters:
d_in (Any) – Distance between inputs under
input_metric
.d_out (Any) – Distance between outputs under
output_measure
.
- Return type:
- class SequentialComposition(input_domain, input_metric, output_measure, d_in, privacy_budget)#
Bases:
tmlt.core.measurements.base.Measurement
Creates a
SequentialQueryable
.This class allows for measurements to be answered interactively using a cumulative privacy budget.
The main restriction, which is enforced by the returned
SequentialQueryable
, is that interactive measurements cannot be freely interleaved.- Parameters:
input_domain (tmlt.core.domains.base.Domain)
input_metric (tmlt.core.metrics.Metric)
output_measure (Union[tmlt.core.measures.PureDP, tmlt.core.measures.ApproxDP, tmlt.core.measures.RhoZCDP])
d_in (Any)
privacy_budget (tmlt.core.measures.PrivacyBudgetInput)
- property d_in: Any#
Returns the distance between input datasets.
- Return type:
Any
- property privacy_budget: tmlt.core.measures.PrivacyBudgetValue#
Total privacy budget across all measurements.
- Return type:
tmlt.core.measures.PrivacyBudgetValue
- property output_measure: tmlt.core.measures.PureDP | tmlt.core.measures.ApproxDP | tmlt.core.measures.RhoZCDP#
Return output measure for the measurement.
- Return type:
Union[tmlt.core.measures.PureDP, tmlt.core.measures.ApproxDP, tmlt.core.measures.RhoZCDP]
- property input_domain: tmlt.core.domains.base.Domain#
Return input domain for the measurement.
- Return type:
- property input_metric: tmlt.core.metrics.Metric#
Distance metric on input domain.
- Return type:
- __init__(input_domain, input_metric, output_measure, d_in, privacy_budget)#
Constructor.
- Parameters:
input_domain (
Domain
) – Domain of input datasets.input_metric (
Metric
) – Distance metric for input datasets.output_measure (
Union
[PureDP
,ApproxDP
,RhoZCDP
]) – Distance measure for measurement’s output.d_in (
Any
) – Input metric value for inputs.privacy_budget (
Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
,Tuple
[Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
],Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
]]]) – Total privacy budget across all measurements.
- privacy_function(d_in)#
Returns the smallest d_out satisfied by the measurement.
The returned d_out is the privacy_budget.
- Parameters:
d_in (Any) – Distance between inputs under input_metric. Must be less than or equal to the d_in the measurement was created with.
- Return type:
tmlt.core.measures.PrivacyBudgetValue
- __call__(data)#
Returns a Queryable object on input data.
- Parameters:
data (Any)
- Return type:
- privacy_relation(d_in, d_out)#
Return True if close inputs produce close outputs.
See the privacy and stability tutorial (add link?) for more information.
- Parameters:
d_in (Any) – Distance between inputs under
input_metric
.d_out (Any) – Distance between outputs under
output_measure
.
- Return type:
- class ParallelComposition(input_domain, input_metric, output_measure, measurements)#
Bases:
tmlt.core.measurements.base.Measurement
Creates a
ParallelQueryable
.This class allows for answering measurements on objects in some
ListDomain
which have aSumOf
orRootSumOfSquared
input metric, such as after a partition.The main restriction, which is enforced by the returned
ParallelQueryable
, is that partitions can only be accessed in the sequence that they appear in the list.- Parameters:
input_domain (tmlt.core.domains.collections.ListDomain)
input_metric (Union[tmlt.core.metrics.SumOf, tmlt.core.metrics.RootSumOfSquared])
output_measure (Union[tmlt.core.measures.PureDP, tmlt.core.measures.ApproxDP, tmlt.core.measures.RhoZCDP])
measurements (List[tmlt.core.measurements.base.Measurement])
- property measurements: List[tmlt.core.measurements.base.Measurement]#
Returns list of composed measurements.
- Return type:
- property input_domain: tmlt.core.domains.base.Domain#
Return input domain for the measurement.
- Return type:
- property input_metric: tmlt.core.metrics.Metric#
Distance metric on input domain.
- Return type:
- property output_measure: tmlt.core.measures.Measure#
Distance measure on output.
- Return type:
- __init__(input_domain, input_metric, output_measure, measurements)#
Constructor.
- Parameters:
input_domain (
ListDomain
) – Domain of input lists.input_metric (
Union
[SumOf
,RootSumOfSquared
]) – Distance metric for input lists.output_measure (
Union
[PureDP
,ApproxDP
,RhoZCDP
]) – Distance measure for measurement’s output.measurements (
List
[Measurement
]) – List of measurements to be applied to the corresponding elements in the input list. The length of this list must match the length of lists in the input_domain.
- privacy_function(d_in)#
Returns the smallest d_out satisfied by the measurement.
Returns the largest
d_out
from theprivacy_function()
of all of the composed measurements.- Parameters:
d_in (Any) – Distance between inputs under input_metric.
- Raises:
NotImplementedError – If any of the composed measurements’
privacy_relation()
raiseNotImplementedError
.- Return type:
tmlt.core.measures.PrivacyBudgetValue
- __call__(data)#
Returns a
ParallelQueryable
.- Parameters:
data (Any)
- Return type:
- privacy_relation(d_in, d_out)#
Return True if close inputs produce close outputs.
See the privacy and stability tutorial (add link?) for more information.
- Parameters:
d_in (Any) – Distance between inputs under
input_metric
.d_out (Any) – Distance between outputs under
output_measure
.
- Return type:
- class MakeInteractive(measurement)#
Bases:
tmlt.core.measurements.base.Measurement
Creates a
GetAnswerQueryable
.This allows submitting non-interactive measurements as interactive measurement queries to
SequentialQueryable
andParallelQueryable
.- Parameters:
measurement (tmlt.core.measurements.base.Measurement)
- property measurement: tmlt.core.measurements.base.Measurement#
Returns wrapped non-interactive measurement.
- Return type:
- property input_domain: tmlt.core.domains.base.Domain#
Return input domain for the measurement.
- Return type:
- property input_metric: tmlt.core.metrics.Metric#
Distance metric on input domain.
- Return type:
- property output_measure: tmlt.core.measures.Measure#
Distance measure on output.
- Return type:
- __init__(measurement)#
Constructor.
- Parameters:
measurement (
Measurement
) – Non-interactive measurement to be wrapped.
- privacy_function(d_in)#
Returns the smallest d_out satisfied by the measurement.
- Parameters:
d_in (Any)
- Return type:
Any
- privacy_relation(d_in, d_out)#
Returns True only if wrapped measurement’s privacy relation is satisfied.
- Parameters:
d_in (Any)
d_out (Any)
- Return type:
Any
- __call__(data)#
Returns a
GetAnswerQueryable
.- Parameters:
data (Any)
- Return type:
- class PrivacyAccountantState#
Bases:
enum.Enum
All possible states for a
PrivacyAccountant
.- ACTIVE = 1#
The
PrivacyAccountant
is active and can perform actions.This is the default state of a
PrivacyAccountant
constructed by callinglaunch()
.A
PrivacyAccountant
can only perform actions if it is ACTIVE.- Transitioning to ACTIVE:
A
PrivacyAccountant
that is WAITING_FOR_SIBLING will become ACTIVE if- the sibling immediately preceding this
PrivacyAccountant
is RETIRED.
- the sibling immediately preceding this
force_activate()
is called.This will retire all preceding siblings and their descendants
A
PrivacyAccountant
that is WAITING_FOR_CHILDREN will become ACTIVE ifall of its children are RETIRED
force_activate()
is called.This will retire all of its descendants
- WAITING_FOR_SIBLING = 2#
The
PrivacyAccountant
is waiting for the preceding sibling to retire.This is the default state of all but the first
PrivacyAccountant
created bysplit()
.PrivacyAccountant
s obtained by callingsplit()
must be activated in the same order that they appear in the list.
- WAITING_FOR_CHILDREN = 3#
The
PrivacyAccountant
has children who have not been retired.- Transitioning to WAITING_FOR_CHILDREN:
A
PrivacyAccountant
that is ACTIVE will become WAITING_FOR_CHILDREN ifsplit()
creates children
- RETIRED = 4#
The
PrivacyAccountant
can no longer perform actions.- Transitioning to RETIRED:
A
PrivacyAccountant
that is WAITING_FOR_SIBLING or ACTIVE will become RETIRED ifretire()
is called on itretire()
is called on one of its ancestors withforce
= Trueforce_activate()
is called on one of its succeeding siblings.force_activate()
is called on one of its ancestors.
Note
If a
PrivacyAccountant
is retired while it is WAITING_FOR_SIBLING (before it has performed any actions), aRuntimeWarning
is raised.A
PrivacyAccountant
that is WAITING_FOR_CHILDREN will become RETIRED whenretire()
is called on it withforce
= Trueretire()
is called on its ancestor withforce
= Trueforce_activate()
is called on one of its succeeding siblings.force_activate()
is called on one of its ancestors.
- class PrivacyAccountant(queryable, input_domain, input_metric, output_measure, d_in, privacy_budget, parent=None)#
An interface for adaptively composing measurements across transformed datasets.
PrivacyAccountant
supports multiple actions to answer measurements and transform data.Calling any of the following methods is considered an action:
To preserve privacy, after children are created (using
split()
), there are restrictions on the order of interactions among thePrivacyAccountant
and its descendants. SeePrivacyAccountantState
for more information.- Parameters:
queryable (Optional[Queryable])
input_domain (tmlt.core.domains.base.Domain)
input_metric (tmlt.core.metrics.Metric)
output_measure (Union[tmlt.core.measures.PureDP, tmlt.core.measures.ApproxDP, tmlt.core.measures.RhoZCDP])
d_in (Any)
privacy_budget (tmlt.core.measures.PrivacyBudgetInput)
parent (Optional[PrivacyAccountant])
- property input_domain: tmlt.core.domains.base.Domain#
Returns the domain of the private data.
- Return type:
- property input_metric: tmlt.core.metrics.Metric#
Returns the distance metric for neighboring datasets.
- Return type:
- property output_measure: tmlt.core.measures.PureDP | tmlt.core.measures.ApproxDP | tmlt.core.measures.RhoZCDP#
Returns the output measure for measurement outputs.
- Return type:
Union[tmlt.core.measures.PureDP, tmlt.core.measures.ApproxDP, tmlt.core.measures.RhoZCDP]
- property d_in: Any#
Returns the distance for neighboring datasets.
- Return type:
Any
- property privacy_budget: tmlt.core.measures.PrivacyBudgetValue#
Returns the remaining privacy budget.
- Return type:
tmlt.core.measures.PrivacyBudgetValue
- property state: PrivacyAccountantState#
Returns this
PrivacyAccountant
’s current state.See
PrivacyAccountantState
for more information.- Return type:
- property parent: PrivacyAccountant | None#
Returns the parent of this
PrivacyAccountant
.If this is the root
PrivacyAccountant
, this returns None.- Return type:
Optional[PrivacyAccountant]
- property children: List[PrivacyAccountant]#
Returns the children of this
PrivacyAccountant
.Children are created by calling
split()
.- Return type:
List[PrivacyAccountant]
- __init__(queryable, input_domain, input_metric, output_measure, d_in, privacy_budget, parent=None)#
Constructor.
Note
A
PrivacyAccountant
should be constructed usinglaunch()
. Do not use the constructor directly.- Parameters:
queryable (
Optional
[Queryable
]) – AQueryable
to wrap. Ifinitial_state
is ACTIVE, this should not be None.input_domain (
Domain
) – The input domain forqueryable
.input_metric (
Metric
) – The input metric forqueryable
.output_measure (
Union
[PureDP
,ApproxDP
,RhoZCDP
]) – The output measure forqueryable
.d_in (
Any
) – The input metric value forqueryable
.privacy_budget (
Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
,Tuple
[Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
],Union
[ExactNumber
,float
,int
,str
,Fraction
,Expr
]]]) – The privacy budget for thequeryable
.parent (
Optional
[PrivacyAccountant
]) – The parent of thisPrivacyAccountant
.
- static launch(measurement, data)#
Returns a
PrivacyAccountant
from a measurement and data.The returned
PrivacyAccountant
isACTIVE
and has noparent
.Example
>>> measurement = SequentialComposition( ... input_domain=SparkDataFrameDomain( ... { ... "A": SparkIntegerColumnDescriptor(), ... "B": SparkStringColumnDescriptor(), ... } ... ), ... input_metric=SymmetricDifference(), ... output_measure=PureDP(), ... d_in=1, ... privacy_budget=5, ... ) >>> privacy_accountant = PrivacyAccountant.launch(measurement, dataframe) >>> privacy_accountant.state <PrivacyAccountantState.ACTIVE: 1> >>> privacy_accountant.output_measure PureDP() >>> privacy_accountant.privacy_budget 5 >>> print(privacy_accountant.parent) None
- Parameters:
measurement (SequentialComposition) – A
SequentialComposition
to apply to the data.data (Any) – The private data to use.
- Return type:
- transform_in_place(transformation, d_out=None)#
Transforms the private data inside this
PrivacyAccountant
.This method is an action.
Requirements to apply
transformation
:this
PrivacyAccountant
’sstate
must be ACTIVEtransformation
’sinput_domain
must match thisPrivacyAccountant
’sinput_domain
transformation
’sinput_metric
must match thisPrivacyAccountant
’sinput_metric
if
d_out
is provided,transformation
’sstability_relation()
must hold forPrivacyAccountant
’sd_in
andd_out
After applying
transformation
:this
PrivacyAccountant
’sinput_domain
will becometransformation
’soutput_domain
this
PrivacyAccountant
’sinput_metric
will becometransformation
’soutput_metric
this
PrivacyAccountant
’sd_in
will becometransformation
’s d_outif
transformation
implements astability_function()
, its d_out is the output of its stability function on thisPrivacyAccountant
’sd_in
otherwise it is the argument
d_out
Example
>>> privacy_accountant.input_domain NumpyIntegerDomain(size=64) >>> privacy_accountant.input_metric AbsoluteDifference() >>> privacy_accountant.output_measure PureDP() >>> privacy_accountant.d_in 2 >>> privacy_accountant.privacy_budget 5 >>> transformation = CreateDictFromValue( ... input_domain=NumpyIntegerDomain(), ... input_metric=AbsoluteDifference(), ... key="A", ... ) >>> privacy_accountant.transform_in_place(transformation) >>> privacy_accountant.input_domain DictDomain(key_to_domain={'A': NumpyIntegerDomain(size=64)}) >>> privacy_accountant.input_metric DictMetric(key_to_metric={'A': AbsoluteDifference()}) >>> privacy_accountant.output_measure PureDP() >>> privacy_accountant.d_in {'A': 2} >>> privacy_accountant.privacy_budget 5
- Parameters:
transformation (tmlt.core.transformations.base.Transformation) – The transformation to apply.
d_out (Optional[Any]) – An optional value for the output metric for
transformation
. It is only used iftransformation
does not implement astability_function()
.
- Raises:
InactiveAccountantError – If this
PrivacyAccountant
is not ACTIVE.- Return type:
None
- measure(measurement, d_out=None)#
Returns the answer to
measurement
.This method is an action.
Requirements to answer
measurement
:measurement
’sinput_domain
must match thisPrivacyAccountant
’sinput_domain
measurement
’sinput_metric
must match thisPrivacyAccountant
’sinput_metric
measurement
’soutput_measure
must match thisPrivacyAccountant
’soutput_measure
if
d_out
is provided,measurement
’sprivacy_relation()
must hold forPrivacyAccountant
’sd_in
andd_out
this
PrivacyAccountant
’sprivacy_budget
must be greater than or equal to themeasurement
’s d_outif
measurement
implements aprivacy_function()
, its d_out is the output of its privacy function on thisPrivacyAccountant
’sd_in
otherwise it is the argument
d_out
After answering
measurement
:this
PrivacyAccountant
’sprivacy_budget
will decrease bymeasurement
’s d_out
Example
>>> privacy_accountant.input_domain NumpyIntegerDomain(size=64) >>> privacy_accountant.input_metric AbsoluteDifference() >>> privacy_accountant.output_measure PureDP() >>> privacy_accountant.d_in 2 >>> privacy_accountant.privacy_budget 5 >>> noise_scale = calculate_noise_scale( ... d_in=2, ... d_out=3, ... output_measure=PureDP(), ... ) >>> measurement = AddLaplaceNoise( ... input_domain=NumpyIntegerDomain(), ... scale=noise_scale, ... ) >>> privacy_accountant.measure(measurement) ... >>> privacy_accountant.input_domain NumpyIntegerDomain(size=64) >>> privacy_accountant.input_metric AbsoluteDifference() >>> privacy_accountant.output_measure PureDP() >>> privacy_accountant.d_in 2 >>> privacy_accountant.privacy_budget 2
- Parameters:
measurement (tmlt.core.measurements.base.Measurement) – A non-interactive measurement to answer.
d_out (Optional[tmlt.core.measures.PrivacyBudgetInput]) – An optional d_out for
measurement
. It is only used ifmeasurement
does not implement aprivacy_function()
.
- Raises:
InactiveAccountantError – If this
PrivacyAccountant
is not ACTIVE.- Return type:
Any
- split(splitting_transformation, privacy_budget, d_out=None)#
Returns new
PrivacyAccountant
s from splitting the private data.Uses
splitting_transformation
to split the private data into a list of new datasets. A newPrivacyAccountant
is returned for each element in the list created bysplitting_transformation
.Note
Unlike
transform_in_place()
, this does not transform the private data in thisPrivacyAccountant
.This method is an action.
Requirements to split:
splitting_transformation
’sinput_domain
must match thisPrivacyAccountant
’sinput_domain
splitting_transformation
’sinput_metric
must match thisPrivacyAccountant
’sinput_metric
if
d_out
is provided,splitting_transformation
’sstability_relation()
must hold for thisPrivacyAccountant
’sd_in
andd_out
splitting_transformation
’soutput_domain
must be aListDomain
with a fixedlength
.splitting_transformation
’soutput_metric
must beSumOf
if thisPrivacyAccountant
’soutput_measure
isPureDP
orRootSumOfSquared
if thisPrivacyAccountant
’soutput_measure
isRhoZCDP
After creating the new
PrivacyAccountant
s:this
PrivacyAccountant
’sprivacy_budget
will decrease byprivacy_budget
this
PrivacyAccountant
’schildren
will be a list with the newPrivacyAccountant
sthis
PrivacyAccountant
’sstate
will become WAITING_FOR_CHILDRENthe new
PrivacyAccountant
s’input_domain
will be the element domain ofsplitting_transformation
’sListDomain
the new
PrivacyAccountant
s’input_metric
will be the inner metric ofsplitting_transformation
’sSumOf
orRootSumOfSquared
metricthe new
PrivacyAccountant
s’output_measure
will be thisPrivacyAccountant
soutput_measure
the new
PrivacyAccountant
s’d_in
will besplitting_transformation
’s d_outif
splitting_transformation
implements astability_function()
, its d_out is the output of its stability function on thisPrivacyAccountant
’sd_in
otherwise it is the argument
d_out
the new
PrivacyAccountant
s’privacy_budget
will beprivacy_budget
the first child
PrivacyAccountant
‘sstate
will be ACTIVE and all other childPrivacyAccountant
s’state
will be WAITING_FOR_SIBLING.
Note
After creating children, the
state
will change to WAITING_FOR_CHILDREN, until the children are all RETIRED.Example
>>> privacy_accountant.input_domain DictDomain(key_to_domain={'A': ListDomain(element_domain=NumpyIntegerDomain(size=64), length=3)}) >>> privacy_accountant.input_metric DictMetric(key_to_metric={'A': SumOf(inner_metric=AbsoluteDifference())}) >>> privacy_accountant.output_measure PureDP() >>> privacy_accountant.d_in {'A': 2} >>> privacy_accountant.privacy_budget 5 >>> privacy_accountant.state <PrivacyAccountantState.ACTIVE: 1> >>> splitting_transformation = GetValue( ... input_domain=DictDomain( ... key_to_domain={ ... "A": ListDomain( ... element_domain=NumpyIntegerDomain(), ... length=3, ... ), ... } ... ), ... input_metric=DictMetric( ... key_to_metric={"A": SumOf(inner_metric=AbsoluteDifference())} ... ), ... key="A", ... ) >>> children = privacy_accountant.split( ... splitting_transformation=splitting_transformation, ... privacy_budget=3, ... ) >>> privacy_accountant.input_domain DictDomain(key_to_domain={'A': ListDomain(element_domain=NumpyIntegerDomain(size=64), length=3)}) >>> privacy_accountant.input_metric DictMetric(key_to_metric={'A': SumOf(inner_metric=AbsoluteDifference())}) >>> privacy_accountant.output_measure PureDP() >>> privacy_accountant.d_in {'A': 2} >>> privacy_accountant.privacy_budget 2 >>> privacy_accountant.state <PrivacyAccountantState.WAITING_FOR_CHILDREN: 3> >>> children[0].input_domain NumpyIntegerDomain(size=64) >>> children[0].input_metric AbsoluteDifference() >>> children[0].output_measure PureDP() >>> children[0].d_in 2 >>> children[0].privacy_budget 3 >>> # The first child is ACTIVE >>> children[0].state <PrivacyAccountantState.ACTIVE: 1> >>> # The other children are WAITING_FOR_SIBLING >>> children[1].state <PrivacyAccountantState.WAITING_FOR_SIBLING: 2> >>> children[2].state <PrivacyAccountantState.WAITING_FOR_SIBLING: 2> >>> # When the first child is RETIRED, the second child becomes ACTIVE >>> children[0].retire() >>> children[0].state <PrivacyAccountantState.RETIRED: 4> >>> children[1].state <PrivacyAccountantState.ACTIVE: 1> >>> # When all children are RETIRED, the parent transitions from >>> # WAITING_FOR_CHILDREN to ACTIVE >>> children[1].retire() >>> children[2].retire() >>> privacy_accountant.state <PrivacyAccountantState.ACTIVE: 1>
- Parameters:
splitting_transformation (tmlt.core.transformations.base.Transformation) – The transformation to apply.
privacy_budget (tmlt.core.measures.PrivacyBudgetInput) – The privacy budget to allocate to the new
PrivacyAccountant
s.d_out (Optional[Any]) – An optional value for the
output_metric
forsplitting_transformation
. It is only used ifsplitting_transformation
does not implement astability_function()
.
- Raises:
InactiveAccountantError – If this
PrivacyAccountant
is not ACTIVE.- Return type:
List[PrivacyAccountant]
- force_activate()#
Set this
PrivacyAccountant
’s state to ACTIVE.A
PrivacyAccountant
must be ACTIVE to perform actionsSee
PrivacyAccountantState
for more information.If this
PrivacyAccountant
is WAITING_FOR_SIBLING, it retires all preceding siblings. If thisPrivacyAccountant
is WAITING_FOR_CHILDREN it retires all of its descendants.- Raises:
RuntimeError – If this
PrivacyAccountant
is RETIRED.- Return type:
None
- retire(force=False)#
Set this
PrivacyAccountant
’s state to RETIRED.If this
PrivacyAccountant
is WAITING_FOR_SIBLING, it also retires all preceding siblings and their descendants. If thisPrivacyAccountant
is WAITING_FOR_CHILDREN it also retires all of its descendants.A RETIRED
PrivacyAccountant
cannot perform actions, but its properties can still be inspected.See
PrivacyAccountantState
for more information.- Parameters:
force (bool) – Whether this
PrivacyAccountant
can retire its descendants if thisPrivacyAccountant
is WAITING_FOR_CHILDREN.- Raises:
RuntimeError – If this
PrivacyAccountant
cannot be set to RETIRED. Ifforce
is False, thisPrivacyAccountant
cannot be WAITING_FOR_CHILDREN. Ifforce
is True,retire()
can always be called.RuntimeWarning – If the
PrivacyAccountant
is WAITING_FOR_SIBLING.
- Return type:
None
- queue_transformation(transformation, d_out=None)#
Queue
transformation
to be executed when thisPrivacyAccountant
becomes ACTIVE.If this
PrivacyAccountant
is ACTIVE, this has the same behavior astransform_in_place()
.If this
PrivacyAccountant
is WAITING_FOR_CHILDREN or WAITING_FOR_SIBLING,transformation
will be applied to the private data when thisPrivacyAccountant
becomes ACTIVE, but otherwise it has the same behavior astransform_in_place()
(input_domain
,input_metric
, andd_in
are updated immediately).Note that multiple transformations can be queued.
- Parameters:
transformation (tmlt.core.transformations.base.Transformation) – The transformation to apply.
d_out (Optional[Any]) – An optional value for the output metric for
transformation
. It is only used iftransformation
does not implement astability_function()
.
- Return type:
None
Exceptions#
- exception InactiveAccountantError#
Bases:
RuntimeError
Raised when trying to perform operations on an accountant that is not ACTIVE.
PrivacyAccountant will raise this exception if you attempt an operation and the accountant is not ACTIVE.