Skip to content

Commit bb999cc

Browse files
committed
docs: fixes and updates
1 parent ab29ba3 commit bb999cc

6 files changed

Lines changed: 66 additions & 32 deletions

File tree

pysatl_cpd/analysis/labeled_data.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,27 @@ def __str__(self) -> str:
101101

102102
@property
103103
def raw_data(self) -> Collection[T]:
104+
"""
105+
Return the raw observation data.
106+
107+
Returns
108+
-------
109+
Collection[T]
110+
The sequential observations forming the time series.
111+
"""
104112
return self.__raw_data
105113

106114
@property
107115
def change_points(self) -> Sequence[int]:
116+
"""
117+
Return the known change point indices.
118+
119+
Each index indicates the first observation after a regime change,
120+
i.e., a change occurs between observations at index ``i-1`` and ``i``.
121+
122+
Returns
123+
-------
124+
Sequence[int]
125+
Indices of change points in the data.
126+
"""
108127
return self.__change_points

pysatl_cpd/core/data_providers/idata_provider.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class DataProvider[T](ABC):
3232
The type of a single observation yielded by the provider.
3333
For univariate data, T is typically a scalar numeric type.
3434
For multivariate data, T is typically a one-dimensional array.
35+
name : str or None, optional
36+
Optional human-readable identifier for the data provider.
37+
If None, defaults to the class name. Default is None.
3538
"""
3639

3740
def __init__(self, name: str | None) -> None:
@@ -63,5 +66,14 @@ def __len__(self) -> int:
6366

6467
@property
6568
def name(self) -> str:
66-
"""Return the name of the DataProvider"""
69+
"""
70+
Return the name of the data provider.
71+
72+
If no name was provided at initialization, returns the class name.
73+
74+
Returns
75+
-------
76+
str
77+
Human-readable identifier for this data provider.
78+
"""
6779
return self._name

pysatl_cpd/core/data_providers/numpy_data_provider.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class NDArrayUnivariateProvider(DataProvider[NumPyNumber]):
3131
data : NumericArray
3232
A one-dimensional array of univariate observations. The array must contain
3333
numeric values and have exactly one dimension.
34+
name : str or None, optional
35+
Optional human-readable identifier for the data provider.
36+
If None, defaults to the class name. Default is None.
3437
3538
Raises
3639
------
@@ -106,6 +109,9 @@ class NDArrayMultivariateProvider(DataProvider[UnivariateNumericArray]):
106109
data : NumericArray
107110
An array with ``ndim == 2``. The first axis indexes observations over time,
108111
while the second axis represents multivariate components.
112+
name : str or None, optional
113+
Optional human-readable identifier for the data provider.
114+
If None, defaults to the class name. Default is None.
109115
110116
Raises
111117
------

pysatl_cpd/core/detection_trace.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class DetectionTrace:
3434
3535
Examples
3636
--------
37-
>>> from pysatl_cpd.data_providers import NDArrayUnivariateProvider
3837
>>> trace = DetectionTrace(detected_change_points=[2, 4])
3938
>>> trace.detected_changes
4039
[2, 4]

pysatl_cpd/core/online/online_cpd_solver.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ class OnlineCpdSolver:
3030
3131
Parameters
3232
----------
33-
algorithm : OnlineAlgorithm[DataT, ConfugrationT, StateT]
34-
The online change-point detection algorithm to apply.
35-
threshold : float, optional
36-
Detection threshold for the change-point function. A change point is
37-
declared when the statistic exceeds this value.
38-
If `nan`, the algorithm will not generate any signals. Default is ``nan``.
3933
skip_period : int, optional
4034
Number of steps to skip (suppress detections) after each declared
4135
change point. Must be non-negative. Default is ``0``.
@@ -62,18 +56,6 @@ def __init__(
6256
max_runlength: int | None = None,
6357
collect_states: bool = True,
6458
) -> None:
65-
"""
66-
Initialize the online change-point detection solver.
67-
68-
Parameters
69-
----------
70-
skip_period : int, optional
71-
Number of steps to skip after each declared change point.
72-
max_runlength : int or None, optional
73-
Maximum run length before forcing a change point.
74-
collect_states : bool, optional
75-
Whether to collect algorithm state snapshots.
76-
"""
7759
# Validate skip_period is non-negative
7860
if skip_period < 0:
7961
raise ValueError(f"skip_period must be non-negative, got {skip_period}")
@@ -102,12 +84,15 @@ def run[DataT, ConfugrationT: OnlineAlgorithmConfiguration, StateT: OnlineAlgori
10284
10385
Parameters
10486
----------
105-
algorithm : OnlineAlgorithm[T]
87+
algorithm : OnlineAlgorithm[DataT, ConfugrationT, StateT]
10688
The online change-point detection algorithm to apply.
10789
data_provider : DataProvider[DataT]
10890
An iterable source of observations.
10991
threshold : float, optional
110-
Detection threshold for the change-point function.
92+
Detection threshold for the change-point function. A change point
93+
is declared when the statistic exceeds this value.
94+
If ``nan``, the algorithm will not generate any signals.
95+
Default is ``nan``.
11196
11297
Yields
11398
------
@@ -182,7 +167,7 @@ def _is_signal_change_point(self, detection_func: Number, threshold: float) -> b
182167
----------
183168
detection_func : Number
184169
Current detection statistic value.
185-
threshold : floatl
170+
threshold : float
186171
Detection threshold for the change-point function.
187172
188173
Returns

pysatl_cpd/core/online/online_detection_trace.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ class OnlineDetectionStepResult[StateT: OnlineAlgorithmState]:
7070
----------
7171
step_num : int, default=0
7272
Zero-based index of the processed observation.
73-
is_change_point : bool, default=False
74-
Whether a changepoint was detected at this step.
75-
is_force_change_point : bool, default=False
73+
is_forced_change_point : bool, default=False
7674
Whether a changepoint was forced due to maximum runlength constraint.
75+
is_signal_change_point : bool, default=False
76+
Whether a changepoint was detected by the algorithm's detection
77+
function exceeding the threshold.
7778
is_in_skip_period : bool, default=False
7879
Whether this step occurred during a post-detection skip period.
7980
detection_function : Number, default=nan
8081
The value of the detection statistic computed for this observation.
8182
processing_time : Number, default=nan
8283
Wall-clock time in seconds spent processing this step.
83-
algorithm_state : StateT | None, default=None
84+
algorithm_state : StateT or None, default=None
8485
Snapshot of algorithm internal state after processing this step.
8586
"""
8687

@@ -94,6 +95,18 @@ class OnlineDetectionStepResult[StateT: OnlineAlgorithmState]:
9495

9596
@property
9697
def is_change_point(self) -> bool:
98+
"""
99+
Whether a changepoint was detected at this step.
100+
101+
A changepoint is considered detected if it was either forced
102+
(due to maximum runlength) or signaled (detection function
103+
exceeded threshold).
104+
105+
Returns
106+
-------
107+
bool
108+
True if a forced or signal changepoint occurred, False otherwise.
109+
"""
97110
return self.is_forced_change_point or self.is_signal_change_point
98111

99112

@@ -126,11 +139,11 @@ class OnlineDetectionTrace[StateT: OnlineAlgorithmState](DetectionTrace):
126139
Indices of beginning and ending of segments where algorithm was
127140
learning data distribution before change point. Default is empty list.
128141
forced_change_points : list[int], optional
129-
Indices where changepoints were forced due to maximum runlength.
130-
Default is empty list.
131-
forced_change_points : list[int], optional
132-
Indices where changepoints were forced due algorithm detection function
133-
overcoming threshold. Default is empty list.
142+
Indices where changepoints were forced due to maximum runlength
143+
constraint. Default is empty list.
144+
signal_change_points : list[int], optional
145+
Indices where changepoints were detected due to the algorithm's
146+
detection function exceeding the threshold. Default is empty list.
134147
"""
135148

136149
threshold: Number | None = None

0 commit comments

Comments
 (0)