Skip to content

Commit c57c4df

Browse files
committed
Updated tutorials to use new RNG
1 parent a810207 commit c57c4df

6 files changed

Lines changed: 35 additions & 29 deletions

README.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Typical usage (1-dimensional time series data) with `STUMP <https://stumpy.readt
8282
import numpy as np
8383
8484
if __name__ == "__main__":
85-
your_time_series = np.random.rand(10000)
85+
your_time_series = np.random.default_rng().random(10000)
8686
window_size = 50 # Approximately, how many data points might be found in a pattern
8787
8888
matrix_profile = stumpy.stump(your_time_series, m=window_size)
@@ -97,7 +97,7 @@ Distributed usage for 1-dimensional time series data with Dask Distributed via `
9797
9898
if __name__ == "__main__":
9999
with Client() as dask_client:
100-
your_time_series = np.random.rand(10000)
100+
your_time_series = np.random.default_rng().random(10000)
101101
window_size = 50 # Approximately, how many data points might be found in a pattern
102102
103103
matrix_profile = stumpy.stumped(dask_client, your_time_series, m=window_size)
@@ -111,7 +111,7 @@ GPU usage for 1-dimensional time series data with `GPU-STUMP <https://stumpy.rea
111111
from numba import cuda
112112
113113
if __name__ == "__main__":
114-
your_time_series = np.random.rand(10000)
114+
your_time_series = np.random.default_rng().random(10000)
115115
window_size = 50 # Approximately, how many data points might be found in a pattern
116116
all_gpu_devices = [device.id for device in cuda.list_devices()] # Get a list of all available GPU devices
117117
@@ -125,7 +125,7 @@ Multi-dimensional time series data with `MSTUMP <https://stumpy.readthedocs.io/e
125125
import numpy as np
126126
127127
if __name__ == "__main__":
128-
your_time_series = np.random.rand(3, 1000) # Each row represents data from a different dimension while each column represents data from the same dimension
128+
your_time_series = np.random.default_rng().random((3, 1000)) # Each row represents data from a different dimension while each column represents data from the same dimension
129129
window_size = 50 # Approximately, how many data points might be found in a pattern
130130
131131
matrix_profile, matrix_profile_indices = stumpy.mstump(your_time_series, m=window_size)
@@ -140,7 +140,7 @@ Distributed multi-dimensional time series data analysis with Dask Distributed `M
140140
141141
if __name__ == "__main__":
142142
with Client() as dask_client:
143-
your_time_series = np.random.rand(3, 1000) # Each row represents data from a different dimension while each column represents data from the same dimension
143+
your_time_series = np.random.default_rng().random((3, 1000)) # Each row represents data from a different dimension while each column represents data from the same dimension
144144
window_size = 50 # Approximately, how many data points might be found in a pattern
145145
146146
matrix_profile, matrix_profile_indices = stumpy.mstumped(dask_client, your_time_series, m=window_size)
@@ -153,7 +153,7 @@ Time Series Chains with `Anchored Time Series Chains (ATSC) <https://stumpy.read
153153
import numpy as np
154154
155155
if __name__ == "__main__":
156-
your_time_series = np.random.rand(10000)
156+
your_time_series = np.random.default_rng().random(10000)
157157
window_size = 50 # Approximately, how many data points might be found in a pattern
158158
159159
matrix_profile = stumpy.stump(your_time_series, m=window_size)
@@ -174,7 +174,7 @@ Semantic Segmentation with `Fast Low-cost Unipotent Semantic Segmentation (FLUSS
174174
import numpy as np
175175
176176
if __name__ == "__main__":
177-
your_time_series = np.random.rand(10000)
177+
your_time_series = np.random.default_rng().random(10000)
178178
window_size = 50 # Approximately, how many data points might be found in a pattern
179179
180180
matrix_profile = stumpy.stump(your_time_series, m=window_size)
@@ -236,7 +236,7 @@ In order to fully understand and appreciate the underlying algorithms and applic
236236
Performance
237237
-----------
238238

239-
We tested the performance of computing the exact matrix profile using the Numba JIT compiled version of the code on randomly generated time series data with various lengths (i.e., ``np.random.rand(n)``) along with different `CPU and GPU hardware resources <hardware_>`_.
239+
We tested the performance of computing the exact matrix profile using the Numba JIT compiled version of the code on randomly generated time series data with various lengths (i.e., ``np.random.default_rng().random(n)``) along with different `CPU and GPU hardware resources <hardware_>`_.
240240

241241
.. image:: https://raw.githubusercontent.com/stumpy-dev/stumpy/main/docs/images/performance.png
242242
:alt: STUMPY Performance Plot

docs/Tutorial_Fast_Approximate_Matrix_Profiles.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,14 @@
334334
"cell_type": "markdown",
335335
"metadata": {},
336336
"source": [
337-
"Please keep in mind that the approximate matrix profile is computed by randomly computing distances along a subset of diagonals. So, each time you initialize a new `scrump` object by calling `stumpy.scrump`, this will randomly shuffle the order that the distances are computed, which inevitably results in different approximate matrix profiles (except when `percentage=1.0`). Depending on your use case, to ensure reproducible results, you may consider setting random seed prior to calling `stumpy.scrump`:\n",
337+
"Please keep in mind that the approximate matrix profile is computed by randomly computing distances along a subset of diagonals. So, each time you initialize a new `scrump` object by calling `stumpy.scrump`, this will randomly shuffle the order that the distances are computed, which inevitably results in different approximate matrix profiles (except when `percentage=1.0`). Depending on your use case, to ensure reproducible results, you may consider fixing the random state prior to calling `stumpy.scrump`:\n",
338338
"\n",
339339
"```\n",
340-
"seed = np.random.randint(100000)\n",
341-
"np.random.seed(seed)\n",
340+
"# Get and set random state\n",
341+
"from stumpy import rng\n",
342+
"state = rng.get_state()\n",
343+
"rng.set_state(state)\n",
344+
"\n",
342345
"approx = stumpy.scrump(steam_df['steam flow'], m, percentage=0.01, pre_scrump=False)\n",
343346
"```\n",
344347
"\n",
@@ -503,7 +506,7 @@
503506
"name": "python",
504507
"nbconvert_exporter": "python",
505508
"pygments_lexer": "ipython3",
506-
"version": "3.12.3"
509+
"version": "3.14.6"
507510
}
508511
},
509512
"nbformat": 4,

docs/Tutorial_Matrix_Profiles_For_Streaming_Data.ipynb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"metadata": {},
4848
"outputs": [],
4949
"source": [
50-
"T = np.random.rand(336)"
50+
"rng = np.random.default_rng()\n",
51+
"T = rng.random(336)"
5152
]
5253
},
5354
{
@@ -122,7 +123,7 @@
122123
"metadata": {},
123124
"outputs": [],
124125
"source": [
125-
"t = np.random.rand()"
126+
"t = rng.random()"
126127
]
127128
},
128129
{
@@ -155,7 +156,7 @@
155156
"outputs": [],
156157
"source": [
157158
"for i in range(1000):\n",
158-
" t = np.random.rand()\n",
159+
" t = rng.random()\n",
159160
" stream.update(t)"
160161
]
161162
},
@@ -183,7 +184,7 @@
183184
"metadata": {},
184185
"outputs": [],
185186
"source": [
186-
"T_full = np.random.rand(64)\n",
187+
"T_full = rng.random(64)\n",
187188
"m = 8\n",
188189
"\n",
189190
"mp = stumpy.stump(T_full, m)\n",
@@ -280,7 +281,7 @@
280281
}
281282
],
282283
"source": [
283-
"T_full = np.random.rand(1_000)\n",
284+
"T_full = rng.random(1_000)\n",
284285
"T_stream = T_full[:20].copy()\n",
285286
"m = 10\n",
286287
"\n",
@@ -266241,7 +266242,7 @@
266241266242
}
266242266243
],
266243266244
"source": [
266244-
"T_full = np.random.rand(64)\n",
266245+
"T_full = rng.random(64)\n",
266245266246
"m = 8\n",
266246266247
"\n",
266247266248
"T_stream = T_full[:10].copy()\n",
@@ -266302,7 +266303,7 @@
266302266303
"name": "python",
266303266304
"nbconvert_exporter": "python",
266304266305
"pygments_lexer": "ipython3",
266305-
"version": "3.12.4"
266306+
"version": "3.14.6"
266306266307
}
266307266308
},
266308266309
"nbformat": 4,

docs/Tutorial_Multidimensional_Motif_Discovery.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@
571571
],
572572
"source": [
573573
"for i in range(4, 11):\n",
574-
" df[f'T{i}'] = np.random.uniform(0.1, -0.1, size=df.shape[0]).cumsum()\n",
574+
" df[f'T{i}'] = np.random.default_rng().uniform(0.1, -0.1, size=df.shape[0]).cumsum()\n",
575575
" \n",
576576
"df = df.sample(frac=1, axis=\"columns\") # Randomly shuffle the columns\n",
577577
"\n",
@@ -804,7 +804,7 @@
804804
"name": "python",
805805
"nbconvert_exporter": "python",
806806
"pygments_lexer": "ipython3",
807-
"version": "3.12.4"
807+
"version": "3.14.6"
808808
},
809809
"widgets": {
810810
"application/vnd.jupyter.widget-state+json": {

docs/Tutorial_Pattern_Matching.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,9 @@
645645
}
646646
],
647647
"source": [
648-
"Q_random = np.random.rand(100)\n",
649-
"T_random = np.random.rand(1_000_000)\n",
648+
"rng = np.random.default_rng()\n",
649+
"Q_random = rng.random(100)\n",
650+
"T_random = rng.random(1_000_000)\n",
650651
"\n",
651652
"naive_distance_profile = compute_naive_distance_profile(Q_random, T_random)"
652653
]
@@ -736,7 +737,7 @@
736737
"name": "python",
737738
"nbconvert_exporter": "python",
738739
"pygments_lexer": "ipython3",
739-
"version": "3.10.4"
740+
"version": "3.14.6"
740741
}
741742
},
742743
"nbformat": 4,

docs/Tutorial_Time_Series_Chains.ipynb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@
7070
}
7171
],
7272
"source": [
73-
"x = np.random.rand(20)\n",
74-
"y = np.random.rand(20)\n",
73+
"rng = np.random.default_rng()\n",
74+
"x = rng.random(20)\n",
75+
"y = rng.random(20)\n",
7576
"n = 10\n",
76-
"motifs_x = 0.5 * np.ones(n) + np.random.uniform(-0.05, 0.05, n)\n",
77-
"motifs_y = 0.5 * np.ones(n) + np.random.uniform(-0.05, 0.05, n)\n",
77+
"motifs_x = 0.5 * np.ones(n) + rng.uniform(-0.05, 0.05, n)\n",
78+
"motifs_y = 0.5 * np.ones(n) + rng.uniform(-0.05, 0.05, n)\n",
7879
"sin_x = np.linspace(0, np.pi/2, n+1)\n",
7980
"sin_y = np.sin(sin_x)/4\n",
8081
"chains_x = 0.5 * np.ones(n+1) + 0.02 * np.arange(n+1)\n",
@@ -605,7 +606,7 @@
605606
"name": "python",
606607
"nbconvert_exporter": "python",
607608
"pygments_lexer": "ipython3",
608-
"version": "3.12.4"
609+
"version": "3.14.6"
609610
}
610611
},
611612
"nbformat": 4,

0 commit comments

Comments
 (0)