expt: Testing epsilon percentages
This commit is contained in:
		@ -391,6 +391,60 @@ def find_lmdks(seq, lmdks, epsilon):
 | 
			
		||||
    lmdks_new = seq[lmdks_seq_new - 1]
 | 
			
		||||
  return lmdks_new, epsilon - eps_sel
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def find_lmdks_eps(seq, lmdks, epsilon):
 | 
			
		||||
  '''
 | 
			
		||||
    Add dummy landmarks to original landmarks.
 | 
			
		||||
 | 
			
		||||
    Parameters:
 | 
			
		||||
      seq     - All of the data points.
 | 
			
		||||
      lmdks   - The original landmarks.
 | 
			
		||||
      epsilon - The available privacy budget.
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
      lmdks_new - The new landmarks.
 | 
			
		||||
  '''
 | 
			
		||||
  # The new landmarks
 | 
			
		||||
  lmdks_new = lmdks
 | 
			
		||||
  if len(lmdks) > 0 and len(seq) != len(lmdks):
 | 
			
		||||
    # Get landmarks timestamps in sequence
 | 
			
		||||
    lmdks_seq = find_lmdks_seq(seq, lmdks)
 | 
			
		||||
    # Turn landmarks to histogram
 | 
			
		||||
    hist, h = get_hist(get_seq(1, len(seq)), lmdks_seq)
 | 
			
		||||
    # Find all possible options
 | 
			
		||||
    opts = get_opts_from_top_h(get_seq(1, len(seq)), lmdks_seq)
 | 
			
		||||
    # Get landmarks histogram with dummy landmarks
 | 
			
		||||
    hist_new, _ = exp_mech.exponential(hist, opts, exp_mech.score, 1.0, epsilon)
 | 
			
		||||
    # Split sequence in parts of size h 
 | 
			
		||||
    pt_idx = []
 | 
			
		||||
    for idx in range(1, len(seq), h):
 | 
			
		||||
      pt_idx.append([idx, idx + h - 1])
 | 
			
		||||
    pt_idx[-1][1] = len(seq)
 | 
			
		||||
    # Get new landmarks indexes
 | 
			
		||||
    lmdks_seq_new = np.array([], dtype=int)
 | 
			
		||||
    for i, pt in enumerate(pt_idx):
 | 
			
		||||
      # Already landmarks
 | 
			
		||||
      lmdks_seq_pt = lmdks_seq[(lmdks_seq >= pt[0]) & (lmdks_seq <= pt[1])]
 | 
			
		||||
      # Sample randomly from the rest of the sequence
 | 
			
		||||
      size = hist_new[i] - len(lmdks_seq_pt)
 | 
			
		||||
      rglr = np.setdiff1d(np.arange(pt[0], pt[1] + 1), lmdks_seq_pt)
 | 
			
		||||
      # Add already landmarks
 | 
			
		||||
      lmdks_seq_new = np.concatenate([lmdks_seq_new, lmdks_seq_pt])
 | 
			
		||||
      # Add new landmarks
 | 
			
		||||
      if size > 0 and len(rglr) > size:
 | 
			
		||||
        lmdks_seq_new = np.concatenate([lmdks_seq_new,
 | 
			
		||||
          np.random.choice(
 | 
			
		||||
            rglr, 
 | 
			
		||||
            size = size, 
 | 
			
		||||
            replace = False
 | 
			
		||||
          )
 | 
			
		||||
        ])
 | 
			
		||||
    # Get actual landmarks values
 | 
			
		||||
    lmdks_new = seq[lmdks_seq_new - 1]
 | 
			
		||||
  return lmdks_new
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test():
 | 
			
		||||
  # Start and end points of the sequence
 | 
			
		||||
  # # Nonrandom
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user