class_docstr: The Direct Method estimator.
  
  Let s_t, a_t, and r_t be the state, action, and reward at timestep t.
  
  This method trains a Q-model for the evaluation policy \pi_e on behavior
  data generated by \pi_b. Currently, RLlib implements this using
  Fitted-Q Evaluation (FQE). You can also implement your own model
  and pass it in as `q_model_config = {"type": your_model_class, **your_kwargs}`.
  
  This estimator computes the expected return for \pi_e for an episode as:
  V^{\pi_e}(s_0) = \sum_{a \in A} \pi_e(a | s_0) Q(s_0, a)
  and returns the mean and standard deviation over episodes.
  
  For more information refer to https://arxiv.org/pdf/1911.06854.pdf
docstr: Initializes a Direct Method OPE Estimator.
  
  Args:
      policy: Policy to evaluate.
      gamma: Discount factor of the environment.
      epsilon_greedy: The probability by which we act acording to a fully random
          policy during deployment. With 1-epsilon_greedy we act according the
          target policy.
      q_model_config: Arguments to specify the Q-model. Must specify
          a `type` key pointing to the Q-model class.
          This Q-model is trained in the train() method and is used
          to compute the state-value estimates for the DirectMethod estimator.
          It must implement `train` and `estimate_v`.
          TODO (Rohan138): Unify this with RLModule API.
docstr_tok: ["Initializes","a","Direct","Method","OPE","Estimator",".","Args",":","policy",":","Policy","to","evaluate",".","gamma",":","Discount","factor","of","the","environment",".","epsilon_greedy",":","The","probability","by","which","we","act","acording","to","a","fully","random","policy","during","deployment",".","With","1-epsilon_greedy","we","act","according","the","target","policy",".","q_model_config",":","Arguments","to","specify","the","Q-model",".","Must","specify","a","`","type","`","key","pointing","to","the","Q-model","class",".","This","Q-model","is","trained","in","the","train","(",")","method","and","is","used","to","compute","the","state-value","estimates","for","the","DirectMethod","estimator",".","It","must","implement","`","train","`","and","`","estimate_v","`",".","TODO","(","Rohan138",")",":","Unify","this","with","RLModule","API","."]
code: def __init__(
      self,
      policy: Policy,
      gamma: float,
      epsilon_greedy: float = 0.0,
      q_model_config: Optional[Dict] = None,
  ):
      """Initializes a Direct Method OPE Estimator.
  
      Args:
          policy: Policy to evaluate.
          gamma: Discount factor of the environment.
          epsilon_greedy: The probability by which we act acording to a fully random
              policy during deployment. With 1-epsilon_greedy we act according the
              target policy.
          q_model_config: Arguments to specify the Q-model. Must specify
              a `type` key pointing to the Q-model class.
              This Q-model is trained in the train() method and is used
              to compute the state-value estimates for the DirectMethod estimator.
              It must implement `train` and `estimate_v`.
              TODO (Rohan138): Unify this with RLModule API.
      """
  
      super().__init__(policy, gamma, epsilon_greedy)
  
      # Some dummy policies and ones that are not based on a tensor framework
      # backend can come without a config or without a framework key.
      if hasattr(policy, "config"):
          assert (
              policy.config.get("framework", "torch") == "torch"
          ), "Framework must be torch to use DirectMethod."
  
      q_model_config = q_model_config or {}
      model_cls = q_model_config.pop("type", FQETorchModel)
      self.model = model_cls(
          policy=policy,
          gamma=gamma,
          **q_model_config,
      )
      assert hasattr(
          self.model, "estimate_v"
      ), "self.model must implement `estimate_v`!"
  
imports: import logging
  from typing import Dict, Any, Optional, List
  import math
  import numpy
  from ray.data import Dataset
  from ray.rllib.offline.estimators.off_policy_estimator import OffPolicyEstimator
  from ray.rllib.offline.offline_evaluation_utils import compute_q_and_v_values
  from ray.rllib.offline.offline_evaluator import OfflineEvaluator
  from ray.rllib.offline.estimators.fqe_torch_model import FQETorchModel
  from ray.rllib.policy import Policy
  from ray.rllib.policy.sample_batch import convert_ma_batch_to_sample_batch
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.annotations import DeveloperAPI, override
  from ray.rllib.utils.typing import SampleBatchType
  from ray.rllib.utils.numpy import convert_to_numpy
label_desc: Use image node_id 1 to create a new DirectMethod object from inherited base classes: OffPolicyEstimator with example: obj = DirectMethod(policy, gamma, epsilon_greedy, q_model_config)