GridWorld

class safe_learning.GridWorld(limits, num_points)

Base class for function approximators on a regular grid.

Parameters:
limits: 2d array-like

A list of limits. For example, [(x_min, x_max), (y_min, y_max)]

num_points: 1d array-like

The number of points with which to grid each dimension.

Attributes:
all_points

Return all the discrete points of the discretization.

Methods

index_to_state(self, indices) Convert indices to physical states.
rectangle_corner_index(self, rectangles) Return the index of the bottom-left corner of the rectangle.
rectangle_to_state(self, rectangles) Convert rectangle indices to the states of the bottem-left corners.
sample_continuous(self, num_samples) Sample uniformly at random from the continuous domain.
sample_discrete(self, num_samples[, replace]) Sample uniformly at random from the discrete domain.
state_to_index(self, states) Convert physical states to indices.
state_to_rectangle(self, states) Convert physical states to its closest rectangle index.
all_points

Return all the discrete points of the discretization.

Returns:
points : ndarray

An array with all the discrete points with size (self.nindex, self.ndim).

index_to_state(self, indices)

Convert indices to physical states.

Parameters:
indices : ndarray (int)

The indices of points on the discretization.

Returns:
states : ndarray

The states with physical units that correspond to the indices.

rectangle_corner_index(self, rectangles)

Return the index of the bottom-left corner of the rectangle.

Parameters:
rectangles: ndarray

The indices of the rectangles.

Returns:
corners : ndarray (int)

The indices of the bottom-left corners of the rectangles.

rectangle_to_state(self, rectangles)

Convert rectangle indices to the states of the bottem-left corners.

Parameters:
rectangles : ndarray (int)

The indices of the rectangles

Returns:
states : ndarray

The states that correspond to the bottom-left corners of the corresponding rectangles.

sample_continuous(self, num_samples)

Sample uniformly at random from the continuous domain.

Parameters:
num_samples : int
Returns:
points : ndarray

Random points on the continuous rectangle.

sample_discrete(self, num_samples, replace=False)

Sample uniformly at random from the discrete domain.

Parameters:
num_samples : int
replace : bool, optional

Whether to sample with replacement.

Returns:
points : ndarray

Random points on the continuous rectangle.

state_to_index(self, states)

Convert physical states to indices.

Parameters:
states: ndarray

Physical states on the discretization.

Returns:
indices: ndarray (int)

The indices that correspond to the physical states.

state_to_rectangle(self, states)

Convert physical states to its closest rectangle index.

Parameters:
states : ndarray

Physical states on the discretization.

Returns:
rectangles : ndarray (int)

The indices that correspond to rectangles of the physical states.