class_docstr: Helper class to manage losses.
class_docstr_tok: ["Helper","class","to","manage","losses","."]
docstr: Get weighted R.
docstr_tok: ["Get","weighted","R","."]
code: def _get_weighted_rate_loss(self, loss_config, bpp_pair, step):
      """Get weighted R."""
      total_nbpp, total_qbpp = bpp_pair
      lmbda_a = self._get_scheduled_param(
          loss_config.lmbda_a,
          self._config.lambda_schedule,
          step,
          "lmbda_a",
      )
      # For a target rate R_target, implement constrained optimization:
      # { 1/lambda_a * R    if R > R_target
      #   1/lambda_b * R    else
      # We assume lambda_a < lambda_b, and thus 1/lambda_a > 1/lambda_b,
      # i.e., if the rate R is too large, we want a larger factor on it.
      if loss_config.lmbda_a >= loss_config.lmbda_b:
          raise ValueError(
              "Expected lmbda_a < lmbda_b, got {} >= {}".format(
                  loss_config.lmbda_a, loss_config.lmbda_b
              )
          )
  
      target_bpp = self._get_scheduled_param(
          loss_config.target,
          loss_config.target_schedule,
          step,
          "target_bpp",
      )
      lmbda_b = self._get_scheduled_param(
          loss_config.lmbda_b,
          self._config.lambda_schedule,
          step,
          "lmbda_b",
      )
      lmbda_inv = tf.where(
          total_qbpp > target_bpp, 1 / lmbda_a, 1 / lmbda_b
      )
  
      tf.summary.scalar("lmbda_inv", lmbda_inv)
      return lmbda_inv * total_nbpp * loss_config.C
  
imports: import collections
  import glob
  import itertools
  from compare_gan.gans import loss_lib
  import tensorflow.compat.v1
  import tensorflow_datasets
  from hific import archs
  from hific import helpers
  from hific.helpers import ModelMode
  from hific.helpers import ModelType
  from hific.helpers import TFDSArguments
label_desc: Use image node_id 4 for calling the _LossScaler obj's underlying member method code with example usage: obj._get_weighted_rate_loss(loss_config, bpp_pair, step) and returns: unknown