Skip to content

Commit 6bc50bb

Browse files
authored
Merge pull request #35 from wwhenxuan/master
Update the Version of PySDKit 0.4.20
2 parents 2d49cc3 + bf24cc7 commit 6bc50bb

File tree

24 files changed

+1396
-80
lines changed

24 files changed

+1396
-80
lines changed

docs/source/API/pysdkit.tsa.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tsa.knn
3232
---------------------------
3333

3434
.. automodule:: pysdkit.tsa._knn
35-
.. autoclass:: pysdkit.tsa._knn.KnnDtw
35+
.. autoclass:: pysdkit.tsa._knn.KNN
3636
:members:
3737
:undoc-members:
3838
:private-members:

example/data_generator.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
},
115115
"cell_type": "code",
116116
"source": [
117-
"# Here we switch the number of the test samples and visualize their frequency domain characteristics.\n",
117+
"# Here we switch the number of the test X and visualize their frequency domain characteristics.\n",
118118
"time, signal = test_univariate_signal(case=2)\n",
119119
"fig = plot_signal(time, signal, spectrum=True)"
120120
],
@@ -190,7 +190,7 @@
190190
},
191191
"cell_type": "code",
192192
"source": [
193-
"# Switch the number of test samples\n",
193+
"# Switch the number of test X\n",
194194
"time, signal = test_multivariate_signal(case=2)\n",
195195
"fig = plot_signal(time, signal, spectrum=True)"
196196
],

example/demo.ipynb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"metadata": {
77
"collapsed": true,
88
"ExecuteTime": {
9-
"end_time": "2025-07-17T03:21:49.953258Z",
10-
"start_time": "2025-07-17T03:21:49.216362Z"
9+
"end_time": "2025-07-22T13:58:02.559853Z",
10+
"start_time": "2025-07-22T13:58:01.838243Z"
1111
}
1212
},
1313
"source": [
@@ -30,8 +30,8 @@
3030
"metadata": {
3131
"collapsed": false,
3232
"ExecuteTime": {
33-
"end_time": "2025-07-17T03:21:50.206086Z",
34-
"start_time": "2025-07-17T03:21:50.111514Z"
33+
"end_time": "2025-07-22T13:58:02.654908Z",
34+
"start_time": "2025-07-22T13:58:02.563875Z"
3535
}
3636
},
3737
"id": "1af048fdecdd07b5",
@@ -60,8 +60,8 @@
6060
"metadata": {
6161
"collapsed": false,
6262
"ExecuteTime": {
63-
"end_time": "2025-07-17T03:21:50.428697Z",
64-
"start_time": "2025-07-17T03:21:50.210156Z"
63+
"end_time": "2025-07-22T13:58:03.032538Z",
64+
"start_time": "2025-07-22T13:58:02.796522Z"
6565
}
6666
},
6767
"id": "65e9ea5b377df1a4",
@@ -82,8 +82,8 @@
8282
{
8383
"metadata": {
8484
"ExecuteTime": {
85-
"end_time": "2025-07-17T03:21:50.664629Z",
86-
"start_time": "2025-07-17T03:21:50.446632Z"
85+
"end_time": "2025-07-22T13:58:03.301349Z",
86+
"start_time": "2025-07-22T13:58:03.049584Z"
8787
}
8888
},
8989
"cell_type": "code",
@@ -127,8 +127,8 @@
127127
"metadata": {
128128
"collapsed": false,
129129
"ExecuteTime": {
130-
"end_time": "2025-07-17T03:21:51.257821Z",
131-
"start_time": "2025-07-17T03:21:50.678659Z"
130+
"end_time": "2025-07-22T13:58:04.006736Z",
131+
"start_time": "2025-07-22T13:58:03.318341Z"
132132
}
133133
},
134134
"id": "36cd37054ec6ba22",
@@ -164,8 +164,8 @@
164164
"metadata": {
165165
"collapsed": false,
166166
"ExecuteTime": {
167-
"end_time": "2025-07-17T03:21:51.657130Z",
168-
"start_time": "2025-07-17T03:21:51.340061Z"
167+
"end_time": "2025-07-22T13:58:04.337209Z",
168+
"start_time": "2025-07-22T13:58:04.027737Z"
169169
}
170170
},
171171
"id": "d066e800d5dd681a",
@@ -193,26 +193,26 @@
193193
{
194194
"metadata": {
195195
"ExecuteTime": {
196-
"end_time": "2025-07-17T03:21:51.687147Z",
197-
"start_time": "2025-07-17T03:21:51.671130Z"
196+
"end_time": "2025-07-22T13:58:04.368264Z",
197+
"start_time": "2025-07-22T13:58:04.355190Z"
198198
}
199199
},
200200
"cell_type": "code",
201201
"source": "",
202-
"id": "ed3ea5b6e4975fcc",
202+
"id": "90b80872d654572e",
203203
"outputs": [],
204204
"execution_count": null
205205
},
206206
{
207207
"metadata": {
208208
"ExecuteTime": {
209-
"end_time": "2025-07-17T01:18:57.758434Z",
210-
"start_time": "2025-07-17T01:18:57.742430Z"
209+
"end_time": "2025-07-22T13:58:04.399956Z",
210+
"start_time": "2025-07-22T13:58:04.384984Z"
211211
}
212212
},
213213
"cell_type": "code",
214214
"source": "",
215-
"id": "cde2d45ca5b42b5e",
215+
"id": "3413958f0630f43a",
216216
"outputs": [],
217217
"execution_count": null
218218
},
@@ -222,7 +222,7 @@
222222
"outputs": [],
223223
"execution_count": null,
224224
"source": "",
225-
"id": "90b80872d654572e"
225+
"id": "8c71740dde571d35"
226226
}
227227
],
228228
"metadata": {

example/example_zh/models/PCA.ipynb

Lines changed: 280 additions & 0 deletions
Large diffs are not rendered by default.

example/example_zh/models/knn.ipynb

Lines changed: 272 additions & 0 deletions
Large diffs are not rendered by default.

example/tsa/knn.ipynb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "initial_id",
7+
"metadata": {
8+
"collapsed": true
9+
},
10+
"outputs": [],
11+
"source": [
12+
""
13+
]
14+
}
15+
],
16+
"metadata": {
17+
"kernelspec": {
18+
"display_name": "Python 3",
19+
"language": "python",
20+
"name": "python3"
21+
},
22+
"language_info": {
23+
"codemirror_mode": {
24+
"name": "ipython",
25+
"version": 2
26+
},
27+
"file_extension": ".py",
28+
"mimetype": "text/x-python",
29+
"name": "python",
30+
"nbconvert_exporter": "python",
31+
"pygments_lexer": "ipython2",
32+
"version": "2.7.6"
33+
}
34+
},
35+
"nbformat": 4,
36+
"nbformat_minor": 5
37+
}

pysdkit/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
A Python library for signal decomposition algorithms.
33
"""
44

5-
__version__ = "0.4.19"
5+
__version__ = "0.4.20"
66

77
# Empirical Mode Decomposition
88
from ._emd import EMD
@@ -164,6 +164,7 @@ def print_functions():
164164
"EWT",
165165
"JMD",
166166
"Moving_Decomp",
167+
"models",
167168
"data",
168169
"entropy",
169170
"HHT",

pysdkit/data/__init__.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
@author: Whenxuan Wang
55
@email: wwhenxuan@gmail.com
66
"""
7+
__all__ = [
8+
"generate_sin_signal",
9+
"generate_cos_signal",
10+
"generate_time_series",
11+
"generate_square_wave",
12+
"generate_triangle_wave",
13+
"generate_sawtooth_wave",
14+
"generate_am_signal",
15+
"generate_exponential_signal",
16+
"test_emd",
17+
"test_hht",
18+
"add_noise",
19+
"test_univariate_signal",
20+
"test_univariate_nonlinear_chip",
21+
"test_univariate_gaussamp_quadfm",
22+
"test_univariate_duffing",
23+
"test_univariate_logistic_am",
24+
"test_univariate_cubic_quad",
25+
"test_multivariate_signal",
26+
"get_meshgrid_2D",
27+
"test_grayscale",
28+
"test_univariate_image",
29+
"test_multivariate_image",
30+
"test_univariate_cube",
31+
"test_multivariate_cube",
32+
"test_pca",
33+
]
734

835
# A series of functions for generating 1D NumPy signals
936
from ._generator import generate_sin_signal, generate_cos_signal
@@ -24,12 +51,26 @@
2451
# Generate the test function for HHT
2552
from ._generator import test_hht
2653

27-
# Generator for 1D multivariate
28-
from ._generator import test_multivariate_signal
29-
3054
# add Gaussian noise
3155
from ._add_noise import add_noise
3256

57+
# Generator for 1D univariate
58+
from ._test_univariate import test_univariate_signal
59+
60+
# Generator for 1D univariate nonlinear chip signal
61+
from ._test_univariate import test_univariate_nonlinear_chip
62+
63+
# Generator for other univariate with different characterization
64+
from ._test_univariate import (
65+
test_univariate_gaussamp_quadfm,
66+
test_univariate_duffing,
67+
test_univariate_logistic_am,
68+
test_univariate_cubic_quad,
69+
)
70+
71+
# Generator for 1D multivariate
72+
from ._generator import test_multivariate_signal
73+
3374
# Generate a grid matrix given an input and output range
3475
from ._image import get_meshgrid_2D
3576

@@ -48,16 +89,5 @@
4889
# Test case for multivariate 3D cube
4990
from ._cube import test_multivariate_cube
5091

51-
# Generator for 1D univariate
52-
from ._test_univariate import test_univariate_signal
53-
54-
# Generator for 1D univariate nonlinear chip signal
55-
from ._test_univariate import test_univariate_nonlinear_chip
56-
57-
# Generator for other univariate with different characterization
58-
from ._test_univariate import (
59-
test_univariate_gaussamp_quadfm,
60-
test_univariate_duffing,
61-
test_univariate_logistic_am,
62-
test_univariate_cubic_quad,
63-
)
92+
# Test case for Principal Component Analysis
93+
from ._models import test_pca

pysdkit/data/_models.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on 2025/07/22 17:46:28
4+
@author: Whenxuan Wang
5+
@email: wwhenxuan@gmail.com
6+
"""
7+
import numpy as np
8+
9+
from typing import Optional, Tuple
10+
11+
12+
def test_pca(number: int = 200, dim: int = 2, random_state: Optional[int] = 42) -> np.ndarray:
13+
"""
14+
Generate synthetic data for testing Principal Component Analysis (PCA).
15+
The dataset is created by multiplying a set of coordinate points (default 2-D)
16+
by a random rotation matrix.
17+
18+
:param number: int, optional
19+
Number of data points to generate, by default 200.
20+
:param dim: int, optional
21+
Dimensionality of the generated data, by default 2.
22+
:param random_state: int, optional
23+
Random seed for reproducibility, by default 42.
24+
:return: X : np.ndarray
25+
Generated test data of shape [n_samples, n_features].
26+
"""
27+
# Initialize random number generator
28+
rng = np.random.RandomState(random_state)
29+
30+
# Generate a random rotation matrix
31+
rot = rng.rand(dim, dim)
32+
33+
return np.dot(rot, rng.randn(dim, number)).T

pysdkit/models/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on 2025/07/21 15:26:00
4+
@author: Whenxuan Wang
5+
@email: wwhenxuan@gmail.com
6+
"""
7+
8+
from pysdkit.models._knn import KNN
9+
10+
from pysdkit.models._pca import pca, PCA

0 commit comments

Comments
 (0)