class_docstr: Tests some sanity checks that should pass based on the math of ope methods.
docstr: Tests that the importance sampling methods.
  
  It checks whether is and wis methods outputs are consistent when
  split_batch_by_episode is True or False (RL vs. Bandits)
docstr_tok: ["Tests","that","the","importance","sampling","methods",".","It","checks","whether","is","and","wis","methods","outputs","are","consistent","when","split_batch_by_episode","is","True","or","False","(","RL","vs.","Bandits",")"]
code: def test_is_and_wis_math(self):
      """Tests that the importance sampling methods.
  
      It checks whether is and wis methods outputs are consistent when
      split_batch_by_episode is True or False (RL vs. Bandits)
      """
  
      ope_classes = [
          ImportanceSampling,
          WeightedImportanceSampling,
      ]
  
      for class_module in ope_classes:
          for policy_tag in ["good", "bad"]:
              target_policy = self.policies[policy_tag]
              estimator = class_module(target_policy, gamma=0)
  
              s = time.time()
              estimate_1 = estimator.estimate(
                  self.sample_batch,
                  split_batch_by_episode=True,
              )
              dt1 = time.time() - s
  
              s = time.time()
              estimate_2 = estimator.estimate(
                  self.sample_batch, split_batch_by_episode=False
              )
              dt2 = time.time() - s
  
              if policy_tag == "good":
                  # check if the v_gain is larger than 1
                  self.assertGreater(estimate_1["v_gain"], 1)
              else:
                  self.assertLess(estimate_1["v_gain"], 1)
  
              # check that the estimates are the same for bandit vs RL
              check(estimate_1, estimate_2)
  
              self.assertGreater(
                  dt1,
                  dt2,
                  f"in bandits split_by_episode = False should improve "
                  f"performance, dt_wo_split={dt2}, dt_with_split={dt1}",
              )
  
imports: import unittest
  import time
  import gymnasium
  import torch
  import numpy
  from ray.rllib.offline.estimators import DirectMethod, DoublyRobust, ImportanceSampling, WeightedImportanceSampling
  from ray.rllib.models.torch.torch_action_dist import TorchCategorical
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.policy.torch_policy_v2 import TorchPolicyV2
  from ray.rllib.utils.test_utils import check
  import ray
label_desc: Use image node_id 3 for calling the TestOPEMath obj's underlying member method code with example usage: obj.test_is_and_wis_math() without return types