Embeddings

sorrel.observation.embedding.positional_embedding(location: tuple | Location, world: Gridworld, scale: tuple[int, int]) ndarray

Get the embedding value for a location within an environment.

Parameters:
  • location – (tuple | Location) The location to be embedded.

  • world – (Gridworld) The gridworld environment within which embeddings should be computed.

  • scale – (tuple[int, int]) The scale for encoding coordinates in the X and Y dimensions.

Returns:

The positional embedding for the given location, with a shape of (1, (scale[0] + scale[1]) * 2).

Return type:

np.ndarray

Note

A lower value for scale[0] or scale[1] results in a lower resolution. This can mean that embedding values repeat, meaning that locations are not uniquely identified. Higher values of scale[0] or scale[1] result in a longer positional embedding value, but are able to uniquely encode points on a larger grid.

sorrel.observation.embedding.generate_positional_embedding(grid_size: tuple[int, int], scale: tuple[int, int]) ndarray

Create an array of positional embeddings for all points on a grid.

Parameters:
  • grid_size – (tuple[int, int]) A tuple indicating the size of the X and Y axes of the grid.

  • scale – (tuple[int, int]) The scale for encoding coordinates in the X and Y dimensions.

Returns:

An array of the embedding values for all points on the grid.

Return type:

np.ndarray

sorrel.observation.embedding.recover_coordinates(embedding: ndarray, grid_size: tuple[int, int], scale: tuple[int, int]) ndarray

Recover coordinates by finding the closest matching embedding.

Parameters:
  • embedding – The positional embedding of all locations in a grid.

  • grid_size – (tuple[int, int]) A tuple indicating the size of the X and Y axes of the grid.

  • scale – (tuple[int, int]) The scale for encoding coordinates in the X and Y dimensions.

Returns:

The recovered coordinates.

Return type:

np.ndarray

Warning

This function expects all embeddings in the grid. If a single embedding or partial list is input, the function will fail.

sorrel.observation.embedding.test_embeddings(grid_size: tuple[int, int] = (40, 40), scale: tuple[int, int] = (4, 4)) None

Helper function to graph embeddings for a given embedding size/scale.

Parameters:
  • grid_size – (tuple[int, int]) A tuple indicating the size of the X and Y axes of the grid.

  • scale – (tuple[int, int]) The scale for encoding coordinates in the X and Y dimensions.