code: def get_actor_core(
      networks: r2d2_networks.R2D2Networks,
      num_epsilons: Optional[int],
      evaluation_epsilon: Optional[float] = None,
  ) -> R2D2Policy:
      """Returns ActorCore for R2D2."""
  
      if (not num_epsilons and evaluation_epsilon is None) or (
          num_epsilons and evaluation_epsilon
      ):
          raise ValueError(
              "Exactly one of `num_epsilons` or `evaluation_epsilon` must be "
              f"specified. Received num_epsilon={num_epsilons} and "
              f"evaluation_epsilon={evaluation_epsilon}."
          )
  
      def select_action(
          params: networks_lib.Params,
          observation: networks_lib.Observation,
          state: R2D2ActorState[actor_core_lib.RecurrentState],
      ):
          rng, policy_rng = jax.random.split(state.rng)
  
          q_values, recurrent_state = networks.apply(
              params, policy_rng, observation, state.recurrent_state
          )
          action = rlax.epsilon_greedy(state.epsilon).sample(
              policy_rng, q_values
          )
  
          return action, R2D2ActorState(
              rng=rng,
              epsilon=state.epsilon,
              recurrent_state=recurrent_state,
              prev_recurrent_state=state.recurrent_state,
          )
  
      def init(
          rng: networks_lib.PRNGKey,
      ) -> R2D2ActorState[actor_core_lib.RecurrentState]:
          rng, epsilon_rng, state_rng = jax.random.split(rng, 3)
          if num_epsilons:
              epsilon = jax.random.choice(
                  epsilon_rng, np.logspace(1, 3, num_epsilons, base=0.1)
              )
          else:
              epsilon = evaluation_epsilon
          initial_core_state = networks.init_recurrent_state(
              state_rng, None
          )
          return R2D2ActorState(
              rng=rng,
              epsilon=epsilon,
              recurrent_state=initial_core_state,
              prev_recurrent_state=initial_core_state,
          )
  
      def get_extras(
          state: R2D2ActorState[actor_core_lib.RecurrentState],
      ) -> R2D2Extras:
          return {"core_state": state.prev_recurrent_state}
  
      return actor_core_lib.ActorCore(
          init=init, select_action=select_action, get_extras=get_extras
      )
  
file_path: acme/acme/agents/jax/r2d2/actor.py
imports: from typing import Callable, Generic, Mapping, Optional, Tuple
  from acme import types
  from acme.agents.jax import actor_core
  from acme.agents.jax.r2d2 import config
  from acme.agents.jax.r2d2 import networks
  from acme.jax import networks
  import chex
  import jax
  import jax.numpy
  import numpy
  import rlax
label_desc: Use image node_id 1 for calling a global function with example usage: get_actor_core(networks, num_epsilons, evaluation_epsilon) and returns: actor_core_lib, action,  R2D2ActorState, R2D2ActorState, dict