예제 #1
0
def kv_en_privkv(kv, epsilon1, epsilon2, set_value=None):
    k, v = int(kv[0]), kv[1]
    if k == 1:
        k = ldplib.perturbation(value=k,
                                perturbed_value=1 - k,
                                epsilon=epsilon1)
        if k == 1:
            discretize_v = ldplib.discretization(v, -1, 1)
            p_k, p_v = 1, ldplib.perturbation(value=discretize_v,
                                              perturbed_value=-discretize_v,
                                              epsilon=epsilon2)
        else:
            p_k, p_v = 0, 0
    else:
        k = ldplib.perturbation(value=k,
                                perturbed_value=1 - k,
                                epsilon=epsilon1)
        if k == 1:
            v = np.random.uniform(low=-1,
                                  high=1) if set_value is None else set_value
            discretize_v = ldplib.discretization(v, -1, 1)
            p_k, p_v = 1, ldplib.perturbation(value=discretize_v,
                                              perturbed_value=-discretize_v,
                                              epsilon=epsilon2)
        else:
            p_k, p_v = 0, 0
    return [p_k, p_v]
예제 #2
0
def encode_duchi(value, epsilon):
    value = dp.discretization(value=value, lower=-1, upper=1)
    value = dp.perturbation(value=value,
                            perturbed_value=-value,
                            epsilon=epsilon)
    value = (np.e**epsilon + 1) / (np.e**epsilon - 1) * value
    return value
예제 #3
0
 def encode(self, v):
     if not -1 <= v <= 1:
         raise Exception(
             "Error, The input domain is [-1, 1], while the input is ", v)
     value = ldplib.discretization(value=v, lower=-1, upper=1)
     value = ldplib.perturbation(value=value,
                                 perturbed_value=-value,
                                 epsilon=self.epsilon)
     return self.C * value