class_docstr: Compilation tests for using OPE both standalone and in an RLlib Algorithm
class_docstr_tok: ["Compilation","tests","for","using","OPE","both","standalone","and","in","an","RLlib","Algorithm"]
docstr: Test that the IS and WIS estimators work.
  
  First we compute the estimates with RLlib's algorithm and then compare the
  results to the estimates that are manually computed on raw data frame version
  of the dataset to check correctness.
docstr_tok: ["Test","that","the","IS","and","WIS","estimators","work",".","First","we","compute","the","estimates","with","RLlib","'s","algorithm","and","then","compare","the","results","to","the","estimates","that","are","manually","computed","on","raw","data","frame","version","of","the","dataset","to","check","correctness","."]
code: def test_is_wis_on_estimate_on_dataset(self):
      """Test that the IS and WIS estimators work.
  
      First we compute the estimates with RLlib's algorithm and then compare the
      results to the estimates that are manually computed on raw data frame version
      of the dataset to check correctness.
      """
      config = self.dqn_on_fake_ds.copy()
      config = config.evaluation(
          off_policy_estimation_methods={
              "is": {"type": ImportanceSampling},
              "wis": {"type": WeightedImportanceSampling},
          },
      )
      num_actions = config.action_space.n
      algo = config.build()
  
      evaluated_results = algo._run_one_evaluation()
      ope_results = evaluated_results["evaluation"][
          "off_policy_estimator"
      ]
      policy = algo.get_policy()
  
      wis_gain, wis_ste = compute_expected_is_or_wis_estimator(
          self.train_df, policy, num_actions=num_actions, is_wis=True
      )
  
      is_gain, is_ste = compute_expected_is_or_wis_estimator(
          self.train_df, policy, num_actions=num_actions, is_wis=False
      )
  
      check(wis_gain, ope_results["wis"]["v_gain_mean"])
      check(wis_ste, ope_results["wis"]["v_gain_ste"])
      check(is_gain, ope_results["is"]["v_gain_mean"])
      check(is_ste, ope_results["is"]["v_gain_ste"])
  
imports: from typing import TYPE_CHECKING, Tuple
  import copy
  import gymnasium
  import numpy
  import os
  import shutil
  import tempfile
  import pandas
  from pathlib import Path
  import unittest
  import ray
  from ray.data import read_json
  from ray.rllib.algorithms.algorithm import Algorithm
  from ray.rllib.algorithms.dqn import DQNConfig
  from ray.rllib.examples.env.cliff_walking_wall_env import CliffWalkingWallEnv
  from ray.rllib.examples.policy.cliff_walking_wall_policy import CliffWalkingWallPolicy
  from ray.rllib.offline.dataset_reader import DatasetReader
  from ray.rllib.offline.estimators import DirectMethod, DoublyRobust, ImportanceSampling, WeightedImportanceSampling
  from ray.rllib.offline.estimators.fqe_torch_model import FQETorchModel
  from ray.rllib.policy.sample_batch import SampleBatch, concat_samples
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.numpy import convert_to_numpy
  from ray.rllib.utils.test_utils import check
label_desc: Use image node_id 6 for calling the TestOPE obj's underlying member method code with example usage: obj.test_is_wis_on_estimate_on_dataset() without return types