datastruct
- class Trivalent(value)[source]
Bases:
enum.Enum
An enumeration.
- TRUE = 'true'
- FALSE = 'false'
- UNKNOWN = 'unknown'
- classmethod from_bool(b: bool)
- is_true()
- is_false()
- class Maybe(value: Optional[sensai.util.datastruct.TValue])[source]
Bases:
Generic
[sensai.util.datastruct.TValue
]- __init__(value: Optional[sensai.util.datastruct.TValue])
- class DeferredParams[source]
Bases:
sensai.util.string.ToStringMixin
Represents a dictionary of parameters that is specifically designed to hold parameters that can only defined late within a process (i.e. not initially at construction time), e.g. because the parameters are data-dependent and therefore can only be determined once the data has been seen.
- UNDEFINED = '__undefined__DeferredParams'
- __init__()
- set_param(name: str, value: Any)
- get_param(name, default='__undefined__DeferredParams')
- Parameters
name – the parameter name
default – in case no value is set, return this value, and if UNDEFINED (default), raise KeyError
- Returns
the parameter value
- get_dict() Dict[str, Any]
- class SortedValues(sorted_values: Sequence[sensai.util.datastruct.TValue])[source]
Bases:
Generic
[sensai.util.datastruct.TValue
]Provides convenient binary search (bisection) operations for sorted sequences
- __init__(sorted_values: Sequence[sensai.util.datastruct.TValue])
- floor_index(value) Optional[int]
Finds the rightmost index where the value is less than or equal to the given value
- Parameters
value – the value to search for
- Returns
the index or None if there is no such index
- ceil_index(value) Optional[int]
Finds the leftmost index where the value is greater than or equal to the given value
- Parameters
value – the value to search for
- Returns
the index or None if there is no such index
- closest_index(value) Optional[int]
Finds the index of the value that is closest to the given value. If two subsequent values have the same distance, the smaller index is returned.
- Parameters
value – the value to search for
- Returns
the index or None if this object is empty
- floor_value(value) Optional[sensai.util.datastruct.TValue]
Finds the largest value that is less than or equal to the given value
- Parameters
value – the value to search for
- Returns
the value or None if there is no such value
- ceil_value(value) Optional[sensai.util.datastruct.TValue]
Finds the smallest value that is greater than or equal to the given value
- Parameters
value – the value to search for
- Returns
the value or None if there is no such value
- closest_value(value) Optional[sensai.util.datastruct.TValue]
Finds the value that is closest to the given value. If two subsequent values have the same distance, the smaller value is returned.
- Parameters
value – the value to search for
- Returns
the value or None if this object is empty
- value_slice(lowest_key, highest_key) Optional[Sequence[sensai.util.datastruct.TValue]]
- class SortedKeyValueStructure(*args, **kwds)[source]
Bases:
Generic
[sensai.util.datastruct.TKey
,sensai.util.datastruct.TValue
],abc.ABC
- abstract floor_index(key: sensai.util.datastruct.TKey) Optional[int]
Finds the rightmost index where the key value is less than or equal to the given value
- Parameters
key – the value to search for
- Returns
the index or None if there is no such index
- abstract ceil_index(key: sensai.util.datastruct.TKey) Optional[int]
Finds the leftmost index where the key value is greater than or equal to the given value
- Parameters
key – the value to search for
- Returns
the index or None if there is no such index
- abstract closest_index(key: sensai.util.datastruct.TKey) Optional[int]
Finds the index where the key is closest to the given value. If two subsequent keys have the same distance, the smaller index is returned.
- Parameters
key – the value to search for
- Returns
the index or None if this object is empty.
- abstract floor_value(key: sensai.util.datastruct.TKey) Optional[sensai.util.datastruct.TValue]
Returns the value for the largest index where the corresponding key is less than or equal to the given value
- Parameters
key – the key to search for
- Returns
the value or None if there is no such value
- abstract ceil_value(key: sensai.util.datastruct.TKey) Optional[sensai.util.datastruct.TValue]
Returns the value for the smallest index where the corresponding key is greater than or equal to the given value
- Parameters
key – the key to search for
- Returns
the value or None if there is no such value
- abstract closest_value(key: sensai.util.datastruct.TKey) Optional[sensai.util.datastruct.TValue]
Finds the value that is closest to the given value. If two subsequent values have the same distance, the smaller value is returned.
- Parameters
key – the key to search for
- Returns
the value or None if this object is empty
- abstract floor_key_and_value(key: sensai.util.datastruct.TKey) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- abstract ceil_key_and_value(key: sensai.util.datastruct.TKey) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- abstract closest_key_and_value(key: sensai.util.datastruct.TKey) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- interpolated_value(key: sensai.util.datastruct.TKey) Optional[sensai.util.datastruct.TValue]
Computes a linearly interpolated value for the given key - based on the two closest key-value pairs found in the data structure. If the key is found in the data structure, the corresponding value is directly returned.
NOTE: This operation is supported only for value types that support the required arithmetic operations.
- Parameters
key – the key for which the interpolated value is to be computed.
- Returns
the interpolated value or None if the data structure does not contain floor/ceil entries for the given key
- slice(lower_bound_key=None, upper_bound_key=None, inner=True) sensai.util.datastruct.TSortedKeyValueStructure
- Parameters
lower_bound_key – the key defining the start of the slice (depending on inner); if None, the first included entry will be the very first entry
upper_bound_key – the key defining the end of the slice (depending on inner); if None, the last included entry will be the very last entry
inner – if True, the returned slice will be within the bounds; if False, the returned slice is extended by one entry in both directions such that it contains the bounds (where possible)
- Returns
- class SortedKeysAndValues(keys: Sequence[sensai.util.datastruct.TKey], values: Sequence[sensai.util.datastruct.TValue])[source]
Bases:
Generic
[sensai.util.datastruct.TKey
,sensai.util.datastruct.TValue
],sensai.util.datastruct.SortedKeyValueStructure
[sensai.util.datastruct.TKey
,sensai.util.datastruct.TValue
]- __init__(keys: Sequence[sensai.util.datastruct.TKey], values: Sequence[sensai.util.datastruct.TValue])
- Parameters
keys – a sorted sequence of keys
values – a sequence of corresponding values
- classmethod from_series(s: pandas.core.series.Series)
Creates an instance from a pandas Series, using the series’ index as the keys and its values as the values
- Parameters
s – the series
- Returns
an instance
- floor_index(key) Optional[int]
Finds the rightmost index where the key value is less than or equal to the given value
- Parameters
key – the value to search for
- Returns
the index or None if there is no such index
- ceil_index(key) Optional[int]
Finds the leftmost index where the key value is greater than or equal to the given value
- Parameters
key – the value to search for
- Returns
the index or None if there is no such index
- closest_index(key) Optional[int]
Finds the index where the key is closest to the given value. If two subsequent keys have the same distance, the smaller index is returned.
- Parameters
key – the value to search for
- Returns
the index or None if this object is empty.
- floor_value(key) Optional[sensai.util.datastruct.TValue]
Returns the value for the largest index where the corresponding key is less than or equal to the given value
- Parameters
key – the key to search for
- Returns
the value or None if there is no such value
- ceil_value(key) Optional[sensai.util.datastruct.TValue]
Returns the value for the smallest index where the corresponding key is greater than or equal to the given value
- Parameters
key – the key to search for
- Returns
the value or None if there is no such value
- closest_value(key) Optional[sensai.util.datastruct.TValue]
Finds the value that is closest to the given value. If two subsequent values have the same distance, the smaller value is returned.
- Parameters
key – the key to search for
- Returns
the value or None if this object is empty
- floor_key_and_value(key) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- ceil_key_and_value(key) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- closest_key_and_value(key) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- value_slice_inner(lower_bound_key, upper_bound_key)
- value_slice_outer(lower_bound_key, upper_bound_key, fallback=False)
- class SortedKeyValuePairs(sorted_key_value_pairs: Sequence[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]])[source]
Bases:
Generic
[sensai.util.datastruct.TKey
,sensai.util.datastruct.TValue
],sensai.util.datastruct.SortedKeyValueStructure
[sensai.util.datastruct.TKey
,sensai.util.datastruct.TValue
]- classmethod from_unsorted_key_value_pairs(unsorted_key_value_pairs: Sequence[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]])
- __init__(sorted_key_value_pairs: Sequence[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]])
- value_for_index(idx: int) sensai.util.datastruct.TValue
- key_for_index(idx: int) sensai.util.datastruct.TKey
- floor_index(key) Optional[int]
Finds the rightmost index where the key is less than or equal to the given key
- floor_value(key) Optional[sensai.util.datastruct.TValue]
Returns the value for the largest index where the corresponding key is less than or equal to the given value
- Parameters
key – the key to search for
- Returns
the value or None if there is no such value
- floor_key_and_value(key) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- ceil_index(key) Optional[int]
Find leftmost index where the key is greater than or equal to the given key
- ceil_value(key) Optional[sensai.util.datastruct.TValue]
Returns the value for the smallest index where the corresponding key is greater than or equal to the given value
- Parameters
key – the key to search for
- Returns
the value or None if there is no such value
- ceil_key_and_value(key) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- closest_index(key) Optional[int]
Finds the index where the key is closest to the given value. If two subsequent keys have the same distance, the smaller index is returned.
- Parameters
key – the value to search for
- Returns
the index or None if this object is empty.
- closest_value(key) Optional[sensai.util.datastruct.TValue]
Finds the value that is closest to the given value. If two subsequent values have the same distance, the smaller value is returned.
- Parameters
key – the key to search for
- Returns
the value or None if this object is empty
- closest_key_and_value(key) Optional[Tuple[sensai.util.datastruct.TKey, sensai.util.datastruct.TValue]]
- value_slice(lowest_key, highest_key) Optional[Sequence[sensai.util.datastruct.TValue]]