对参与者进行泊松子采样的联合学习过程

问题描述

我正在用 TFF 进行一些实验。在这一个中,我想根据 poisson subsampling 在每次训练中对参与的客户进行抽样,其中每个客户的抽样概率为 p = users_per_round / num_users

在每一轮中,执行 poisson subsampling 直到列表 sampled_ids唯一 ids 填充,其数量等于 users_per_round数量

total_rounds = 100
num_users = 500
users_per_round = 150
lambda_value = np.random.rand()

for round_num in range(total_rounds):

   sampled_ids = []

   while len(sampled_ids) < users_per_round:

      subsampling = np.random.poisson(lambda_value,num_users)
      whether = subsampling > 1 - users_per_round / num_users
      for i in np.arange(num_users):
          if whether[i] and len(sampled_ids) < users_per_round and i 
             not in sampled_ids:
                  sampled_ids.append(i)


  sampled_clients = [train_data.client_ids[i] for i in sampled_ids]

  sampled_train_data = 
     [train_data.create_tf_dataset_for_client(client) for client in 
         sampled_clients]

  server_state,train_metrics = iterative_process.next(server_state,sampled_train_data)

是否有更好的方法来执行 poisson subsampling,特别是如果在 differentially private FL 中应用二次抽样,以便 RDP accountant 产生准确的隐私分析结果?

设置 lambda 值而不是 random 值的最佳策略是什么?

解决方法

泊松子采样意味着每个用户都以概率 q 被包含在内。如果 q 很小,您从这个过程中获得的每一轮的用户数量近似泊松分布。如果您希望样本按预期您在一轮中拥有 users_per_round 个用户,您可以执行以下操作:

users_this_round = np.random.poisson(users_per_round)
sampled_ids = np.random.choice(num_users,size=users_this_round,replace=False)

如果您想精确地选择 users_per_round 个用户(这在技术上不是泊松子采样),您可以这样做:

sampled_ids = np.random.choice(num_users,size=users_per_round,replace=False)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...