class_docstr: A Behavioral Cloning agent.
  
  # pyformat: disable
  Implements a generic form of BehavioralCloning that can also be used to pipe
  supervised learning through TF-Agents. By default the agent defines two types
  of losses.
  
  For discrete actions the agent uses:
  
  ```python
  def discrete_loss(agent, experience, training=False):
    bc_logits = self._cloning_network(experience.observation, training=training)
  
    return tf.nn.sparse_softmax_cross_entropy_with_logits(
      labels=experience.action - action_spec.minimum, logits=bc_logits)
  ```
  
  This requires a Network that generates `num_action` Q-values. In the case of
  continuous actions a simple MSE loss is used by default:
  
  ```python
  def continuous_loss_fn(agent, experience, training=False):
    bc_output, _ = self._cloning_network(
        experience.observation,
        step_type=experience.step_type,
        training=training,
        network_state=network_state)
  
    if isinstance(bc_output, tfp.distributions.Distribution):
      bc_action = bc_output.sample()
    else:
      bc_action = bc_output
  
    return tf.losses.mse(experience.action, bc_action)
  ```
  # pyformat: enable
  
  The implementation of these loss functions is slightly more complex to
  support nested action_specs.
class_docstr_tok: ["A","Behavioral","Cloning","agent",".","#","pyformat",":","disable","Implements","a","generic","form","of","BehavioralCloning","that","can","also","be","used","to","pipe","supervised","learning","through","TF-Agents",".","By","default","the","agent","defines","two","types","of","losses",".","For","discrete","actions","the","agent","uses",":","``","`","python","def","discrete_loss","(","agent",",","experience",",","training=False",")",":","bc_logits","=","self._cloning_network","(","experience.observation",",","training=training",")","return","tf.nn.sparse_softmax_cross_entropy_with_logits","(","labels=experience.action","-","action_spec.minimum",",","logits=bc_logits",")","``","`","This","requires","a","Network","that","generates","`","num_action","`","Q-values",".","In","the","case","of","continuous","actions","a","simple","MSE","loss","is","used","by","default",":","``","`","python","def","continuous_loss_fn","(","agent",",","experience",",","training=False",")",":","bc_output",",","_","=","self._cloning_network","(","experience.observation",",","step_type=experience.step_type",",","training=training",",","network_state=network_state",")","if","isinstance","(","bc_output",",","tfp.distributions.Distribution",")",":","bc_action","=","bc_output.sample","(",")","else",":","bc_action","=","bc_output","return","tf.losses.mse","(","experience.action",",","bc_action",")","``","`","#","pyformat",":","enable","The","implementation","of","these","loss","functions","is","slightly","more","complex","to","support","nested","action_specs","."]
code: def _continuous_loss_fn(self, experience, training: bool = False):
      batch_size = (
          tf.compat.dimension_value(experience.step_type.shape[0])
          or tf.shape(experience.step_type)[0]
      )
      network_state = self._cloning_network.get_initial_state(
          batch_size
      )
      bc_output, _ = self._cloning_network(
          experience.observation,
          step_type=experience.step_type,
          training=training,
          network_state=network_state,
      )
  
      if isinstance(bc_output, tfp.distributions.Distribution):
          bc_action = bc_output.sample()
      else:
          bc_action = bc_output
  
      losses = tf.nest.map_structure(
          tf.losses.mse, experience.action, bc_action
      )
      losses = tf.nest.flatten(losses)
      return tf.add_n(losses)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import Callable, Optional, Text
  import gin
  import tensorflow
  import tensorflow_probability
  from tf_agents.agents import data_converter
  from tf_agents.agents import tf_agent
  from tf_agents.distributions import utils
  from tf_agents.networks import network
  from tf_agents.policies import actor_policy
  from tf_agents.policies import epsilon_greedy_policy
  from tf_agents.policies import greedy_policy
  from tf_agents.policies import q_policy
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import common
  import typing_extensions
label_desc: Use image node_id 4 for calling the BehavioralCloningAgent obj's underlying member method code with example usage: obj._continuous_loss_fn(experience, training) and returns: tf