code: def membership_accuracy(
      model, positive_set, negative_set, epsilon=0.0
  ):
      """
      Measure accuracy of membership inference attacks on model using the specified
      positive and negative data sets.
      """
  
      # compute weights for all arms:
      weights = (
          model["b"].unsqueeze(1).matmul(model["A_inv"]).squeeze(1)
      )
      weights = weights.type(torch.float32)
  
      # compute rewards for both sets:
      rewards = {
          "positive": compute_rewards(
              weights, positive_set, epsilon=epsilon
          ),
          "negative": compute_rewards(
              weights, negative_set, epsilon=epsilon
          ),
      }
  
      def p_reward(x):
          return torch.sum(x).type(torch.float32) / x.numel()
  
      p_reward_pos = p_reward(rewards["positive"])
      p_reward_neg = p_reward(rewards["negative"])
      advantage = (p_reward_pos - p_reward_neg).abs().item()
      return advantage
  
file_path: CrypTen/examples/bandits/membership_inference.py
imports: import argparse
  import logging
  import os
  import pickle
  import examples.util
  import torch
  import visdom
  from examples.multiprocess_launcher import MultiProcessLauncher
label_desc: Use image node_id 2 for calling a global function with example usage: membership_accuracy(model, positive_set, negative_set, epsilon) and returns: advantage, unknown