code: def categorical_td_learning(
      v_atoms_tm1: Array,
      v_logits_tm1: Array,
      r_t: Numeric,
      discount_t: Numeric,
      v_atoms_t: Array,
      v_logits_t: Array,
      stop_target_gradients: bool = True,
  ) -> Numeric:
      """Implements TD-learning for categorical value distributions.
  
      See "A Distributional Perspective on Reinforcement Learning", by
      Bellemere, Dabney and Munos (https://arxiv.org/pdf/1707.06887.pdf).
  
      Args:
        v_atoms_tm1: atoms of V distribution at time t-1.
        v_logits_tm1: logits of V distribution at time t-1.
        r_t: reward at time t.
        discount_t: discount at time t.
        v_atoms_t: atoms of V distribution at time t.
        v_logits_t: logits of V distribution at time t.
        stop_target_gradients: bool indicating whether or not to apply stop gradient
          to targets.
  
      Returns:
        Categorical Q learning loss (i.e. temporal difference error).
      """
      chex.assert_rank(
          [
              v_atoms_tm1,
              v_logits_tm1,
              r_t,
              discount_t,
              v_atoms_t,
              v_logits_t,
          ],
          [1, 1, 0, 0, 1, 1],
      )
      chex.assert_type(
          [
              v_atoms_tm1,
              v_logits_tm1,
              r_t,
              discount_t,
              v_atoms_t,
              v_logits_t,
          ],
          [float, float, float, float, float, float],
      )
  
      # Scale and shift time-t distribution atoms by discount and reward.
      target_z = r_t + discount_t * v_atoms_t
  
      # Convert logits to distribution.
      v_t_probs = jax.nn.softmax(v_logits_t)
  
      # Project using the Cramer distance and maybe stop gradient flow to targets.
      target = categorical_l2_project(target_z, v_t_probs, v_atoms_tm1)
      target = jax.lax.select(
          stop_target_gradients, jax.lax.stop_gradient(target), target
      )
  
      # Compute loss (i.e. temporal difference error).
      return distributions.categorical_cross_entropy(
          labels=target, logits=v_logits_tm1
      )
  
imports: from typing import Union
  import chex
  import jax
  import jax.numpy
  from rlax._src import base
  from rlax._src import clipping
  from rlax._src import distributions
  from rlax._src import multistep
label_desc: Use image node_id 15 for calling a global function with example usage: categorical_td_learning(v_atoms_tm1, v_logits_tm1, r_t, discount_t, v_atoms_t, v_logits_t, stop_target_gradients) and returns: distributions