# tf_agents.bandits.policies.constraints.RelativeQuantileConstraint

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/bandits/policies/constraints.py#L418-L496) |

Class for representing a trainable relative quantile constraint.

Inherits From: [`NeuralConstraint`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/bandits/policies/constraints/NeuralConstraint), [`BaseConstraint`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/bandits/policies/constraints/BaseConstraint)

    tf_agents.bandits.policies.constraints.RelativeQuantileConstraint(
        time_step_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types#TimeStep,
        action_spec: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types#BoundedTensorSpec,
        constraint_network: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types#Network,
        quantile: float = 0.5,
        comparator_fn: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/ComparatorFn = tf.greater,
        baseline_action_fn: Optional[Callable[[types.Tensor], types.Tensor]] = None,
        name: Text = 'RelativeQuantileConstraint'
    )

This constraint class implements a relative quantile constraint such as

    Q_tau(action) >= Q_tau(baseline_action)

or

    Q_tau(action) <= Q_tau(baseline_action)

<br />

<br />

<br />

| ## 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`. |
| `quantile` | A float between 0. and 1., the quantile we want to regress. |
| `comparator_fn` | a comparator function, such as tf.greater or tf.less. |
| `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. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `constraint_network` | <br /> <br /> |
| `observation_spec` | <br /> <br /> |

<br />

## Methods

### `compute_loss`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/bandits/policies/constraints.py#L149-L191)

    compute_loss(
        observations: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedTensor,
        actions: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/NestedTensor,
        rewards: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/Tensor,
        weights: Optional[types.Float] = None,
        training: bool = False
    ) -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/Tensor

Computes loss for training the constraint network.

<br />

<br />

<br />

| Args ||
|---|---|
| `observations` | A batch of observations. |
| `actions` | A batch of actions. |
| `rewards` | A batch of rewards. |
| `weights` | Optional scalar or elementwise (per-batch-entry) importance weights. The output batch loss will be scaled by these weights, and the final scalar loss is the mean of these values. |
| `training` | Whether the loss is being used for training. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `loss` | A `Tensor` containing the loss for the training step. |

<br />

### `initialize`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/bandits/policies/constraints.py#L145-L147)

    initialize()

Returns an op to initialize the constraint.

### `__call__`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/bandits/policies/constraints.py#L472-L496)

    __call__(
        observation, actions=None
    )

Returns the probability of input actions being feasible.