class_docstr: Class for representing a trainable relative constraint.
  
  This constraint class implements a relative constraint such as
  ```
  expected_value(action) >= (1 - margin) * expected_value(baseline_action)
  ```
  or
  ```
  expected_value(action) <= (1 - margin) * expected_value(baseline_action)
  ```
class_docstr_tok: ["Class","for","representing","a","trainable","relative","constraint",".","This","constraint","class","implements","a","relative","constraint","such","as","``","`","expected_value","(","action",")",">","=","(","1","-","margin",")","*","expected_value","(","baseline_action",")","``","`","or","``","`","expected_value","(","action",")","<","=","(","1","-","margin",")","*","expected_value","(","baseline_action",")","``","`"]
docstr: Creates a trainable relative constraint using a neural network.
  
  Args:
    time_step_spec: A `TimeStep` spec of the expected time_steps.
    action_spec: A nest of `BoundedTensorSpec` representing the actions.
    constraint_network: An instance of `tf_agents.network.Network` used to
      provide estimates of action feasibility. The input structure should be
      consistent with the `observation_spec`.
    error_loss_fn: A function for computing the loss used to train the
      constraint network. The default is `tf.losses.mean_squared_error`.
    comparator_fn: A comparator function, such as tf.greater or tf.less.
    margin: A float in (0,1] that determines how strongly we want to enforce
      the constraint.
    baseline_action_fn: a callable that given the observation returns the
      baseline action. If None, the baseline action is set to 0.
    name: Python str name of this agent. All variables in this module will
      fall under that name. Defaults to the class name.
code: def __init__(
      self,
      time_step_spec: types.TimeStep,
      action_spec: types.BoundedTensorSpec,
      constraint_network: types.Network,
      error_loss_fn: types.LossFn = tf.compat.v1.losses.mean_squared_error,
      comparator_fn: types.ComparatorFn = tf.greater,
      margin: float = 0.0,
      baseline_action_fn: Optional[
          Callable[[types.NestedTensor], types.Tensor]
      ] = None,
      name: Text = "RelativeConstraint",
  ):
      """Creates a trainable relative constraint using a neural network.
  
      Args:
        time_step_spec: A `TimeStep` spec of the expected time_steps.
        action_spec: A nest of `BoundedTensorSpec` representing the actions.
        constraint_network: An instance of `tf_agents.network.Network` used to
          provide estimates of action feasibility. The input structure should be
          consistent with the `observation_spec`.
        error_loss_fn: A function for computing the loss used to train the
          constraint network. The default is `tf.losses.mean_squared_error`.
        comparator_fn: A comparator function, such as tf.greater or tf.less.
        margin: A float in (0,1] that determines how strongly we want to enforce
          the constraint.
        baseline_action_fn: a callable that given the observation returns the
          baseline action. If None, the baseline action is set to 0.
        name: Python str name of this agent. All variables in this module will
          fall under that name. Defaults to the class name.
      """
      self._baseline_action_fn = baseline_action_fn
      self._comparator_fn = comparator_fn
      self._error_loss_fn = error_loss_fn
      self._margin = margin
  
      super(RelativeConstraint, self).__init__(
          time_step_spec,
          action_spec,
          constraint_network,
          error_loss_fn=self._error_loss_fn,
          name=name,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import functools
  from typing import Callable, Iterable, Optional, Text
  import six
  import tensorflow
  import tensorflow_probability
  from tf_agents.bandits.policies import loss_utils
  from tf_agents.bandits.specs import utils
  from tf_agents.policies import utils
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 1 to create a new RelativeConstraint object from inherited base classes: NeuralConstraint with example: obj = RelativeConstraint(time_step_spec, action_spec, constraint_network, error_loss_fn, comparator_fn, margin, baseline_action_fn, name)