class_docstr: For details, visit https://arxiv.org/pdf/1612.01205.pdf
class_docstr_tok: ["For","details",",","visit","https",":","\/\/arxiv.org\/pdf\/1612.01205.pdf"]
docstr: Split the data into training, validation and evaluation parts.
  Training and validation and used for model training to estimate
  the importance weights.
  Only evaluation data is used for policy estimation.
  
  This function is used for BOP-E and Estimated Propensity Score methods,
  but not for the standard Doubly Robust estimator.
docstr_tok: ["Split","the","data","into","training",",","validation","and","evaluation","parts",".","Training","and","validation","and","used","for","model","training","to","estimate","the","importance","weights",".","Only","evaluation","data","is","used","for","policy","estimation",".","This","function","is","used","for","BOP-E","and","Estimated","Propensity","Score","methods",",","but","not","for","the","standard","Doubly","Robust","estimator","."]
code: def _split_data(
      self,
      edp: EvaluationDataPage,
      frac_train: float = DEFAULT_FRAC_TRAIN,
      frac_valid: float = DEFAULT_FRAC_VALID,
  ) -> TrainValidEvalData:
      """
      Split the data into training, validation and evaluation parts.
      Training and validation and used for model training to estimate
      the importance weights.
      Only evaluation data is used for policy estimation.
  
      This function is used for BOP-E and Estimated Propensity Score methods,
      but not for the standard Doubly Robust estimator.
      """
      num_examples = edp.model_propensities.shape[0]
      # split data into training, validation and eval
      indices = np.random.permutation(num_examples)
      idx_train = indices[0 : int(frac_train * num_examples)]
      idx_valid = indices[
          int(frac_train * num_examples) : int(
              (frac_train + frac_valid) * num_examples
          )
      ]
      idx_eval = indices[
          int((frac_train + frac_valid) * num_examples) :
      ]
      if edp.contexts is None:
          raise ValueError("contexts not provided in input")
      contexts_dict = {
          "train": edp.contexts[idx_train],
          # pyre-fixme[16]: `Optional` has no attribute `__getitem__`.
          "valid": edp.contexts[idx_valid],
          "eval": edp.contexts[idx_eval],
      }
      model_propensities_dict = {
          "train": edp.model_propensities[idx_train],
          "valid": edp.model_propensities[idx_valid],
          "eval": edp.model_propensities[idx_eval],
      }
      # edp.action_mask is N*N_actions tensor of indicators of which actions
      # were actually taken by the logged algo
      actions_logged = torch.max(edp.action_mask, dim=1, keepdim=True)[
          1
      ].float()
      actions_logged_dict = {
          "train": actions_logged[idx_train],
          "valid": actions_logged[idx_valid],
          "eval": actions_logged[idx_eval],
      }
      action_mask_dict = {
          "train": edp.action_mask[idx_train],
          "valid": edp.action_mask[idx_valid],
          "eval": edp.action_mask[idx_eval],
      }
      logged_rewards_dict = {
          "train": edp.logged_rewards[idx_train],
          "valid": edp.logged_rewards[idx_valid],
          "eval": edp.logged_rewards[idx_eval],
      }
      model_rewards_dict = {
          "train": edp.model_rewards[idx_train],
          "valid": edp.model_rewards[idx_valid],
          "eval": edp.model_rewards[idx_eval],
      }
      model_rewards_for_logged_action_dict = {
          "train": edp.model_rewards_for_logged_action[idx_train],
          "valid": edp.model_rewards_for_logged_action[idx_valid],
          "eval": edp.model_rewards_for_logged_action[idx_eval],
      }
      logged_propensities_dict = {
          "train": edp.logged_propensities[idx_train],
          "valid": edp.logged_propensities[idx_valid],
          "eval": edp.logged_propensities[idx_eval],
      }
      num_examples_dict = {
          "train": int(frac_train * num_examples),
          "valid": int((frac_train + frac_valid) * num_examples)
          - int(frac_train * num_examples),
          "eval": num_examples
          - int((frac_train + frac_valid) * num_examples),
      }
      return TrainValidEvalData(
          contexts_dict=contexts_dict,
          model_propensities_dict=model_propensities_dict,
          actions_logged_dict=actions_logged_dict,
          action_mask_dict=action_mask_dict,
          logged_rewards_dict=logged_rewards_dict,
          model_rewards_dict=model_rewards_dict,
          model_rewards_for_logged_action_dict=model_rewards_for_logged_action_dict,
          logged_propensities_dict=logged_propensities_dict,
          num_examples_dict=num_examples_dict,
      )
  
imports: import logging
  from dataclasses import dataclass
  from typing import Dict, NamedTuple, Optional, Tuple, Union
  import numpy
  import torch
  from reagent.evaluation.cpe import bootstrapped_std_error_of_mean, CpeEstimate
  from reagent.evaluation.evaluation_data_page import EvaluationDataPage
  from torch import Tensor
label_desc: Use image node_id 1 for calling the DoublyRobustEstimator obj's underlying member method code with example usage: obj._split_data(edp, frac_train, frac_valid) and returns: TrainValidEvalData