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",")"]
code: def _process_all_data(self, batch: CBInput) -> None:
      assert batch.reward is not None
      if batch.weight is not None:
          weights = batch.weight
      else:
          weights = torch.ones_like(batch.reward)
      self.sum_weight_all_data_local += weights.sum()
      self.sum_reward_weighted_all_data_local += (
          weights * batch.reward
      ).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_all_data_local += (
          weights.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 1 for calling the PolicyEvaluator obj's underlying member method code with example usage: obj._process_all_data(batch) without return types