|
17 | 17 | class KSWINConfig(BaseWindowConfig): |
18 | 18 | """KSWIN (Kolmogorov-Smirnov Windowing) [raab2020reactive]_ configuration. |
19 | 19 |
|
| 20 | + :param alpha: significance value, defaults to 0.0001 |
| 21 | + :type alpha: float |
| 22 | + :param seed: seed value, defaults to None |
| 23 | + :type seed: Optional[int] |
| 24 | + :param min_num_instances: minimum numbers of instances to start looking for changes, defaults to 100 |
| 25 | + :type min_num_instances: int |
| 26 | + :param num_test_instances: numbers of instances to be used by the statistical test, defaults to 30 |
| 27 | + :type num_test_instances: int |
| 28 | + :raises ValueError: Value error exception if seed is not valid |
| 29 | +
|
20 | 30 | :References: |
21 | 31 |
|
22 | 32 | .. [raab2020reactive] Raab, Christoph, Moritz Heusinger, and Frank-Michael Schleif. |
23 | 33 | "Reactive soft prototype computing for concept drift streams." |
24 | 34 | Neurocomputing 416 (2020): 340-351. |
25 | | - """ |
| 35 | + """ # noqa: E501 |
26 | 36 |
|
27 | | - def __init__( |
| 37 | + def __init__( # noqa: D107 |
28 | 38 | self, |
29 | 39 | alpha: float = 0.0001, |
30 | 40 | seed: Optional[int] = None, |
31 | 41 | min_num_instances: int = 100, |
32 | 42 | num_test_instances: int = 30, |
33 | 43 | ) -> None: |
34 | | - """Init method. |
35 | | -
|
36 | | - :param alpha: significance value |
37 | | - :type alpha: float |
38 | | - :param seed: seed value |
39 | | - :type seed: Optional[int] |
40 | | - :param min_num_instances: minimum numbers of instances |
41 | | - to start looking for changes |
42 | | - :type min_num_instances: int |
43 | | - :param num_test_instances: numbers of instances |
44 | | - to be used by the statistical test |
45 | | - :type num_test_instances: int |
46 | | - :raises ValueError: Value error exception |
47 | | - """ |
48 | 44 | try: |
49 | 45 | np.random.seed(seed=seed) |
50 | 46 | except ValueError as e: |
@@ -104,30 +100,43 @@ def num_test_instances(self, value: int) -> None: |
104 | 100 | class KSWIN(BaseWindow): |
105 | 101 | """KSWIN (Kolmogorov-Smirnov Windowing) [raab2020reactive]_ detector. |
106 | 102 |
|
| 103 | + :param config: configuration object of the detector, defaults to None. If None, the default configuration of :class:`KSWINConfig` is used. |
| 104 | + :type config: Optional[KSWINConfig] |
| 105 | + :param callbacks: callbacks, defaults to None |
| 106 | + :type callbacks: Optional[Union[BaseCallbackStreaming, List[BaseCallbackStreaming]]] |
| 107 | +
|
107 | 108 | :References: |
108 | 109 |
|
109 | 110 | .. [raab2020reactive] Raab, Christoph, Moritz Heusinger, and Frank-Michael Schleif. |
110 | 111 | "Reactive soft prototype computing for concept drift streams." |
111 | 112 | Neurocomputing 416 (2020): 340-351. |
112 | | - """ |
| 113 | +
|
| 114 | + :Example: |
| 115 | +
|
| 116 | + >>> from frouros.detectors.concept_drift import KSWIN, KSWINConfig |
| 117 | + >>> import numpy as np |
| 118 | + >>> np.random.seed(seed=31) |
| 119 | + >>> dist_a = np.random.normal(loc=0.2, scale=0.01, size=1000) |
| 120 | + >>> dist_b = np.random.normal(loc=0.8, scale=0.04, size=1000) |
| 121 | + >>> stream = np.concatenate((dist_a, dist_b)) |
| 122 | + >>> detector = KSWIN(config=KSWINConfig(seed=31)) |
| 123 | + >>> for i, value in enumerate(stream): |
| 124 | + ... _ = detector.update(value=value) |
| 125 | + ... if detector.drift: |
| 126 | + ... print(f"Change detected at index {i}") |
| 127 | + ... break |
| 128 | + Change detected at index 1016 |
| 129 | + """ # noqa: E501 |
113 | 130 |
|
114 | 131 | config_type = KSWINConfig |
115 | 132 |
|
116 | | - def __init__( |
| 133 | + def __init__( # noqa: D107 |
117 | 134 | self, |
118 | 135 | config: Optional[KSWINConfig] = None, |
119 | 136 | callbacks: Optional[ |
120 | 137 | Union[BaseCallbackStreaming, List[BaseCallbackStreaming]] |
121 | 138 | ] = None, |
122 | 139 | ) -> None: |
123 | | - """Init method. |
124 | | -
|
125 | | - :param config: configuration parameters |
126 | | - :type config: Optional[KSWINConfig] |
127 | | - :param callbacks: callbacks |
128 | | - :type callbacks: Optional[Union[BaseCallbackStreaming, |
129 | | - List[BaseCallbackStreaming]]] |
130 | | - """ |
131 | 140 | super().__init__( |
132 | 141 | config=config, |
133 | 142 | callbacks=callbacks, |
|
0 commit comments