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
DecoratedQueryableallows transforming the private data and answering non-interactiveMeasurementQuerys 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.ABCBase 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_outit satisfies.Note
The
d_inis 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_outit satisfies.Note
The
d_inis 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:
QueryableWraps another Queryable and allows retiring all descendant Queryables.
A RetirableQueryable can be initialized with any instance of
Queryableand can be in one of two internal states: “active” or “retired”.All descendant
Queryables of a RetirableQueryable are instances of RetirableQueryable. The__call__method on RetirableQueryable accepts a specialRetireQueryquery that retires itself and all descendantQueryables.Submitting a query
qto a RetirableQueryableRQhas the following behavior:If
qis aRetireQuery,RQsubmits aRetireQueryto each childRetirableQueryable, changes its state to “retired”, and returnsNone.If
qis not aRetireQueryandRQis “active”, it obtains an answerAby submittingqto its inner Queryable.If
Ais not a Queryable,RQreturnsA.Otherwise,
RQconstructs and returns a new RetirableQueryable withQueryableA.
If
qis not aRetireQueryandRQis “retired”, an error is raised.
- Parameters:
queryable (Queryable)
- __init__(queryable)#
Constructor.
- Arg:
queryable:
Queryableto be wrapped.
- Parameters:
queryable (Queryable)
- __call__(query)#
Answers query.
If
queryisRetireQuery, this queryable and all descendant queryables are retired. Otherwise, thequeryis 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:
QueryableAnswers 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 (
PureDP|ApproxDP|RhoZCDP) – Distance measure on output.privacy_budget (
ExactNumber|float|int|str|Fraction|Expr|Tuple[ExactNumber|float|int|str|Fraction|Expr,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:
QueryableAnswers 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
IndexQuerys.- Parameters:
query (IndexQuery)
- Return type:
Any
- class GetAnswerQueryable(measurement, data)#
Bases:
QueryableReturns 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:
QueryableAllows modifying the query to and the answer from a Queryable.
The privacy guarantee for
DecoratedQueryabledepends on the passed functionpostprocess_answersatisfying certain properties. In particular,postprocess_answershould 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.MeasurementCreates a
DecoratedQueryable.This class allows preprocessing queries to a
Queryablelaunched 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.MeasurementCreates 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 (
PureDP|ApproxDP|RhoZCDP) – Distance measure for measurement’s output.d_in (
Any) – Input metric value for inputs.privacy_budget (
ExactNumber|float|int|str|Fraction|Expr|Tuple[ExactNumber|float|int|str|Fraction|Expr,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.MeasurementCreates a
ParallelQueryable.This class allows for answering measurements on objects in some
ListDomainwhich have aSumOforRootSumOfSquaredinput 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 (
SumOf|RootSumOfSquared) – Distance metric for input lists.output_measure (
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_outfrom 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.MeasurementCreates a
GetAnswerQueryable.This allows submitting non-interactive measurements as interactive measurement queries to
SequentialQueryableandParallelQueryable.- 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.EnumAll possible states for a
PrivacyAccountant.- ACTIVE = 1#
The
PrivacyAccountantis active and can perform actions.This is the default state of a
PrivacyAccountantconstructed by callinglaunch().A
PrivacyAccountantcan only perform actions if it is ACTIVE.- Transitioning to ACTIVE:
A
PrivacyAccountantthat is WAITING_FOR_SIBLING will become ACTIVE if- the sibling immediately preceding this
PrivacyAccountantis RETIRED.
- the sibling immediately preceding this
force_activate()is called.This will retire all preceding siblings and their descendants
A
PrivacyAccountantthat 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
PrivacyAccountantis waiting for the preceding sibling to retire.This is the default state of all but the first
PrivacyAccountantcreated bysplit().PrivacyAccountants obtained by callingsplit()must be activated in the same order that they appear in the list.
- WAITING_FOR_CHILDREN = 3#
The
PrivacyAccountanthas children who have not been retired.- Transitioning to WAITING_FOR_CHILDREN:
A
PrivacyAccountantthat is ACTIVE will become WAITING_FOR_CHILDREN ifsplit()creates children
- RETIRED = 4#
The
PrivacyAccountantcan no longer perform actions.- Transitioning to RETIRED:
A
PrivacyAccountantthat 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
PrivacyAccountantis retired while it is WAITING_FOR_SIBLING (before it has performed any actions), aRuntimeWarningis raised.A
PrivacyAccountantthat 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.
PrivacyAccountantsupports 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 thePrivacyAccountantand its descendants. SeePrivacyAccountantStatefor 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
PrivacyAccountantStatefor 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
PrivacyAccountantshould be constructed usinglaunch(). Do not use the constructor directly.- Parameters:
queryable (
Queryable|None) – AQueryableto wrap. Ifinitial_stateis ACTIVE, this should not be None.input_domain (
Domain) – The input domain forqueryable.input_metric (
Metric) – The input metric forqueryable.output_measure (
PureDP|ApproxDP|RhoZCDP) – The output measure forqueryable.d_in (
Any) – The input metric value forqueryable.privacy_budget (
ExactNumber|float|int|str|Fraction|Expr|Tuple[ExactNumber|float|int|str|Fraction|Expr,ExactNumber|float|int|str|Fraction|Expr]) – The privacy budget for thequeryable.parent (
PrivacyAccountant|None) – The parent of thisPrivacyAccountant.
- static launch(measurement, data)#
Returns a
PrivacyAccountantfrom a measurement and data.The returned
PrivacyAccountantisACTIVEand 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
SequentialCompositionto 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’sstatemust be ACTIVEtransformation’sinput_domainmust match thisPrivacyAccountant’sinput_domaintransformation’sinput_metricmust match thisPrivacyAccountant’sinput_metricif
d_outis provided,transformation’sstability_relation()must hold forPrivacyAccountant’sd_inandd_out
After applying
transformation:this
PrivacyAccountant’sinput_domainwill becometransformation’soutput_domainthis
PrivacyAccountant’sinput_metricwill becometransformation’soutput_metricthis
PrivacyAccountant’sd_inwill becometransformation’s d_outif
transformationimplements astability_function(), its d_out is the output of its stability function on thisPrivacyAccountant’sd_inotherwise 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 iftransformationdoes not implement astability_function().
- Raises:
InactiveAccountantError – If this
PrivacyAccountantis 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_domainmust match thisPrivacyAccountant’sinput_domainmeasurement’sinput_metricmust match thisPrivacyAccountant’sinput_metricmeasurement’soutput_measuremust match thisPrivacyAccountant’soutput_measureif
d_outis provided,measurement’sprivacy_relation()must hold forPrivacyAccountant’sd_inandd_outthis
PrivacyAccountant’sprivacy_budgetmust be greater than or equal to themeasurement’s d_outif
measurementimplements aprivacy_function(), its d_out is the output of its privacy function on thisPrivacyAccountant’sd_inotherwise it is the argument
d_out
After answering
measurement:this
PrivacyAccountant’sprivacy_budgetwill 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 ifmeasurementdoes not implement aprivacy_function().
- Raises:
InactiveAccountantError – If this
PrivacyAccountantis not ACTIVE.- Return type:
Any
- split(splitting_transformation, privacy_budget, d_out=None)#
Returns new
PrivacyAccountants from splitting the private data.Uses
splitting_transformationto split the private data into a list of new datasets. A newPrivacyAccountantis 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_domainmust match thisPrivacyAccountant’sinput_domainsplitting_transformation’sinput_metricmustmatch this
PrivacyAccountant’sinput_metric
if
d_outis provided,splitting_transformation’sstability_relation()must hold for thisPrivacyAccountant’sd_inandd_outsplitting_transformation’soutput_domainmust be aListDomainwith a fixedlength.splitting_transformation’soutput_metricmust beSumOfif thisPrivacyAccountant’soutput_measureisPureDPorRootSumOfSquaredif thisPrivacyAccountant’soutput_measureisRhoZCDP
After creating the new
PrivacyAccountants:this
PrivacyAccountant’sprivacy_budgetwill decrease byprivacy_budgetthis
PrivacyAccountant’schildrenwill be a list with the newPrivacyAccountantsthis
PrivacyAccountant’sstatewill become WAITING_FOR_CHILDRENthe new
PrivacyAccountants’input_domainwill be the element domain ofsplitting_transformation’sListDomainthe new
PrivacyAccountants’input_metricwill be the inner metric ofsplitting_transformation’sSumOforRootSumOfSquaredmetricthe new
PrivacyAccountants’output_measurewill be thisPrivacyAccountantsoutput_measurethe new
PrivacyAccountants’d_inwill besplitting_transformation’s d_outif
splitting_transformationimplements astability_function(), its d_out is the output of its stability function on thisPrivacyAccountant’sd_inotherwise it is the argument
d_out
the new
PrivacyAccountants’privacy_budgetwill beprivacy_budgetthe first child
PrivacyAccountant‘sstatewill be ACTIVE and all other childPrivacyAccountants’statewill be WAITING_FOR_SIBLING.
Note
After creating children, the
statewill 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
PrivacyAccountants.d_out (Optional[Any]) – An optional value for the
output_metricforsplitting_transformation. It is only used ifsplitting_transformationdoes not implement astability_function().
- Raises:
InactiveAccountantError – If this
PrivacyAccountantis not ACTIVE.- Return type:
List[PrivacyAccountant]
- force_activate()#
Set this
PrivacyAccountant’s state to ACTIVE.A
PrivacyAccountantmust be ACTIVE to perform actionsSee
PrivacyAccountantStatefor more information.If this
PrivacyAccountantis WAITING_FOR_SIBLING, it retires all preceding siblings. If thisPrivacyAccountantis WAITING_FOR_CHILDREN it retires all of its descendants.- Raises:
RuntimeError – If this
PrivacyAccountantis RETIRED.- Return type:
None
- retire(force=False)#
Set this
PrivacyAccountant’s state to RETIRED.If this
PrivacyAccountantis WAITING_FOR_SIBLING, it also retires all preceding siblings and their descendants. If thisPrivacyAccountantis WAITING_FOR_CHILDREN it also retires all of its descendants.A RETIRED
PrivacyAccountantcannot perform actions, but its properties can still be inspected.See
PrivacyAccountantStatefor more information.- Parameters:
force (bool) – Whether this
PrivacyAccountantcan retire its descendants if thisPrivacyAccountantis WAITING_FOR_CHILDREN.- Raises:
RuntimeError – If this
PrivacyAccountantcannot be set to RETIRED. Ifforceis False, thisPrivacyAccountantcannot be WAITING_FOR_CHILDREN. Ifforceis True,retire()can always be called.RuntimeWarning – If the
PrivacyAccountantis WAITING_FOR_SIBLING.
- Return type:
None
- queue_transformation(transformation, d_out=None)#
Queue
transformationto be executed when this accountant becomes ACTIVE.If this
PrivacyAccountantis ACTIVE, this has the same behavior astransform_in_place().If this
PrivacyAccountantis WAITING_FOR_CHILDREN or WAITING_FOR_SIBLING,transformationwill be applied to the private data when thisPrivacyAccountantbecomes ACTIVE, but otherwise it has the same behavior astransform_in_place()(input_domain,input_metric, andd_inare 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 iftransformationdoes not implement astability_function().
- Return type:
None
Exceptions#
- exception InactiveAccountantError#
Bases:
RuntimeErrorRaised 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.