class_docstr: The step-wise WIS estimator.
  
  Let s_t, a_t, and r_t be the state, action, and reward at timestep t.
  
  For behavior policy \pi_b and evaluation policy \pi_e, define the
  cumulative importance ratio at timestep t as:
  p_t = \sum_{t'=0}^t (\pi_e(a_{t'} | s_{t'}) / \pi_b(a_{t'} | s_{t'})).
  
  Define the average importance ratio over episodes i in the dataset D as:
  w_t = \sum_{i \in D} p^(i)_t / |D|
  
  This estimator computes the expected return for \pi_e for an episode as:
  V^{\pi_e}(s_0) = \E[\sum_t \gamma ^ {t} * (p_t / w_t) * r_t]
  and returns the mean and standard deviation over episodes.
  
  For more information refer to https://arxiv.org/pdf/1911.06854.pdf
class_docstr_tok: ["The","step-wise","WIS","estimator",".","Let","s_t",",","a_t",",","and","r_t","be","the","state",",","action",",","and","reward","at","timestep","t.","For","behavior","policy","\\pi_b","and","evaluation","policy","\\pi_e",",","define","the","cumulative","importance","ratio","at","timestep","t","as",":","p_t","=","\\sum_","{","t'=0","}","^t","(","\\pi_e","(","a_","{","t","'","}","|","s_","{","t","'","}",")","\/","\\pi_b","(","a_","{","t","'","}","|","s_","{","t","'","}",")",")",".","Define","the","average","importance","ratio","over","episodes","i","in","the","dataset","D","as",":","w_t","=","\\sum_","{","i","\\in","D","}","p^","(","i",")","_t","\/","|D|","This","estimator","computes","the","expected","return","for","\\pi_e","for","an","episode","as",":","V^","{","\\pi_e","}","(","s_0",")","=","\\E","[","\\sum_t","\\gamma","^","{","t","}","*","(","p_t","\/","w_t",")","*","r_t","]","and","returns","the","mean","and","standard","deviation","over","episodes",".","For","more","information","refer","to","https",":","\/\/arxiv.org\/pdf\/1911.06854.pdf"]
code: def estimate_on_single_episode(
      self, episode: SampleBatch
  ) -> Dict[str, Any]:
      estimates_per_epsiode = {}
      rewards = episode["rewards"]
  
      eps_id = episode[SampleBatch.EPS_ID][0]
      if eps_id not in self.p:
          raise ValueError(
              f"Cannot find target weight for episode {eps_id}. "
              f"Did it go though the peek_on_single_episode() function?"
          )
  
      # calculate stepwise weighted IS estimate
      v_behavior = 0.0
      v_target = 0.0
      episode_p = self.p[eps_id]
      for t in range(episode.count):
          v_behavior += rewards[t] * self.gamma**t
          w_t = (
              self.cummulative_ips_values[t]
              / self.episode_timestep_count[t]
          )
          v_target += episode_p[t] / w_t * rewards[t] * self.gamma**t
  
      estimates_per_epsiode["v_behavior"] = v_behavior
      estimates_per_epsiode["v_target"] = v_target
  
      return estimates_per_epsiode
  
file_path: ray/rllib/offline/estimators/weighted_importance_sampling.py
imports: from typing import Dict, Any, List
  import numpy
  import math
  from ray.data import Dataset
  from ray.rllib.offline.offline_evaluator import OfflineEvaluator
  from ray.rllib.offline.estimators.off_policy_estimator import OffPolicyEstimator
  from ray.rllib.offline.offline_evaluation_utils import remove_time_dim, compute_is_weights
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.policy import Policy
  from ray.rllib.utils.annotations import override, DeveloperAPI
label_desc: Use image node_id 2 for calling the WeightedImportanceSampling obj's underlying member method code with example usage: obj.estimate_on_single_episode(episode) and returns: estimates_per_epsiode