pitchscapes.scapes.DiscreteScape
- class pitchscapes.scapes.DiscreteScape(values, times=None, weights=None, strategy='left')[source]
Bases:
Scape
Discrete-time scape that is only well-defined at specific points in time. It computes the weighted sum over the given time window i.e. it sums up the values weighted by the corresponding time span.
Public Methods:
__init__
(values[, times, weights, strategy])Initialise the scape.
assert_valid_time_window
(start, end)assert_valid_index_window
(start, end)__getitem__
(item)Return value of the scape at position :type item: :param item: (start, end) with start < end :return: value of the scape for the time window (start, end)
recursive_indices
(start_idx, end_idx)get_value_at_index
(start, end)Compute all values bottom up.
Inherited from
Scape
__init__
(min_time, max_time)__getitem__
(item)Return value of the scape at position :type item: :param item: (start, end) with start < end :return: value of the scape for the time window (start, end)
assert_valid_time_window
(start, end)
- __annotations__ = {}
- __dict__ = mappingproxy({'__module__': 'pitchscapes.scapes', '__doc__': '\n Discrete-time scape that is only well-defined at specific points in time. It computes the weighted sum over the\n given time window i.e. it sums up the values weighted by the corresponding time span.\n ', '__init__': <function DiscreteScape.__init__>, 'assert_valid_time_window': <function DiscreteScape.assert_valid_time_window>, 'assert_valid_index_window': <function DiscreteScape.assert_valid_index_window>, '__getitem__': <function DiscreteScape.__getitem__>, 'recursive_indices': <function DiscreteScape.recursive_indices>, 'get_value_at_index': <function DiscreteScape.get_value_at_index>, 'parse_bottom_up': <function DiscreteScape.parse_bottom_up>, '__annotations__': {}})
- __getitem__(item)[source]
Return value of the scape at position :type item: :param item: (start, end) with start < end :return: value of the scape for the time window (start, end)
- __init__(values, times=None, weights=None, strategy='left')[source]
Initialise the scape. :type values: :param values: values for each time slot (first dimension of size N runs over time intervals) :type times: :param times: [optional] boundaries of the time intervals (array like of length N+1). Defaults to [0, 1, …, N]. :type weights: :param weights: [optional] non-negative weights for the values; if not provided, the size of respective time interval is used. :type strategy: :param strategy: one of [“left”, “right”, “center”] (default: “left”). Determines how a time-index interval [K, L] is split in the recursive computations. For “left”: [K,L-1]+[L-1,L]; for “right”: [K,K+1]+[K+1,L]; for “center”: [K,K+1]+[K+1,L-1]+[L-1,L]. Also see comments for parse_bottom_up concerning efficiency and run time.
- __module__ = 'pitchscapes.scapes'
- __weakref__
list of weak references to the object (if defined)
- parse_bottom_up()[source]
Compute all values bottom up. Performs an efficient dynamic programming pass through the entire scape and avoids time consuming recursive look-ups for compting single values (run time ~O(n^2)). This can be used if all values within the scape are expected to be needed. For high-resolution scapes where only few values need to be computed this may be inefficient as a single lookup has only ~O(n) run time. So if fewer than n values are needed, separate lookup will be more efficient. Moreover, if multiple value have the same start or end time, the overall run time for computing these values is only ~O(n). Depending on whether star or end time are in common the “left” or “right” strategy is more efficient.