class_docstr: The Thompson Sampling MAB with Normal-Gamma distribution for rewards.
  Appropriate for MAB with normally distributed rewards.
  We use posterior update equations from
      https://en.wikipedia.org/wiki/Normal-gamma_distribution#Posterior_distribution_of_the_parameters
class_docstr_tok: ["The","Thompson","Sampling","MAB","with","Normal-Gamma","distribution","for","rewards",".","Appropriate","for","MAB","with","normally","distributed","rewards",".","We","use","posterior","update","equations","from","https",":","\/\/en.wikipedia.org\/wiki\/Normal-gamma_distribution","#","Posterior_distribution_of_the_parameters"]
code: def add_batch_observations(
      self,
      n_obs_per_arm: Tensor,
      sum_reward_per_arm: Tensor,
      sum_reward_squared_per_arm: Tensor,
      arm_ids: Optional[List[str]] = None,
  ) -> None:
      (
          n_obs_per_arm,
          sum_reward_per_arm,
          sum_reward_squared_per_arm,
      ) = reindex_multiple_tensors(
          all_ids=self.arm_ids,
          batch_ids=arm_ids,
          value_tensors=(
              n_obs_per_arm,
              sum_reward_per_arm,
              sum_reward_squared_per_arm,
          ),
      )
  
      mean_rewards_batch = torch.nan_to_num(
          sum_reward_per_arm / n_obs_per_arm, nan=0.0
      )
      lambdas = self.lambda_0 + self.total_n_obs_per_arm
      self.gamma_rates += 0.5 * n_obs_per_arm * lambdas / (
          n_obs_per_arm
          + lambdas
          # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and `int`.
      ) * (mean_rewards_batch - self.mus) ** 2 + 0.5 * (
          sum_reward_squared_per_arm
          # pyre-fixme[58]: `**` is not supported for operand types `Tensor` and
          #  `int`.
          - n_obs_per_arm * mean_rewards_batch**2
      )
      self.mus += (sum_reward_per_arm - n_obs_per_arm * self.mus) / (
          n_obs_per_arm + lambdas
      )
      super().add_batch_observations(
          n_obs_per_arm=n_obs_per_arm,
          sum_reward_per_arm=sum_reward_per_arm,
          sum_reward_squared_per_arm=sum_reward_squared_per_arm,
          arm_ids=self.arm_ids,  # pass self.arm_ids instead of arm_ids because we've already reindexed all tensors
      )
  
file_path: ReAgent/reagent/mab/thompson_sampling.py
imports: from abc import abstractmethod
  from typing import List, Optional
  import torch
  from reagent.mab.mab_algorithm import MABAlgo, reindex_multiple_tensors
  from torch import Tensor
label_desc: Use image node_id 3 for calling the NormalGammaThompson obj's underlying member method code with example usage: obj.add_batch_observations(n_obs_per_arm, sum_reward_per_arm, sum_reward_squared_per_arm, arm_ids) without return types