utils

Utility and helper functions for the Genius Python SDK.

To import any utility functions run: from genius_client_sdk.utils import <function>

control_map

Maps from an integer dummy encoding of an action to the action's string name.

Parameter
Type
Default
Description

controls

list[str]

Required

A list of strings containing possible actions.

chosen_action

int

Required

An integer encoding of the selected action.

Returns:

Type
Description

str

The string representation of the action.

Example:

controls = ["LEFT", "RIGHT"]
chosen_action = 1

control_map(controls=controls, chosen_action=chosen_action)

# Returns: "RIGHT"

flatten_nested_list

Flatten a nested list.

Parameter
Type
Default
Description

nested_list

list[list]

Required

A nested list with a maximum depth of 1.

Returns:

Type
Description

list

A flattened list.

get_policy_space

Constructs the space of all policies possible for the agent to pursue. Note that this function can be used for multiple observation modalities or state factor which is why the inputs for n_states and n_actions are lists.

Parameter
Type
Default
Description

n_states

list[int]

Required

A list of the number of states for each state factor.

n_actions

list[int]

Required

A list of the number of actions for each state factor.

policy_len

int

Required

Length of policy (i.e. number of actions).

actions

list[str]

Optional

String representation of possible actions.

Returns:

Type
Description

list[list[list[str]]]

Either the string representation of the policy space (if actions are provided) or the dummy encoding of the policy space.

onehot

Generates a one hot numpy array of size size with a 1 inserted in position position.

Parameter
Type
Default
Description

size

int

Required

The size of the array.

position

int

Required

The position to insert a 1.

Returns:

Type
Description

np.ndarray

A one hot numpy array of dimension size with a 1 at the specified position and zeros elsewhere.

plot_categorical

Plot a categorical distribution as a bar plot.

circle-info

The color parameter must either be a hex string or one of the standard Matplotlib CSS colorsarrow-up-right.

Parameter
Type
Default
Description

x

list

Required

A list of categories or x-axis values.

y

list

Required

A list of values corresponding to each category in x.

xlabel

str

X

A label for the x-axis.

ylabel

str

Y

A label for the y-axis.

title

str

"no title"

The title of the plot.

color

str

"dodgerblue"

The color of the bars in the plot.

rotation

int

0

The rotation angle of the x-axis labels.

policy_map

Maps from the integer dummy encoding of a policy in the policy space and the policy string.

Parameter
Type
Default
Description

policy_space

list[list[str]]

Required

The The space of possible policies pursued by the agent. Can be obtained by using get_policy_space().

chosen_policy

int

Required

An integer encoding the chosen policy in the policy space.

Returns:

Type
Description

list[str]

A policy list which contains a sequence of actions as a string.

Example: