class_docstr: An offline evaluator for Contextual Bandits, based on the paper https://arxiv.org/pdf/1003.0146.pdf (Algorithm 3)
class_docstr_tok: ["An","offline","evaluator","for","Contextual","Bandits",",","based","on","the","paper","https",":","\/\/arxiv.org\/pdf\/1003.0146.pdf","(","Algorithm","3",")"]
docstr: Process the observations for which the logged action matches the model action:
      - Update the average reward
      - Update the total weight counter
docstr_tok: ["Process","the","observations","for","which","the","logged","action","matches","the","model","action",":","-","Update","the","average","reward","-","Update","the","total","weight","counter"]
code: def _process_used_data(self, batch: CBInput) -> None:
      """
      Process the observations for which the logged action matches the model action:
          - Update the average reward
          - Update the total weight counter
      """
      assert batch.reward is not None
      assert batch.importance_weight is not None
      assert batch.importance_weight.shape == batch.reward.shape
      if batch.weight is not None:
          weights = batch.weight
      else:
          weights = torch.ones_like(batch.reward)
      assert weights.shape == batch.importance_weight.shape
      self.sum_reward_importance_weighted_accepted_local += (
          batch.effective_weight * batch.reward
      ).sum()
      accepted_indicators = (batch.importance_weight > 0).float()
      self.sum_reward_weighted_accepted_local += (
          weights * accepted_indicators * batch.reward
      ).sum()
      self.sum_weight_accepted_local += (
          weights * accepted_indicators
      ).sum()
      self.sum_importance_weight_accepted_local += (
          batch.effective_weight.sum()
      )
      if batch.arm_presence is not None:
          sizes = batch.arm_presence.sum(1)
      else:
          # assume that all arms are present
          sizes = (
              torch.ones_like(batch.reward)
              * batch.context_arm_features.shape[1]
          )
      self.sum_size_weighted_accepted_local += (
          (weights * accepted_indicators).squeeze() * sizes
      ).sum()
  
file_path: ReAgent/reagent/evaluation/cb/policy_evaluator.py
imports: import logging
  import torch
  from pytorch_lightning.utilities.distributed import ReduceOp, sync_ddp_if_available
  from reagent.core.types import CBInput
  from reagent.evaluation.cb.base_evaluator import BaseOfflineEval
label_desc: Use image node_id 2 for calling the PolicyEvaluator obj's underlying member method code with example usage: obj._process_used_data(batch) without return types