code: def __init__(
      self,
      policy: Policy,
      value_estimates: TensorType,
      action_dist: ActionDistribution,
      train_batch: SampleBatch,
      vf_loss_coeff: float,
      beta: float,
  ):
      # L = - A * log\pi_\theta(a|s)
      logprobs = action_dist.logp(train_batch[SampleBatch.ACTIONS])
      if beta != 0.0:
          cumulative_rewards = train_batch[Postprocessing.ADVANTAGES]
          # Advantage Estimation.
          adv = cumulative_rewards - value_estimates
          adv_squared = tf.reduce_mean(tf.math.square(adv))
          # Value function's loss term (MSE).
          self.v_loss = 0.5 * adv_squared
  
          # Perform moving averaging of advantage^2.
          rate = policy.config[
              "moving_average_sqd_adv_norm_update_rate"
          ]
  
          # Update averaged advantage norm.
          # Eager.
          if policy.config["framework"] == "tf2":
              update_term = (
                  adv_squared - policy._moving_average_sqd_adv_norm
              )
              policy._moving_average_sqd_adv_norm.assign_add(
                  rate * update_term
              )
  
              # Exponentially weighted advantages.
              c = tf.math.sqrt(policy._moving_average_sqd_adv_norm)
              exp_advs = tf.math.exp(beta * (adv / (1e-8 + c)))
          # Static graph.
          else:
              update_adv_norm = tf1.assign_add(
                  ref=policy._moving_average_sqd_adv_norm,
                  value=rate
                  * (adv_squared - policy._moving_average_sqd_adv_norm),
              )
  
              # Exponentially weighted advantages.
              with tf1.control_dependencies([update_adv_norm]):
                  exp_advs = tf.math.exp(
                      beta
                      * tf.math.divide(
                          adv,
                          1e-8
                          + tf.math.sqrt(
                              policy._moving_average_sqd_adv_norm
                          ),
                      )
                  )
          exp_advs = tf.stop_gradient(exp_advs)
  
          self.explained_variance = tf.reduce_mean(
              explained_variance(cumulative_rewards, value_estimates)
          )
  
      else:
          # Value function's loss term (MSE).
          self.v_loss = tf.constant(0.0)
          exp_advs = 1.0
  
      # logprob loss alone tends to push action distributions to
      # have very low entropy, resulting in worse performance for
      # unfamiliar situations.
      # A scaled logstd loss term encourages stochasticity, thus
      # alleviate the problem to some extent.
      logstd_coeff = policy.config["bc_logstd_coeff"]
      if logstd_coeff > 0.0:
          logstds = tf.reduce_sum(action_dist.log_std, axis=1)
      else:
          logstds = 0.0
  
      self.p_loss = -1.0 * tf.reduce_mean(
          exp_advs * (logprobs + logstd_coeff * logstds)
      )
  
      self.total_loss = self.p_loss + vf_loss_coeff * self.v_loss
  
imports: import logging
  from typing import Any, Dict, List, Optional, Type, Union
  from ray.rllib.evaluation.episode import Episode
  from ray.rllib.evaluation.postprocessing import compute_advantages, Postprocessing
  from ray.rllib.models.action_dist import ActionDistribution
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.models.tf.tf_action_dist import TFActionDistribution
  from ray.rllib.policy.dynamic_tf_policy_v2 import DynamicTFPolicyV2
  from ray.rllib.policy.eager_tf_policy_v2 import EagerTFPolicyV2
  from ray.rllib.policy.policy import Policy
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.policy.tf_mixins import ValueNetworkMixin, compute_gradients
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.framework import try_import_tf, get_variable
  from ray.rllib.utils.tf_utils import explained_variance
  from ray.rllib.utils.typing import LocalOptimizer, ModelGradients, TensorType
label_desc: Use image node_id 1 to create a new MARWILLoss object  with example: obj = MARWILLoss(policy, value_estimates, action_dist, train_batch, vf_loss_coeff, beta)