docstr: Return (discounted) sum of rewards.
docstr_tok: ["Return","(","discounted",")","sum","of","rewards","."]
code: def calculate_cumulative_reward(self, gamma: float = 1.0):
      """Return (discounted) sum of rewards."""
      num_transitions = len(self)
      assert num_transitions > 0, "called on empty trajectory"
      rewards = self.reward
      discounts = [gamma**i for i in range(num_transitions)]
      return sum(
          reward * discount
          for reward, discount in zip(rewards, discounts)
      )
  
imports: from abc import ABC, abstractmethod
  from dataclasses import asdict, dataclass, field, fields
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import reagent.core.types
  import torch
  import torch.nn.functional
label_desc: Use image node_id 5 for calling the Trajectory obj's underlying member method code with example usage: obj.calculate_cumulative_reward(gamma) and returns: sum