transform#

gym_socks.sampling.transform.flatten_sample(sample)[source]#

Reshapes trajectory samples.

Often, trajectory samples are organized such that the “trajectory” components are a 2D array of points indexed by time. However, for kernel methods, we typically require that the trajectories be concatenated into a single vector (1D array):

[[x1], [x2], ..., [xn]] -> [x1, x2, ..., xn]

This function converts the sample so that the trajectories are 1D arrays.

Parameters

sample – list of tuples

Returns

List of tuples, where the components of the tuples are flattened.

gym_socks.sampling.transform.transpose_sample(sample)[source]#

Transpose the sample.

By default, a sample should be a list of tuples of the form:

S = [(x_1, y_1), ..., (x_n, y_n)]

For most algorithms, we need to isolate the sample components (e.g. all x’s). This function converts a sample from a list of tuples to a tuple of lists:

S_T = ([x_1, ..., x_n], [y_1, ..., y_n])

This can then be unpacked as: X, Y = S_T

Parameters

sample – list of tuples

Returns

tuple of lists