segment
Segment and state descriptors for the data layer.
- class pysatl_cpd.data.typedefs.segment.StateDescriptor(**kwargs)[source]
Bases:
Mapping[str,StateValue]Immutable mapping for state attributes.
This class provides an immutable mapping interface for storing state attributes as key-value pairs. It uses frozendict internally to ensure hashability and immutability.
- __init__(**kwargs)[source]
- Parameters:
kwargs (StateValue)
- __len__()[source]
Get number of state attributes.
- Returns:
Number of key-value pairs in the state.
- Return type:
- class pysatl_cpd.data.typedefs.segment.TransitionDescriptor(*, curr_state, next_state)[source]
Bases:
objectTransition between two states.
This class represents a transition from a current state to a next state, used for tracking state changes in time series segments.
- Variables:
curr_state – The current state before the transition.
next_state – The next state after the transition.
- Parameters:
curr_state (StateDescriptor)
next_state (StateDescriptor)
- curr_state: StateDescriptor
- next_state: StateDescriptor
- __repr__()[source]
Return a string representation of the transition.
- Returns:
Current state and next state separated by an arrow.
- Return type:
- __init__(*, curr_state, next_state)
- Parameters:
curr_state (StateDescriptor)
next_state (StateDescriptor)
- Return type:
None
- class pysatl_cpd.data.typedefs.segment.SegmentInfo(*, segment_num, segment_start, segment_end, state)[source]
Bases:
objectInformation about a time series segment.
This class represents a contiguous segment of a time series with a specific state, including the segment number and start/end indices.
- Variables:
segment_num – Sequential number of the segment.
segment_start – Start index of the segment (inclusive, zero-based).
segment_end – End index of the segment (inclusive, zero-based).
state – The state descriptor for this segment.
- Parameters:
segment_num (int)
segment_start (int)
segment_end (int)
state (StateDescriptor)
- state: StateDescriptor
- __post_init__()[source]
Validate segment indices.
- Raises:
ValueError – If segment_start is negative, or segment_end is less than segment_start.
- Return type:
- classmethod from_change_points_and_states(total_len, change_points, segment_states)[source]
Create segment infos from change points and states.
This class method constructs a tuple of SegmentInfo objects from the total length of the series, change point indices, and corresponding segment states.
- Parameters:
- Returns:
Tuple of SegmentInfo objects for each segment.
- Return type:
- Raises:
ValueError – If the number of segment_states is not exactly one more than the number of change_points.
- __init__(*, segment_num, segment_start, segment_end, state)
- Parameters:
segment_num (int)
segment_start (int)
segment_end (int)
state (StateDescriptor)
- Return type:
None
- class pysatl_cpd.data.typedefs.segment.BisegmentInfo(*, bisegment_num, bisegment_start, bisegment_end, change_point, transition)[source]
Bases:
objectInformation about a bisegment spanning a change point.
This class represents a bisegment that spans a change point, including the transition between two states.
- Variables:
bisegment_num – Sequential number of the bisegment.
bisegment_start – Start index of the bisegment (inclusive, zero-based).
bisegment_end – End index of the bisegment (inclusive, zero-based).
change_point – Index of the change point within the bisegment.
transition – Transition descriptor for the state change.
- Parameters:
bisegment_num (int)
bisegment_start (int)
bisegment_end (int)
change_point (int)
transition (TransitionDescriptor)
- transition: TransitionDescriptor
- __post_init__()[source]
Validate bisegment boundaries and change-point position.
- Raises:
ValueError – If bisegment_start is negative, bisegment_end is less than bisegment_start, or change_point is not within [bisegment_start, bisegment_end].
- Return type:
- classmethod from_segment_tuple(segments)[source]
Create bisegment info from a pair of segments.
This method constructs a BisegmentInfo from two consecutive SegmentInfo objects, extracting the bisegment boundaries and creating a transition descriptor.
- Parameters:
segments (
tuple[SegmentInfo,SegmentInfo]) – Tuple of two consecutive SegmentInfo objects.- Returns:
The constructed BisegmentInfo object.
- Return type: