code: def _compute_membership_probability(
      attack_input: AttackInputData, num_bins: int = 15
  ) -> SingleMembershipProbabilityResult:
      """Computes each individual point's likelihood of being a member (denoted as privacy risk score in https://arxiv.org/abs/2003.10595).
  
      For an individual sample, its privacy risk score is computed as the posterior
      probability of being in the training set
      after observing its prediction output by the target machine learning model.
  
      Args:
        attack_input: input data for compute membership probability
        num_bins: the number of bins used to compute the training/test histogram
  
      Returns:
        membership probability results
      """
  
      # Uses the provided loss or entropy. Otherwise computes the loss.
      if (
          attack_input.loss_train is not None
          and attack_input.loss_test is not None
      ):
          train_values = attack_input.loss_train
          test_values = attack_input.loss_test
      elif (
          attack_input.entropy_train is not None
          and attack_input.entropy_test is not None
      ):
          train_values = attack_input.entropy_train
          test_values = attack_input.entropy_test
      else:
          train_values = attack_input.get_loss_train()
          test_values = attack_input.get_loss_test()
  
      # Compute the histogram in the log scale
      small_value = 1e-10
      train_values = np.maximum(train_values, small_value)
      test_values = np.maximum(test_values, small_value)
  
      min_value = min(train_values.min(), test_values.min())
      max_value = max(train_values.max(), test_values.max())
      bins_hist = np.logspace(
          np.log10(min_value), np.log10(max_value), num_bins + 1
      )
  
      train_hist, _ = np.histogram(train_values, bins=bins_hist)
      train_hist = train_hist / (len(train_values) + 0.0)
      train_hist_indices = (
          np.fmin(np.digitize(train_values, bins=bins_hist), num_bins)
          - 1
      )
  
      test_hist, _ = np.histogram(test_values, bins=bins_hist)
      test_hist = test_hist / (len(test_values) + 0.0)
      test_hist_indices = (
          np.fmin(np.digitize(test_values, bins=bins_hist), num_bins)
          - 1
      )
  
      combined_hist = train_hist + test_hist
      combined_hist[combined_hist == 0] = small_value
      membership_prob_list = train_hist / (combined_hist + 0.0)
      train_membership_probs = membership_prob_list[train_hist_indices]
      test_membership_probs = membership_prob_list[test_hist_indices]
  
      return SingleMembershipProbabilityResult(
          slice_spec=_get_slice_spec(attack_input),
          train_membership_probs=train_membership_probs,
          test_membership_probs=test_membership_probs,
      )
  
imports: import logging
  from typing import Iterable, List, Optional, Union
  import numpy
  from scipy import special
  from sklearn import metrics
  from sklearn import model_selection
  from tensorflow_privacy.privacy.privacy_tests import epsilon_lower_bound
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack import models
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackInputData
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackResults
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackType
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import DataSize
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EPSILON_ALPHA
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EPSILON_K
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EPSILON_METHODS
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import EpsilonLowerBoundValue
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import MembershipProbabilityResults
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import PrivacyReportMetadata
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import RocCurve
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleAttackResult
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleMembershipProbabilityResult
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleSliceSpec
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SlicingSpec
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.dataset_slicing import get_single_slice_specs
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.dataset_slicing import get_slice
label_desc: Use image node_id 7 for calling a global function with example usage: _compute_membership_probability(attack_input, num_bins) and returns: SingleMembershipProbabilityResult