Skip to content

Commit 1f19788

Browse files
authored
Merge pull request #39 from wwhenxuan/master
Update PySDKit 0.4.21 for STL
2 parents 2e1daa8 + d10ce92 commit 1f19788

File tree

14 files changed

+399
-281
lines changed

14 files changed

+399
-281
lines changed

.gitignore

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,26 @@
1+
# Byte-compiled / optimized / DLL files
12
__pycache__/
2-
*workspace
33
*.py[cod]
4-
build/
5-
develop-eggs/
6-
dist/
7-
downloads/
8-
eggs/
9-
.eggs/
10-
lib/
11-
lib64/
12-
parts/
13-
sdist/
14-
var/
15-
wheels/
16-
pip-wheel-metadata/
17-
htmlcov/
18-
.tox/
19-
.nox/
20-
.hypothesis/
21-
.pytest_cache/
4+
*$py.class
5+
6+
# C developer
7+
*.so
8+
9+
# File for PyPI
2210
*.egg-info/
23-
.vscode/
24-
.*.swp
25-
.coverage
26-
.coverage.*
27-
.cache
28-
nosetests.xml
29-
coverage.xml
30-
junit*.xml
31-
*.cover
32-
MANIFEST
33-
.installed.cfg
34-
*.egg
35-
*.manifest
36-
*.spec
37-
*.log
38-
*.con
39-
*.out
40-
env.sh
41-
*-env.sh
11+
dist/
12+
build/
13+
14+
# IDE config
15+
.idea/
16+
.spyderproject
17+
.ropeproject
18+
19+
# Python env
20+
.venv/
21+
venv/
22+
.env
23+
.python-version
24+
25+
# save the test data
26+
/data/

README.md

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

example/demo.ipynb

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

example/example_zh/tsa/stl.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+
}

example/tsa/stl.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: 6 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.20"
5+
__version__ = "0.4.21"
66

77
# Empirical Mode Decomposition
88
from ._emd import EMD
@@ -79,6 +79,9 @@
7979
# Moving Average Decomposition
8080
from .tsa import Moving_Decomp
8181

82+
# Seasonal-Trend decomposition using LOESS (STL)
83+
from .tsa import STL
84+
8285
# Hilbert-Huang Transform
8386
from ._emd import HHT
8487

@@ -130,6 +133,7 @@ def print_functions():
130133
Empirical Wavelet Transform | EWT
131134
Jump Plus AM-FM Mode Decomposition | JMD
132135
Moving Average Decomposition | Moving
136+
Seasonal-Trend decomposition using LOESS | STL
133137
Hilbert-Huang Transform | HHT
134138
_______________________________________________________________
135139
"""
@@ -164,6 +168,7 @@ def print_functions():
164168
"EWT",
165169
"JMD",
166170
"Moving_Decomp",
171+
"STL",
167172
"models",
168173
"data",
169174
"entropy",

pysdkit/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@
9090
from ._cube import test_multivariate_cube
9191

9292
# Test case for Principal Component Analysis
93-
from ._models import test_pca
93+
from ._models import test_pca

pysdkit/data/_models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from typing import Optional, Tuple
1010

1111

12-
def test_pca(number: int = 200, dim: int = 2, random_state: Optional[int] = 42) -> np.ndarray:
12+
def test_pca(
13+
number: int = 200, dim: int = 2, random_state: Optional[int] = 42
14+
) -> np.ndarray:
1315
"""
1416
Generate synthetic data for testing Principal Component Analysis (PCA).
1517
The dataset is created by multiplying a set of coordinate points (default 2-D)
@@ -30,4 +32,4 @@ def test_pca(number: int = 200, dim: int = 2, random_state: Optional[int] = 42)
3032
# Generate a random rotation matrix
3133
rot = rng.rand(dim, dim)
3234

33-
return np.dot(rot, rng.randn(dim, number)).T
35+
return np.dot(rot, rng.randn(dim, number)).T

pysdkit/models/_pca.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def variance_(self) -> np.ndarray | List[float]:
208208
else:
209209
raise ValueError("Please run the PCA algorithm first!")
210210

211+
211212
# if __name__ == "__main__":
212213
# # 创建示例数据(4个样本,3个特征)
213214
# X = np.array([[2.5, 2.4, 3.1], [0.5, 0.7, 1.2], [2.2, 2.9, 2.5], [1.9, 2.2, 1.8]])

pysdkit/tests/models/test_pca.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@ def test_create_pca(self) -> None:
2727
n_components,
2828
msg="创建的PCA对象中的属性参数与传入的超参数不一致",
2929
)
30+
3031
def test_none(self) -> None:
3132
"""测试在未执行`fit_transform`方法前PCA中的初始化数据属性是否为None"""
3233
# 创建K近邻分类器实例对象
3334
pca = PCA(n_components=2)
3435
# 检验初始的拟合数据是否为None
35-
self.assertIsNone(pca.X_reduced, msg="创建的PCA对象在未拟合数据时数据对象为非None")
36-
self.assertIsNone(pca._components, msg="创建的PCA对象在未拟合数据时数据对象为非None")
37-
self.assertIsNone(pca._explained_variance_ratio, msg="创建的PCA对象在未拟合数据时数据对象为非None")
36+
self.assertIsNone(
37+
pca.X_reduced, msg="创建的PCA对象在未拟合数据时数据对象为非None"
38+
)
39+
self.assertIsNone(
40+
pca._components, msg="创建的PCA对象在未拟合数据时数据对象为非None"
41+
)
42+
self.assertIsNone(
43+
pca._explained_variance_ratio,
44+
msg="创建的PCA对象在未拟合数据时数据对象为非None",
45+
)
3846

3947
def test_wrong_shape_inputs(self) -> None:
4048
"""测试PCA算法的非法的形状输入"""
@@ -60,4 +68,4 @@ def test_wrong_type_inputs(self) -> None:
6068

6169
def test_fit_transform(self) -> None:
6270
"""测试PCA算法能否正确执行"""
63-
X = ...
71+
X = ...

0 commit comments

Comments
 (0)