Skip to content

Commit 3ed8e5c

Browse files
MNT refactor the project structure (#27)
* MNT refactor the project structure
1 parent 1ae7d9e commit 3ed8e5c

File tree

13 files changed

+164
-149
lines changed

13 files changed

+164
-149
lines changed

doc/index.rst

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,41 @@
99

1010
.. include:: ../README.rst
1111

12-
.. currentmodule:: fastcan
1312

1413

1514
API Reference
1615
-------------
17-
.. autosummary::
18-
:toctree: generated/
19-
20-
FastCan
21-
refine
22-
minibatch
23-
ssc
24-
ols
25-
make_poly_ids
26-
make_poly_features
27-
make_time_shift_features
28-
make_time_shift_ids
29-
make_narx
30-
print_narx
31-
Narx
16+
.. automodule:: fastcan
17+
18+
.. rubric:: Classes
19+
20+
.. autosummary::
21+
:toctree: generated/
22+
23+
FastCan
24+
25+
.. rubric:: Functions
26+
27+
.. autosummary::
28+
:toctree: generated/
29+
30+
refine
31+
minibatch
32+
33+
.. rubric:: Submodules
34+
35+
.. autosummary::
36+
:toctree: generated/
37+
38+
narx
39+
utils
3240

3341
Useful Links
3442
------------
3543
.. toctree::
3644
:maxdepth: 2
3745

38-
User Guild <user_guide>
46+
User Guide <user_guide>
3947
Examples <auto_examples/index>
4048

4149
API Compatibility

doc/templates/autosummary/module.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{ objname | escape | underline(line="=") }}
2+
3+
.. automodule:: {{ fullname }}
4+
5+
{% block classes %}
6+
{% if classes %}
7+
.. rubric:: {{ _('Classes') }}
8+
9+
.. autosummary::
10+
:toctree:
11+
{% for item in classes %}
12+
{{ item }}
13+
{%- endfor %}
14+
{% endif %}
15+
{% endblock %}
16+
17+
18+
{% block functions %}
19+
{% if functions %}
20+
.. rubric:: {{ _('Functions') }}
21+
22+
.. autosummary::
23+
:toctree:
24+
{% for item in functions %}
25+
{{ item }}
26+
{%- endfor %}
27+
{% endif %}
28+
{% endblock %}

examples/plot_affinity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
from sklearn.datasets import load_diabetes
2424
from sklearn.linear_model import OrthogonalMatchingPursuit
2525

26-
from fastcan import FastCan, ols
26+
from fastcan import FastCan
27+
from fastcan.utils import ols
2728

2829
X, y = load_diabetes(return_X_y=True)
2930

examples/plot_speed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# canonical correlation coefficients may be more than one, the feature ranking
4040
# criterion used here is the sum squared of all canonical correlation coefficients.
4141

42-
from fastcan import ssc
42+
from fastcan.utils import ssc
4343

4444

4545
def baseline(X, y, t):

fastcan/__init__.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
"""
2-
The :mod:`fastcan` module implements algorithms, including
2+
The implementation of fast canonical correlation analysis based feature selection
3+
algorithm.
34
"""
45

6+
from . import narx, utils
57
from ._fastcan import FastCan
68
from ._minibatch import minibatch
7-
from ._narx import (
8-
Narx,
9-
make_narx,
10-
make_poly_features,
11-
make_poly_ids,
12-
make_time_shift_features,
13-
make_time_shift_ids,
14-
print_narx,
15-
)
169
from ._refine import refine
17-
from ._utils import ols, ssc
1810

1911
__all__ = [
2012
"FastCan",
21-
"ssc",
22-
"ols",
2313
"refine",
2414
"minibatch",
25-
"make_narx",
26-
"print_narx",
27-
"Narx",
28-
"make_poly_features",
29-
"make_poly_ids",
30-
"make_time_shift_features",
31-
"make_time_shift_ids",
15+
"narx",
16+
"utils",
3217
]

fastcan/_minibatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Feature selection with mini-batch
2+
Feature selection with mini-batch.
33
"""
44

55
from copy import deepcopy
@@ -29,7 +29,7 @@
2929
prefer_skip_nested_validation=False,
3030
)
3131
def minibatch(X, y, n_features_to_select=1, batch_size=1, verbose=1):
32-
"""FastCan selection with mini batches.
32+
"""Feature selection using :class:`fastcan.FastCan` with mini batches.
3333
3434
It is suitable for selecting a very large number of features
3535
even larger than the number of samples.

fastcan/_refine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
prefer_skip_nested_validation=True,
3232
)
3333
def refine(selector, drop=1, max_iter=None, verbose=1):
34-
"""Two-Stage Refining.
34+
"""Two-stage refining for the results of :class:`fastcan.FastCan`.
3535
3636
In the refining process, the selected features will be dropped, and
3737
the vacancy positions will be refilled from the candidate features.

fastcan/_narx.py renamed to fastcan/narx.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
This file contains Narx model class.
2+
The module related to nonlinear autoregressive exogenous (NARX) model for system
3+
identification.
34
"""
45

56
import math
@@ -47,7 +48,7 @@ def make_time_shift_features(X, ids):
4748
4849
Examples
4950
--------
50-
>>> from fastcan import make_time_shift_features
51+
>>> from fastcan.narx import make_time_shift_features
5152
>>> X = [[1, 2], [3, 4], [5, 6], [7, 8]]
5253
>>> ids = [[0, 0], [0, 1], [1, 1]]
5354
>>> make_time_shift_features(X, ids)
@@ -108,7 +109,7 @@ def make_time_shift_ids(
108109
109110
Examples
110111
--------
111-
>>> from fastcan import make_time_shift_ids
112+
>>> from fastcan.narx import make_time_shift_ids
112113
>>> make_time_shift_ids(2, max_delay=3, include_zero_delay=[True, False])
113114
array([[0, 0],
114115
[0, 1],
@@ -172,7 +173,7 @@ def make_poly_features(X, ids):
172173
173174
Examples
174175
--------
175-
>>> from fastcan import make_poly_features
176+
>>> from fastcan.narx import make_poly_features
176177
>>> X = [[1, 2], [3, 4], [5, 6], [7, 8]]
177178
>>> ids = [[0, 0], [0, 1], [1, 1], [0, 2]]
178179
>>> make_poly_features(X, ids)
@@ -233,7 +234,7 @@ def make_poly_ids(
233234
234235
Examples
235236
--------
236-
>>> from fastcan import make_poly_ids
237+
>>> from fastcan.narx import make_poly_ids
237238
>>> make_poly_ids(2, degree=3)
238239
array([[0, 0, 1],
239240
[0, 0, 2],
@@ -274,7 +275,7 @@ def _mask_missing_value(*arr):
274275

275276

276277
class Narx(RegressorMixin, BaseEstimator):
277-
"""Nonlinear Autoregressive eXogenous model.
278+
"""The Nonlinear Autoregressive eXogenous (NARX) model class.
278279
For example, a (polynomial) Narx model is like
279280
y(t) = y(t-1)*u(t-1) + u(t-1)^2 + u(t-2) + 1.5
280281
where y(t) is the system output at time t,
@@ -332,7 +333,7 @@ class Narx(RegressorMixin, BaseEstimator):
332333
Examples
333334
--------
334335
>>> import numpy as np
335-
>>> from fastcan import Narx, print_narx
336+
>>> from fastcan.narx import Narx, print_narx
336337
>>> rng = np.random.default_rng(12345)
337338
>>> n_samples = 1000
338339
>>> max_delay = 3
@@ -675,7 +676,7 @@ def print_narx(
675676
Examples
676677
--------
677678
>>> from sklearn.datasets import load_diabetes
678-
>>> from fastcan import print_narx, Narx
679+
>>> from fastcan.narx import print_narx, Narx
679680
>>> X, y = load_diabetes(return_X_y=True)
680681
>>> print_narx(Narx().fit(X, y), term_space=10, coef_space=5, float_precision=0)
681682
| Term |Coef |
@@ -816,7 +817,7 @@ def make_narx(
816817
--------
817818
>>> import numpy as np
818819
>>> from sklearn.metrics import mean_squared_error
819-
>>> from fastcan import make_narx, print_narx
820+
>>> from fastcan.narx import make_narx, print_narx
820821
>>> rng = np.random.default_rng(12345)
821822
>>> n_samples = 1000
822823
>>> max_delay = 3

fastcan/_utils.py renamed to fastcan/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Sum squared of correlation."""
1+
"""Utils functions."""
22

33
from numbers import Integral
44

@@ -33,7 +33,7 @@ def ssc(X, y):
3333
3434
Examples
3535
--------
36-
>>> from fastcan import ssc
36+
>>> from fastcan.utils import ssc
3737
>>> X = [[1], [-1], [0]]
3838
>>> y = [[0], [1], [-1]]
3939
>>> ssc(X, y)
@@ -58,7 +58,7 @@ def ssc(X, y):
5858
prefer_skip_nested_validation=True,
5959
)
6060
def ols(X, y, t=1):
61-
"""Orthogonal least-squares
61+
"""Orthogonal least-squares.
6262
6363
Parameters
6464
----------
@@ -83,7 +83,7 @@ def ols(X, y, t=1):
8383
8484
Examples
8585
--------
86-
>>> from fastcan import ols
86+
>>> from fastcan.utils import ols
8787
>>> X = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]]
8888
>>> y = [1, 0, 1, 0]
8989
>>> indices, scores = ols(X, y, 2)

0 commit comments

Comments
 (0)