plaid.utils.interpolation ========================= .. py:module:: plaid.utils.interpolation .. autoapi-nested-parse:: Interpolation utilities for working with ordered lists and vectors. Functions --------- .. autoapisummary:: plaid.utils.interpolation.binary_search plaid.utils.interpolation.binary_search_vectorized plaid.utils.interpolation.piece_wise_linear_interpolation plaid.utils.interpolation.piece_wise_linear_interpolation_with_map plaid.utils.interpolation.piece_wise_linear_interpolation_vectorized plaid.utils.interpolation.piece_wise_linear_interpolation_vectorized_with_map Module Contents --------------- .. py:function:: binary_search(ordered_list: Union[list, numpy.ndarray], item: Union[float, int]) -> int 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 :param ordered_list: The data sorted in increasing order from which the previous rank is searched. :type ordered_list: Union[list, np.ndarray] :param item: The item for which the previous rank is searched. :type item: Union[float, int] :returns: 0 or the rank of the largest element smaller or equal than item in "ordered_list". :rtype: int .. py:function:: binary_search_vectorized(ordered_list: Union[list, numpy.ndarray], items: Union[list, numpy.ndarray]) -> numpy.ndarray Vectorized binary search for multiple items in a sorted list (items is now a list or one-dimensional np.ndarray). :param ordered_list: The data sorted in increasing order. :type ordered_list: Union[list, np.ndarray] :param items: The items for which ranks are searched. :type items: Union[list, np.ndarray] :returns: An array containing the ranks of the largest elements smaller or equal to each item. :rtype: np.ndarray .. py:function:: piece_wise_linear_interpolation(item: float, item_indices: numpy.ndarray, vectors: Union[numpy.ndarray, dict], tolerance: float = 0.0001) -> numpy.ndarray Computes a item interpolation for temporal vectors defined either by item_indices and vectors at these indices. :param item: The input item at which the interpolation is required. :type item: float :param item_indices: The items where the available data is defined, of size (numberOfTimeIndices). :type item_indices: np.ndarray :param vectors: The available data, of size (numberOfVectors, numberOfDofs). :type vectors: Union[np.ndarray, dict] :param tolerance: Tolerance for deciding when using the closest timestep value instead of carrying out the linear interpolation, default to 1e-4. :type tolerance: float :returns: Interpolated vector, of size (numberOfDofs). :rtype: np.ndarray .. py:function:: piece_wise_linear_interpolation_with_map(item: float, item_indices: numpy.ndarray, vectors: Union[numpy.ndarray, dict], vectors_map: list = None, tolerance: float = 0.0001) -> 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. :param item: The input item at which the interpolation is required. :type item: float :param item_indices: The items where the available data is defined, of size (numberOfTimeIndices). :type item_indices: np.ndarray :param vectors: The available data, of size (numberOfVectors, numberOfDofs). :type vectors: Union[np.ndarray, dict] :param vectors_map: List containing the mapping from the numberOfTimeIndices items indices to the numberOfVectors vectors, of size (numberOfTimeIndices,). Defaults to None. :type vectors_map: list, optional :param tolerance: Tolerance for deciding when using the closest timestep value instead of carrying out the linear interpolation, default to 1e-4. :type tolerance: float, optional :returns: Interpolated vector, of size (numberOfDofs). :rtype: np.ndarray .. py:function:: piece_wise_linear_interpolation_vectorized(items: list[float], item_indices: numpy.ndarray, vectors: Union[numpy.ndarray, str]) -> list[numpy.ndarray] piece_wise_linear_interpolation for more than one call (items is now a list or one-dimensional np.ndarray). :param items: The input items at which interpolations are required. :type items: list[float] :param item_indices: The items where the available data is defined, of size (numberOfTimeIndices). :type item_indices: np.ndarray :param vectors: The available data, of size (numberOfVectors, numberOfDofs). :type vectors: np.ndarray or dict :returns: List of interpolated vectors, each of size (numberOfDofs). :rtype: list[np.ndarray] .. py:function:: piece_wise_linear_interpolation_vectorized_with_map(items: list[float], item_indices: numpy.ndarray, vectors: Union[numpy.ndarray, dict], vectors_map: list = None) -> list[numpy.ndarray] piece_wise_linear_interpolation_with_map for more than one call (items is now a list or one-dimensional np.ndarray). :param items: The input items at which interpolations are required. :type items: list[float] :param item_indices: The items where the available data is defined, of size (numberOfTimeIndices). :type item_indices: np.ndarray :param vectors: The available data, of size (numberOfVectors, numberOfDofs). :type vectors: np.ndarray or dict :param vectors_map: List containing the mapping from the numberOfTimeIndices items indices to the numberOfVectors vectors, of size (numberOfTimeIndices,). Default is None, in which case numberOfVectors = numberOfTimeIndices. :type vectors_map: list :returns: List of interpolated vectors, each of size (numberOfDofs). :rtype: list[np.ndarray]