# tf_agents.bandits.environments.drifting_linear_environment.DriftingLinearEnvironment

<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/environments/drifting_linear_environment.py#L267-L301) |

Implements a drifting linear environment.

Inherits From: [`NonStationaryStochasticEnvironment`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/bandits/environments/non_stationary_stochastic_environment/NonStationaryStochasticEnvironment), [`BanditTFEnvironment`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/bandits/environments/bandit_tf_environment/BanditTFEnvironment), [`TFEnvironment`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/environments/TFEnvironment)

    tf_agents.bandits.environments.drifting_linear_environment.DriftingLinearEnvironment(
        observation_distribution: types.Distribution,
        observation_to_reward_distribution: types.Distribution,
        drift_distribution: types.Distribution,
        additive_reward_distribution: types.Distribution
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `observation_distribution` | A distribution from [`tfp.distributions`](https://www.tensorflow.org/probability/api_docs/python/tfp/distributions) with shape `[batch_size, observation_dim]`. Note that the values of `batch_size` and `observation_dim` are deduced from the distribution. |
| `observation_to_reward_distribution` | A distribution from [`tfp.distributions`](https://www.tensorflow.org/probability/api_docs/python/tfp/distributions) with shape `[observation_dim, num_actions]`. The value `observation_dim` must match the second dimension of `observation_distribution`. |
| `drift_distribution` | A scalar distribution from [`tfp.distributions`](https://www.tensorflow.org/probability/api_docs/python/tfp/distributions) of type tf.float32. It represents the angle of rotation. |
| `additive_reward_distribution` | A distribution from [`tfp.distributions`](https://www.tensorflow.org/probability/api_docs/python/tfp/distributions) with shape `[num_actions]`. This models the non-contextual behavior of the bandit. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `batch_size` | <br /> <br /> |
| `batched` | <br /> <br /> |
| `environment_dynamics` | <br /> <br /> |
| `name` | <br /> <br /> |

<br />

## Methods

### `action_spec`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L146-L157)

    action_spec()

Describes the specs of the Tensors expected by `step(action)`.

`action` can be a single Tensor, or a nested dict, list or tuple of
Tensors.

<br />

<br />

<br />

| Returns ||
|---|---|
| An single `TensorSpec`, or a nested dict, list or tuple of `TensorSpec` objects, which describe the shape and dtype of each Tensor expected by `step()`. ||

<br />

### `current_time_step`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L185-L196)

    current_time_step()

Returns the current `TimeStep`.

<br />

<br />

<br />

| Returns ||
|---|---|
| A `TimeStep` namedtuple containing: step_type: A `StepType` value. reward: Reward at this time_step. discount: A discount in the range \[0, 1\]. observation: A Tensor, or a nested dict, list or tuple of Tensors corresponding to `observation_spec()`. ||

<br />

### `observation_spec`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L159-L166)

    observation_spec()

Defines the `TensorSpec` of observations provided by the environment.

<br />

<br />

<br />

| Returns ||
|---|---|
| A `TensorSpec`, or a nested dict, list or tuple of `TensorSpec` objects, which describe the observation. ||

<br />

### `render`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L243-L249)

    render()

Renders a frame from the environment.

<br />

<br />

<br />

| Raises ||
|---|---|
| `NotImplementedError` | If the environment does not support rendering. |

<br />

### `reset`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L198-L209)

    reset()

Resets the environment and returns the current time_step.

<br />

<br />

<br />

| Returns ||
|---|---|
| A `TimeStep` namedtuple containing: step_type: A `StepType` value. reward: Reward at this time_step. discount: A discount in the range \[0, 1\]. observation: A Tensor, or a nested dict, list or tuple of Tensors corresponding to `observation_spec()`. ||

<br />

### `reward_spec`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L168-L175)

    reward_spec()

Defines the `TensorSpec` of rewards provided by the environment.

<br />

<br />

<br />

| Returns ||
|---|---|
| A `TensorSpec`, or a nested dict, list or tuple of `TensorSpec` objects, which describe the reward. ||

<br />

### `step`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L211-L241)

    step(
        action
    )

Steps the environment according to the action.

If the environment returned a `TimeStep` with [`StepType.LAST`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/StepType#LAST) at the
previous step, this call to `step` should reset the environment (note that
it is expected that whoever defines this method, calls reset in this case),
start a new sequence and `action` will be ignored.

This method will also start a new sequence if called after the environment
has been constructed and `reset()` has not been called. In this case
`action` will be ignored.

Expected sequences look like:

time_step -\> action -\> next_time_step

The action should depend on the previous time_step for correctness.

<br />

<br />

<br />

| Args ||
|---|---|
| `action` | A Tensor, or a nested dict, list or tuple of Tensors corresponding to `action_spec()`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `TimeStep` namedtuple containing: step_type: A `StepType` value. reward: Reward at this time_step. discount: A discount in the range \[0, 1\]. observation: A Tensor, or a nested dict, list or tuple of Tensors corresponding to `observation_spec()`. ||

<br />

### `time_step_spec`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/tf_environment.py#L136-L144)

    time_step_spec()

Describes the `TimeStep` specs of Tensors returned by `step()`.

<br />

<br />

<br />

| Returns ||
|---|---|
| A `TimeStep` namedtuple containing `TensorSpec` objects defining the Tensors returned by `step()`, i.e. (step_type, reward, discount, observation). ||

<br />