code: def _complete_horizon_values(self, indices, internals, reward):
      zero = tf_util.constant(value=0, dtype="int")
      one = tf_util.constant(value=1, dtype="int")
      true = tf_util.constant(value=True, dtype="bool")
      reward_horizon = self.reward_horizon.value()
      reward_discount = self.reward_discount.value()
  
      # TODO: no need for memory if update episode-based (or not random replay?)
  
      # Internal values to retrieve, depending on different internals configurations
      baseline_internals_values = "internals/baseline"
      if self.predict_action_values and self.separate_baseline:
          internals_values = "internals"
      elif self.separate_baseline:
          if len(self.internals_spec["baseline"]) > 0:
              internals_values = "internals/baseline"
          else:
              internals_values = None
      else:
          if len(self.internals_spec["policy"]) > 0:
              internals_values = "internals/policy"
              baseline_internals_values = "internals/policy"
          else:
              internals_values = None
  
      if self.baseline.max_past_horizon(on_policy=False) == 0:
          # Horizons indexing tensor
          batch_size = tf_util.cast(
              x=tf.shape(input=indices)[0], dtype="int"
          )
          starts = tf.range(batch_size)
          lengths = tf.ones_like(input=indices)
          horizons = tf.stack(values=(starts, lengths), axis=1)
  
          # TODO: remove restriction
          if self.predict_action_values and self.separate_baseline:
              assert self.policy.max_past_horizon(on_policy=False) == 0
  
          # Retrieve horizon values from memory
          values = ("states", "auxiliaries", "terminal")
          if internals_values is not None:
              values += (internals_values,)
          offsets, values = self.memory.successors(
              indices=indices,
              horizon=reward_horizon,
              sequence_values=(),
              final_values=values,
          )
          states = values["states"]
          policy_internals = values.get("internals/policy")
          baseline_internals = values.get(
              baseline_internals_values, TensorDict()
          )
          auxiliaries = values["auxiliaries"]
          terminal = values["terminal"]
  
          # -1 since successors length >= 1
          offsets = offsets - one
  
      else:
          baseline_horizon = self.baseline.past_horizon(on_policy=False)
          assertions = list()
          if (
              self.config.create_tf_assertions
              and self.predict_action_values
          ):
              policy_horizon = self.policy.past_horizon(on_policy=False)
              # TODO: remove restriction
              assertions.append(
                  tf.debugging.assert_equal(
                      x=policy_horizon,
                      y=baseline_horizon,
                      message="Policy and baseline cannot depend on a different number of "
                      "previous states if predict_action_values is True.",
                  )
              )
  
          with tf.control_dependencies(control_inputs=assertions):
              # (Tried to do this more efficiently by differentiating between
              # reward horizon >/=/< baseline horizon, but gets too complex since
              # it needs to take into account episode start/end edge cases.)
  
              # Retrieve horizon values from memory
              offsets, values = self.memory.successors(
                  indices=indices,
                  horizon=reward_horizon,
                  sequence_values=(),
                  final_values=("auxiliaries", "terminal"),
              )
              auxiliaries = values["auxiliaries"]
              terminal = values["terminal"]
  
              # -1 since successors length >= 1
              offsets = offsets - one
  
              # Retrieve baseline states sequence and initial internals from memory
              if internals_values is None:
                  horizons, sequence_values = self.memory.predecessors(
                      indices=(indices + offsets),
                      horizon=baseline_horizon,
                      sequence_values=("states",),
                      initial_values=(),
                  )
                  policy_internals = None
                  baseline_internals = TensorDict()
              else:
                  (
                      horizons,
                      sequence_values,
                      initial_values,
                  ) = self.memory.predecessors(
                      indices=indices,
                      horizon=(baseline_horizon - reward_horizon),
                      sequence_values=("states",),
                      initial_values=(internals_values,),
                  )
                  policy_internals = initial_values.get(
                      "internals/policy"
                  )
                  baseline_internals = initial_values.get(
                      baseline_internals_values, TensorDict()
                  )
              states = sequence_values["states"]
  
      # Predict horizon values
      if self.predict_action_values:
          actions, _ = self.policy.act(
              states=states,
              horizons=horizons,
              internals=policy_internals,
              auxiliaries=auxiliaries,
              deterministic=true,
              independent=True,
          )
          horizon_values = self.baseline.action_value(
              states=states,
              horizons=horizons,
              internals=baseline_internals,
              auxiliaries=auxiliaries,
              actions=actions,
          )
      else:
          horizon_values = self.baseline.state_value(
              states=states,
              horizons=horizons,
              internals=baseline_internals,
              auxiliaries=auxiliaries,
          )
  
      # Value horizon assertions
      assertions = list()
      if self.config.create_tf_assertions:
          assertions.append(
              tf.debugging.assert_greater_equal(x=offsets, y=zero)
          )
          if self.baseline.max_past_horizon(on_policy=False) == 0:
              baseline_horizon = self.baseline.past_horizon(
                  on_policy=False
              )
          assertions.append(
              tf.debugging.assert_less_equal(
                  x=offsets, y=reward_horizon
              )
          )
  
      # Add appropriately discounted horizon values to reward
      with tf.control_dependencies(control_inputs=assertions):
          # Pow numerically stable since 0.0 <= discount <= 1.0
          discounts = tf.math.pow(
              x=reward_discount,
              y=tf_util.cast(x=offsets, dtype="float"),
          )
          if not self.predict_terminal_values:
              is_terminal = tf.math.equal(x=terminal, y=one)
              zeros = tf.zeros_like(input=discounts)
              discounts = tf.where(
                  condition=is_terminal, x=zeros, y=discounts
              )
  
      return reward + discounts * horizon_values
  
imports: import logging
  import tensorflow
  from tensorforce import TensorforceError
  from tensorforce.core import ModuleDict, memory_modules, optimizer_modules, parameter_modules, SignatureDict, TensorDict, TensorSpec, TensorsSpec, tf_function, tf_util, VariableDict
  from tensorforce.core.models import Model
  from tensorforce.core.networks import Preprocessor
  from tensorforce.core.objectives import objective_modules
  from tensorforce.core.policies import policy_modules, StochasticPolicy
label_desc: Use image node_id 19 for calling the TensorforceModel obj's underlying member method code with example usage: obj._complete_horizon_values(indices, internals, reward) and returns: unknown