# get_action_interp_reg¶

`process_ais_data.``get_action_interp_reg`(row, options, grid_params)

Calculates the actions taken from the previous state to reach the current state, interpolating if necessary.

First, the relative offset between the current and previous state in rows and columns is calculated. Then the sign of `rel_row` and `rel_col` are then used to iteratively describe a sequence of actions from the previous state to current state, breaking up state transitions with multiple actions if the states are not adjacent (only actions are right, left, up, down, and none). This interpolation assumes a deterministic system.

Example

For example, if `prev_state = 5`, `cur_state = 7`, and `num_cols = 4`, then our state grid is populated as follows:

```8  9 10 11
4  p  6  c
0  1  2  3
```

Output snippet:

```pd.DataFrame({})
```

Where p represents the location of the previous state, and c represents the location of the current state. Then the current state’s position relative to the previous state is `rel_row = 0`, `rel_col = 2`. Our action spiral then looks like this:

```   2            2
3  0  1  ->  3  p  1  c
4            4
```

Output snippet:

```output: pd.DataFrame({
'ID': [traj_num, ],
'PREV': [prev_state, ],
'ACT': [1, ],
'CUR': [prev_state + 1, ]
})
```

Because the current state is not adjacent, we interpolate by taking the action that brings us closest to the current state: action `1`, resulting in a new action spiral and a new previous state:

```   2            1
3  0  1  ->  2  p  c
4            4
```

Final output:

```pd.DataFrame({
'ID': [traj_num] * 2,
'PREV': [prev_state, prev_state + 1],
'ACT': [1, 1],
'CUR': [prev_state + 1, cur_state]
})
```

Now, our new previous state is adjacent to the current state, so we can take action `1`, which updates our previous state to exactly match the current state, so the algorithm terminates and returns the list of state-action-state transitions.

Parameters
• row (pandas.Series) – One row of the DataFrame the function is applied to, containing the trajectory number, previous state, current state, longitude, and latitude.

• options (dict) – The script options specified in the `config_file`.

• grid_params (dict) – The grid parameters specified in the `config_file`.

Returns

State-action-state triplets that interpolate between `prev_state` and `cur_state`.

Return type

dict