class_docstr: Returns private cumulative sums by clipping and adding correlated noise.
  
  Consider calling `get_noised_result` T times, and each (x_i, i=0,2,...,T-1) is
  the private value returned by `accumulate_record`, i.e. x_i = sum_{j=0}^{n-1}
  x_{i,j} where each x_{i,j} is a private record in the database. This class is
  intended to make multiple queries, which release privatized values of the
  cumulative sums s_i = sum_{k=0}^{i} x_k, for i=0,...,T-1.
  Each call to `get_noised_result` releases the next cumulative sum s_i, which
  is in contrast to the GaussianSumQuery that releases x_i. Noise for the
  cumulative sums is accomplished using the tree aggregation logic in
  `tree_aggregation`, which is proportional to log(T).
  
  Example usage:
    query = TreeCumulativeSumQuery(...)
    global_state = query.initial_global_state()
    params = query.derive_sample_params(global_state)
    for i, samples in enumerate(streaming_samples):
      sample_state = query.initial_sample_state(samples[0])
      # Compute  x_i = sum_{j=0}^{n-1} x_{i,j}
      for j,sample in enumerate(samples):
        sample_state = query.accumulate_record(params, sample_state, sample)
      # noised_cumsum is privatized estimate of s_i
      noised_cumsum, global_state, event = query.get_noised_result(
        sample_state, global_state)
  
  Attributes:
    clip_fn: Callable that specifies clipping function. `clip_fn` receives two
      arguments: a flat list of vars in a record and a `clip_value` to clip the
        corresponding record, e.g. clip_fn(flat_record, clip_value).
    clip_value: float indicating the value at which to clip the record.
    record_specs: `Collection[tf.TensorSpec]` specifying shapes of records.
    tree_aggregator: `tree_aggregation.TreeAggregator` initialized with user
      defined `noise_generator`. `noise_generator` is a
      `tree_aggregation.ValueGenerator` to generate the noise value for a tree
      node. Noise stdandard deviation is specified outside the `dp_query` by the
      user when defining `noise_fn` and should have order
      O(clip_norm*log(T)/eps) to guarantee eps-DP.
class_docstr_tok: ["Returns","private","cumulative","sums","by","clipping","and","adding","correlated","noise",".","Consider","calling","`","get_noised_result","`","T","times",",","and","each","(","x_i",",","i=0,2",",","...",",","T-1",")","is","the","private","value","returned","by","`","accumulate_record","`",",","i.e",".","x_i","=","sum_","{","j=0","}","^","{","n-1","}","x_","{","i",",","j","}","where","each","x_","{","i",",","j","}","is","a","private","record","in","the","database",".","This","class","is","intended","to","make","multiple","queries",",","which","release","privatized","values","of","the","cumulative","sums","s_i","=","sum_","{","k=0","}","^","{","i","}","x_k",",","for","i=0",",","...",",","T-1",".","Each","call","to","`","get_noised_result","`","releases","the","next","cumulative","sum","s_i",",","which","is","in","contrast","to","the","GaussianSumQuery","that","releases","x_i",".","Noise","for","the","cumulative","sums","is","accomplished","using","the","tree","aggregation","logic","in","`","tree_aggregation","`",",","which","is","proportional","to","log","(","T",")",".","Example","usage",":","query","=","TreeCumulativeSumQuery","(","...",")","global_state","=","query.initial_global_state","(",")","params","=","query.derive_sample_params","(","global_state",")","for","i",",","samples","in","enumerate","(","streaming_samples",")",":","sample_state","=","query.initial_sample_state","(","samples","[","0","]",")","#","Compute","x_i","=","sum_","{","j=0","}","^","{","n-1","}","x_","{","i",",","j","}","for","j",",","sample","in","enumerate","(","samples",")",":","sample_state","=","query.accumulate_record","(","params",",","sample_state",",","sample",")","#","noised_cumsum","is","privatized","estimate","of","s_i","noised_cumsum",",","global_state",",","event","=","query.get_noised_result","(","sample_state",",","global_state",")","Attributes",":","clip_fn",":","Callable","that","specifies","clipping","function",".","`","clip_fn","`","receives","two","arguments",":","a","flat","list","of","vars","in","a","record","and","a","`","clip_value","`","to","clip","the","corresponding","record",",","e.g",".","clip_fn","(","flat_record",",","clip_value",")",".","clip_value",":","float","indicating","the","value","at","which","to","clip","the","record",".","record_specs",":","`","Collection","[","tf.TensorSpec","]","`","specifying","shapes","of","records",".","tree_aggregator",":","`","tree_aggregation.TreeAggregator","`","initialized","with","user","defined","`","noise_generator","`",".","`","noise_generator","`","is","a","`","tree_aggregation.ValueGenerator","`","to","generate","the","noise","value","for","a","tree","node",".","Noise","stdandard","deviation","is","specified","outside","the","`","dp_query","`","by","the","user","when","defining","`","noise_fn","`","and","should","have","order","O","(","clip_norm","*","log","(","T",")","\/eps",")","to","guarantee","eps-DP","."]
docstr: Implements `tensorflow_privacy.DPQuery.get_noised_result`.
  
  Updates tree state, and returns noised cumulative sum and updated state.
  
  Computes new cumulative sum, and returns its noised value. Grows tree state
  by one new leaf, and returns the new state.
  
  Args:
    sample_state: Sum of clipped records for this round.
    global_state: Global state with current sample's cumulative sum and tree
      state.
  
  Returns:
    A tuple of (noised_cumulative_sum, new_global_state).
docstr_tok: ["Implements","`","tensorflow_privacy.DPQuery.get_noised_result","`",".","Updates","tree","state",",","and","returns","noised","cumulative","sum","and","updated","state",".","Computes","new","cumulative","sum",",","and","returns","its","noised","value",".","Grows","tree","state","by","one","new","leaf",",","and","returns","the","new","state",".","Args",":","sample_state",":","Sum","of","clipped","records","for","this","round",".","global_state",":","Global","state","with","current","sample","'s","cumulative","sum","and","tree","state",".","Returns",":","A","tuple","of","(","noised_cumulative_sum",",","new_global_state",")","."]
code: def get_noised_result(self, sample_state, global_state):
      """Implements `tensorflow_privacy.DPQuery.get_noised_result`.
  
      Updates tree state, and returns noised cumulative sum and updated state.
  
      Computes new cumulative sum, and returns its noised value. Grows tree state
      by one new leaf, and returns the new state.
  
      Args:
        sample_state: Sum of clipped records for this round.
        global_state: Global state with current sample's cumulative sum and tree
          state.
  
      Returns:
        A tuple of (noised_cumulative_sum, new_global_state).
      """
      new_cumulative_sum = tf.nest.map_structure(
          tf.add, global_state.samples_cumulative_sum, sample_state
      )
      (
          cumulative_sum_noise,
          new_tree_state,
      ) = self._tree_aggregator.get_cumsum_and_update(
          global_state.tree_state
      )
      noised_cumulative_sum = tf.nest.map_structure(
          tf.add, new_cumulative_sum, cumulative_sum_noise
      )
      new_global_state = TreeCumulativeSumQuery.GlobalState(
          tree_state=new_tree_state,
          clip_value=global_state.clip_value,
          samples_cumulative_sum=new_cumulative_sum,
      )
      event = dp_accounting.UnsupportedDpEvent()
      return noised_cumulative_sum, new_global_state, event
  
imports: import collections
  from typing import Any, NamedTuple
  import dp_accounting
  import tensorflow
  from tensorflow_privacy.privacy.dp_query import dp_query
  from tensorflow_privacy.privacy.dp_query import tree_aggregation
label_desc: Use image node_id 5 for calling the TreeCumulativeSumQuery obj's underlying member method code with example usage: obj.get_noised_result(sample_state, global_state) and returns: noised_cumulative_sum,  new_global_state,  event