plaid.utils.interpolation

Interpolation utilities for working with ordered lists and vectors.

Functions

binary_search(→ int)

Find the rank of the largest element smaller or equal to the given item in a sorted list.

binary_search_vectorized(→ numpy.ndarray)

Vectorized binary search for multiple items in a sorted list (items is now a list or one-dimensional np.ndarray).

piece_wise_linear_interpolation(→ numpy.ndarray)

Computes a item interpolation for temporal vectors defined either by item_indices and vectors at these indices.

piece_wise_linear_interpolation_with_map(→ numpy.ndarray)

Computes a item interpolation for temporal vectors defined either by item_indices, some tags at these item indices (vectors_map), and vectors at those tags.

piece_wise_linear_interpolation_vectorized(...)

piece_wise_linear_interpolation for more than one call (items is now a list or one-dimensional np.ndarray).

piece_wise_linear_interpolation_vectorized_with_map(...)

piece_wise_linear_interpolation_with_map for more than one call (items is now a list or one-dimensional np.ndarray).

Module Contents

Find the rank of the largest element smaller or equal to the given item in a sorted list.

Inspects the sorted list “ordered_list” and returns:
  • 0 if item <= ordered_list[0]

  • the rank of the largest element smaller or equal than item otherwise

Parameters:
  • ordered_list (Union[list, np.ndarray]) – The data sorted in increasing order from which the previous rank is searched.

  • item (Union[float, int]) – The item for which the previous rank is searched.

Returns:

0 or the rank of the largest element smaller or equal than item in “ordered_list”.

Return type:

int

binary_search_vectorized(ordered_list: list | numpy.ndarray, items: list | numpy.ndarray) numpy.ndarray[source]

Vectorized binary search for multiple items in a sorted list (items is now a list or one-dimensional np.ndarray).

Parameters:
  • ordered_list (Union[list, np.ndarray]) – The data sorted in increasing order.

  • items (Union[list, np.ndarray]) – The items for which ranks are searched.

Returns:

An array containing the ranks of the largest elements smaller or equal to each item.

Return type:

np.ndarray

piece_wise_linear_interpolation(item: float, item_indices: numpy.ndarray, vectors: numpy.ndarray | dict, tolerance: float = 0.0001) numpy.ndarray[source]

Computes a item interpolation for temporal vectors defined either by item_indices and vectors at these indices.

Parameters:
  • item (float) – The input item at which the interpolation is required.

  • item_indices (np.ndarray) – The items where the available data is defined, of size (numberOfTimeIndices).

  • vectors (Union[np.ndarray, dict]) – The available data, of size (numberOfVectors, numberOfDofs).

  • tolerance (float) – Tolerance for deciding when using the closest timestep value instead of carrying out the linear interpolation, default to 1e-4.

Returns:

Interpolated vector, of size (numberOfDofs).

Return type:

np.ndarray

piece_wise_linear_interpolation_with_map(item: float, item_indices: numpy.ndarray, vectors: numpy.ndarray | dict, vectors_map: list = None, tolerance: float = 0.0001) numpy.ndarray[source]

Computes a item interpolation for temporal vectors defined either by item_indices, some tags at these item indices (vectors_map), and vectors at those tags.

Parameters:
  • item (float) – The input item at which the interpolation is required.

  • item_indices (np.ndarray) – The items where the available data is defined, of size (numberOfTimeIndices).

  • vectors (Union[np.ndarray, dict]) – The available data, of size (numberOfVectors, numberOfDofs).

  • vectors_map (list, optional) – List containing the mapping from the numberOfTimeIndices items indices to the numberOfVectors vectors, of size (numberOfTimeIndices,). Defaults to None.

  • tolerance (float, optional) – Tolerance for deciding when using the closest timestep value instead of carrying out the linear interpolation, default to 1e-4.

Returns:

Interpolated vector, of size (numberOfDofs).

Return type:

np.ndarray

piece_wise_linear_interpolation_vectorized(items: list[float], item_indices: numpy.ndarray, vectors: numpy.ndarray | str) list[numpy.ndarray][source]

piece_wise_linear_interpolation for more than one call (items is now a list or one-dimensional np.ndarray).

Parameters:
  • items (list[float]) – The input items at which interpolations are required.

  • item_indices (np.ndarray) – The items where the available data is defined, of size (numberOfTimeIndices).

  • vectors (np.ndarray or dict) – The available data, of size (numberOfVectors, numberOfDofs).

Returns:

List of interpolated vectors, each of size (numberOfDofs).

Return type:

list[np.ndarray]

piece_wise_linear_interpolation_vectorized_with_map(items: list[float], item_indices: numpy.ndarray, vectors: numpy.ndarray | dict, vectors_map: list = None) list[numpy.ndarray][source]

piece_wise_linear_interpolation_with_map for more than one call (items is now a list or one-dimensional np.ndarray).

Parameters:
  • items (list[float]) – The input items at which interpolations are required.

  • item_indices (np.ndarray) – The items where the available data is defined, of size (numberOfTimeIndices).

  • vectors (np.ndarray or dict) – The available data, of size (numberOfVectors, numberOfDofs).

  • vectors_map (list) – List containing the mapping from the numberOfTimeIndices items indices to the numberOfVectors vectors, of size (numberOfTimeIndices,). Default is None, in which case numberOfVectors = numberOfTimeIndices.

Returns:

List of interpolated vectors, each of size (numberOfDofs).

Return type:

list[np.ndarray]