segment

Segment and state descriptors for the data layer.

type pysatl_cpd.data.typedefs.segment.StateValue = str | int | float | bool
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.

Parameters:

**kwargs (str | int | float | bool) – Key-value pairs representing state attributes.

__init__(**kwargs)[source]
Parameters:

kwargs (StateValue)

__getitem__(key)[source]

Get state value by key.

Parameters:

key (str) – The key to look up.

Returns:

The value associated with the key.

Return type:

str | int | float | bool

__iter__()[source]

Iterate over state keys.

Returns:

Iterator over the state keys.

Return type:

Iterator[str]

__len__()[source]

Get number of state attributes.

Returns:

Number of key-value pairs in the state.

Return type:

int

__repr__()[source]

Return a string representation of the state descriptor.

Returns:

Pipe-separated key=value pairs sorted by key.

Return type:

str

__hash__()[source]

Get hash of the state descriptor.

Returns:

Hash value of the underlying frozendict.

Return type:

int

class pysatl_cpd.data.typedefs.segment.TransitionDescriptor(*, curr_state, next_state)[source]

Bases: object

Transition 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
__repr__()[source]

Return a string representation of the transition.

Returns:

Current state and next state separated by an arrow.

Return type:

str

__hash__()[source]

Return a stable hash for the transition descriptor.

Return type:

int

__init__(*, curr_state, next_state)
Parameters:
Return type:

None

class pysatl_cpd.data.typedefs.segment.SegmentInfo(*, segment_num, segment_start, segment_end, state)[source]

Bases: object

Information 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
__post_init__()[source]

Validate segment indices.

Raises:

ValueError – If segment_start is negative, or segment_end is less than segment_start.

Return type:

None

__hash__()[source]

Return a stable hash for segment metadata.

Return type:

int

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:
  • total_len (int) – Total length of the time series.

  • change_points (tuple[int, ...]) – Tuple of change point indices (zero-based).

  • segment_states (Sequence[StateDescriptor]) – Sequence of state descriptors for each segment.

Returns:

Tuple of SegmentInfo objects for each segment.

Return type:

tuple[SegmentInfo, ...]

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:
Return type:

None

class pysatl_cpd.data.typedefs.segment.BisegmentInfo(*, bisegment_num, bisegment_start, bisegment_end, change_point, transition)[source]

Bases: object

Information 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
__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:

None

__hash__()[source]

Return a stable hash for bisegment metadata.

Return type:

int

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:

BisegmentInfo

__init__(*, bisegment_num, bisegment_start, bisegment_end, change_point, transition)
Parameters:
Return type:

None