From 3ed8e5cdcc833f1c38b0751a4d2c7dfebec5c80f Mon Sep 17 00:00:00 2001 From: SIKAI ZHANG <34108862+MatthewSZhang@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:59:29 +0800 Subject: [PATCH] MNT refactor the project structure (#27) * MNT refactor the project structure --- doc/index.rst | 42 +++++---- doc/templates/autosummary/module.rst | 28 ++++++ examples/plot_affinity.py | 3 +- examples/plot_speed.py | 2 +- fastcan/__init__.py | 25 +---- fastcan/_minibatch.py | 4 +- fastcan/_refine.py | 2 +- fastcan/{_narx.py => narx.py} | 19 ++-- fastcan/{_utils.py => utils.py} | 8 +- pixi.lock | 136 +++++++++++++-------------- tests/test_narx.py | 2 +- tests/test_ols.py | 24 ----- tests/{test_ssc.py => test_utils.py} | 18 +++- 13 files changed, 164 insertions(+), 149 deletions(-) create mode 100644 doc/templates/autosummary/module.rst rename fastcan/{_narx.py => narx.py} (98%) rename fastcan/{_utils.py => utils.py} (95%) delete mode 100644 tests/test_ols.py rename tests/{test_ssc.py => test_utils.py} (64%) diff --git a/doc/index.rst b/doc/index.rst index a65056a..071cafd 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -9,33 +9,41 @@ .. include:: ../README.rst -.. currentmodule:: fastcan API Reference ------------- -.. autosummary:: - :toctree: generated/ - - FastCan - refine - minibatch - ssc - ols - make_poly_ids - make_poly_features - make_time_shift_features - make_time_shift_ids - make_narx - print_narx - Narx +.. automodule:: fastcan + + .. rubric:: Classes + + .. autosummary:: + :toctree: generated/ + + FastCan + + .. rubric:: Functions + + .. autosummary:: + :toctree: generated/ + + refine + minibatch + + .. rubric:: Submodules + + .. autosummary:: + :toctree: generated/ + + narx + utils Useful Links ------------ .. toctree:: :maxdepth: 2 - User Guild + User Guide Examples API Compatibility diff --git a/doc/templates/autosummary/module.rst b/doc/templates/autosummary/module.rst new file mode 100644 index 0000000..14ad518 --- /dev/null +++ b/doc/templates/autosummary/module.rst @@ -0,0 +1,28 @@ +{{ objname | escape | underline(line="=") }} + +.. automodule:: {{ fullname }} + + {% block classes %} + {% if classes %} + .. rubric:: {{ _('Classes') }} + + .. autosummary:: + :toctree: + {% for item in classes %} + {{ item }} + {%- endfor %} + {% endif %} + {% endblock %} + + + {% block functions %} + {% if functions %} + .. rubric:: {{ _('Functions') }} + + .. autosummary:: + :toctree: + {% for item in functions %} + {{ item }} + {%- endfor %} + {% endif %} + {% endblock %} diff --git a/examples/plot_affinity.py b/examples/plot_affinity.py index dd22245..d39d46b 100644 --- a/examples/plot_affinity.py +++ b/examples/plot_affinity.py @@ -23,7 +23,8 @@ from sklearn.datasets import load_diabetes from sklearn.linear_model import OrthogonalMatchingPursuit -from fastcan import FastCan, ols +from fastcan import FastCan +from fastcan.utils import ols X, y = load_diabetes(return_X_y=True) diff --git a/examples/plot_speed.py b/examples/plot_speed.py index 1b2a05e..ce933dd 100644 --- a/examples/plot_speed.py +++ b/examples/plot_speed.py @@ -39,7 +39,7 @@ # canonical correlation coefficients may be more than one, the feature ranking # criterion used here is the sum squared of all canonical correlation coefficients. -from fastcan import ssc +from fastcan.utils import ssc def baseline(X, y, t): diff --git a/fastcan/__init__.py b/fastcan/__init__.py index a1d71c1..edd05f7 100644 --- a/fastcan/__init__.py +++ b/fastcan/__init__.py @@ -1,32 +1,17 @@ """ -The :mod:`fastcan` module implements algorithms, including +The implementation of fast canonical correlation analysis based feature selection +algorithm. """ +from . import narx, utils from ._fastcan import FastCan from ._minibatch import minibatch -from ._narx import ( - Narx, - make_narx, - make_poly_features, - make_poly_ids, - make_time_shift_features, - make_time_shift_ids, - print_narx, -) from ._refine import refine -from ._utils import ols, ssc __all__ = [ "FastCan", - "ssc", - "ols", "refine", "minibatch", - "make_narx", - "print_narx", - "Narx", - "make_poly_features", - "make_poly_ids", - "make_time_shift_features", - "make_time_shift_ids", + "narx", + "utils", ] diff --git a/fastcan/_minibatch.py b/fastcan/_minibatch.py index 148dfab..b879687 100644 --- a/fastcan/_minibatch.py +++ b/fastcan/_minibatch.py @@ -1,5 +1,5 @@ """ -Feature selection with mini-batch +Feature selection with mini-batch. """ from copy import deepcopy @@ -29,7 +29,7 @@ prefer_skip_nested_validation=False, ) def minibatch(X, y, n_features_to_select=1, batch_size=1, verbose=1): - """FastCan selection with mini batches. + """Feature selection using :class:`fastcan.FastCan` with mini batches. It is suitable for selecting a very large number of features even larger than the number of samples. diff --git a/fastcan/_refine.py b/fastcan/_refine.py index 0fb2bfd..c0ef85d 100644 --- a/fastcan/_refine.py +++ b/fastcan/_refine.py @@ -31,7 +31,7 @@ prefer_skip_nested_validation=True, ) def refine(selector, drop=1, max_iter=None, verbose=1): - """Two-Stage Refining. + """Two-stage refining for the results of :class:`fastcan.FastCan`. In the refining process, the selected features will be dropped, and the vacancy positions will be refilled from the candidate features. diff --git a/fastcan/_narx.py b/fastcan/narx.py similarity index 98% rename from fastcan/_narx.py rename to fastcan/narx.py index de6f476..879483e 100644 --- a/fastcan/_narx.py +++ b/fastcan/narx.py @@ -1,5 +1,6 @@ """ -This file contains Narx model class. +The module related to nonlinear autoregressive exogenous (NARX) model for system +identification. """ import math @@ -47,7 +48,7 @@ def make_time_shift_features(X, ids): Examples -------- - >>> from fastcan import make_time_shift_features + >>> from fastcan.narx import make_time_shift_features >>> X = [[1, 2], [3, 4], [5, 6], [7, 8]] >>> ids = [[0, 0], [0, 1], [1, 1]] >>> make_time_shift_features(X, ids) @@ -108,7 +109,7 @@ def make_time_shift_ids( Examples -------- - >>> from fastcan import make_time_shift_ids + >>> from fastcan.narx import make_time_shift_ids >>> make_time_shift_ids(2, max_delay=3, include_zero_delay=[True, False]) array([[0, 0], [0, 1], @@ -172,7 +173,7 @@ def make_poly_features(X, ids): Examples -------- - >>> from fastcan import make_poly_features + >>> from fastcan.narx import make_poly_features >>> X = [[1, 2], [3, 4], [5, 6], [7, 8]] >>> ids = [[0, 0], [0, 1], [1, 1], [0, 2]] >>> make_poly_features(X, ids) @@ -233,7 +234,7 @@ def make_poly_ids( Examples -------- - >>> from fastcan import make_poly_ids + >>> from fastcan.narx import make_poly_ids >>> make_poly_ids(2, degree=3) array([[0, 0, 1], [0, 0, 2], @@ -274,7 +275,7 @@ def _mask_missing_value(*arr): class Narx(RegressorMixin, BaseEstimator): - """Nonlinear Autoregressive eXogenous model. + """The Nonlinear Autoregressive eXogenous (NARX) model class. For example, a (polynomial) Narx model is like y(t) = y(t-1)*u(t-1) + u(t-1)^2 + u(t-2) + 1.5 where y(t) is the system output at time t, @@ -332,7 +333,7 @@ class Narx(RegressorMixin, BaseEstimator): Examples -------- >>> import numpy as np - >>> from fastcan import Narx, print_narx + >>> from fastcan.narx import Narx, print_narx >>> rng = np.random.default_rng(12345) >>> n_samples = 1000 >>> max_delay = 3 @@ -675,7 +676,7 @@ def print_narx( Examples -------- >>> from sklearn.datasets import load_diabetes - >>> from fastcan import print_narx, Narx + >>> from fastcan.narx import print_narx, Narx >>> X, y = load_diabetes(return_X_y=True) >>> print_narx(Narx().fit(X, y), term_space=10, coef_space=5, float_precision=0) | Term |Coef | @@ -816,7 +817,7 @@ def make_narx( -------- >>> import numpy as np >>> from sklearn.metrics import mean_squared_error - >>> from fastcan import make_narx, print_narx + >>> from fastcan.narx import make_narx, print_narx >>> rng = np.random.default_rng(12345) >>> n_samples = 1000 >>> max_delay = 3 diff --git a/fastcan/_utils.py b/fastcan/utils.py similarity index 95% rename from fastcan/_utils.py rename to fastcan/utils.py index d477d25..ab9467a 100644 --- a/fastcan/_utils.py +++ b/fastcan/utils.py @@ -1,4 +1,4 @@ -"""Sum squared of correlation.""" +"""Utils functions.""" from numbers import Integral @@ -33,7 +33,7 @@ def ssc(X, y): Examples -------- - >>> from fastcan import ssc + >>> from fastcan.utils import ssc >>> X = [[1], [-1], [0]] >>> y = [[0], [1], [-1]] >>> ssc(X, y) @@ -58,7 +58,7 @@ def ssc(X, y): prefer_skip_nested_validation=True, ) def ols(X, y, t=1): - """Orthogonal least-squares + """Orthogonal least-squares. Parameters ---------- @@ -83,7 +83,7 @@ def ols(X, y, t=1): Examples -------- - >>> from fastcan import ols + >>> from fastcan.utils import ols >>> X = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]] >>> y = [1, 0, 1, 0] >>> indices, scores = ols(X, y, 2) diff --git a/pixi.lock b/pixi.lock index be62b15..51f2613 100644 --- a/pixi.lock +++ b/pixi.lock @@ -66,7 +66,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/python_abi-3.13-5_cp313.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytz-2024.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8228510_1.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.8.2-py313he87ea70_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.8.3-py313he87ea70_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scikit-learn-1.6.0-py313h8ef605b_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.14.1-py313h27c5614_2.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.6.0-pyhff2d567_1.conda @@ -78,7 +78,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/tomli-2.2.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.12.2-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024b-hc8b5060_0.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/uv-0.5.7-h0f3a69f_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/uv-0.5.8-h0f3a69f_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/zipp-3.21.0-pyhd8ed1ab_1.conda - pypi: https://files.pythonhosted.org/packages/7e/b3/6b4067be973ae96ba0d615946e314c5ae35f9f993eca561b356540bb0c2b/alabaster-1.0.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/ed/20/bc79bc575ba2e2a7f70e8a1155618bb1301eaa5132a8271373a6903f73f8/babel-2.16.0-py3-none-any.whl @@ -95,7 +95,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/39/fa/cdc0b6105d90eadc3bee525fecc9179e2b41e1ce0293caaf49cb631a6aaf/kiwisolver-1.4.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - pypi: https://files.pythonhosted.org/packages/0c/91/96cf928db8236f1bfab6ce15ad070dfdd02ed88261c2afafd4b43575e9e9/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - - pypi: https://files.pythonhosted.org/packages/29/09/146a17d37e32313507f11ac984e65311f2d5805d731eb981d4f70eb928dc/matplotlib-3.9.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl + - pypi: https://files.pythonhosted.org/packages/f8/6b/9eb761c00e1cb838f6c92e5f25dcda3f56a87a52f6cb8fdfa561e6cf6a13/matplotlib-3.9.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - pypi: https://files.pythonhosted.org/packages/44/ae/7e4f6662a9b1cb5f92b9cc9cab8321c381ffbee309210940e57432a4063a/pillow-11.0.0-cp313-cp313-manylinux_2_28_x86_64.whl - pypi: https://files.pythonhosted.org/packages/f7/3f/01c8b82017c199075f8f788d0d906b9ffbbc5a47dc9918a945e13d5a2bda/pygments-2.18.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/be/ec/2eb3cd785efd67806c46c13a17339708ddc346cbb684eade7a6e6f79536a/pyparsing-3.2.0-py3-none-any.whl @@ -198,7 +198,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-64/python_abi-3.13-5_cp313.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytz-2024.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/readline-8.2-h9e318b2_1.conda - - conda: https://conda.anaconda.org/conda-forge/osx-64/ruff-0.8.2-py313h2493e73_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-64/ruff-0.8.3-py313h2493e73_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/scikit-learn-1.6.0-py313hedeaec8_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/scipy-1.14.1-py313hd641537_2.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.6.0-pyhff2d567_1.conda @@ -212,7 +212,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/tomli-2.2.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.12.2-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024b-hc8b5060_0.conda - - conda: https://conda.anaconda.org/conda-forge/osx-64/uv-0.5.7-h8de1528_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-64/uv-0.5.8-h8de1528_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/zipp-3.21.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/zlib-1.3.1-hd23fc13_2.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/zstd-1.5.6-h915ae27_0.conda @@ -231,7 +231,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/97/f5/b8a370d1aa593c17882af0a6f6755aaecd643640c0ed72dcfd2eafc388b9/kiwisolver-1.4.7-cp313-cp313-macosx_10_13_x86_64.whl - pypi: https://files.pythonhosted.org/packages/83/0e/67eb10a7ecc77a0c2bbe2b0235765b98d164d81600746914bebada795e97/MarkupSafe-3.0.2-cp313-cp313-macosx_10_13_universal2.whl - - pypi: https://files.pythonhosted.org/packages/60/04/949640040982822416c471d9ebe4e9e6c69ca9f9bb6ba82ed30808863c02/matplotlib-3.9.3-cp313-cp313-macosx_10_13_x86_64.whl + - pypi: https://files.pythonhosted.org/packages/49/b1/999f89a7556d101b23a2f0b54f1b6e140d73f56804da1398f2f0bc0924bc/matplotlib-3.9.4-cp313-cp313-macosx_10_13_x86_64.whl - pypi: https://files.pythonhosted.org/packages/63/24/e2e15e392d00fcf4215907465d8ec2a2f23bcec1481a8ebe4ae760459995/pillow-11.0.0-cp313-cp313-macosx_10_13_x86_64.whl - pypi: https://files.pythonhosted.org/packages/f7/3f/01c8b82017c199075f8f788d0d906b9ffbbc5a47dc9918a945e13d5a2bda/pygments-2.18.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/be/ec/2eb3cd785efd67806c46c13a17339708ddc346cbb684eade7a6e6f79536a/pyparsing-3.2.0-py3-none-any.whl @@ -335,7 +335,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python_abi-3.13-5_cp313.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytz-2024.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/readline-8.2-h92ec313_1.conda - - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.8.2-py313heab95af_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.8.3-py313heab95af_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scikit-learn-1.6.0-py313hecba28c_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.14.1-py313hc010ede_2.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.6.0-pyhff2d567_1.conda @@ -349,7 +349,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/tomli-2.2.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.12.2-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024b-hc8b5060_0.conda - - conda: https://conda.anaconda.org/conda-forge/osx-arm64/uv-0.5.7-h668ec48_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/uv-0.5.8-h668ec48_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/zipp-3.21.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/zlib-1.3.1-h8359307_2.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/zstd-1.5.6-hb46c0d2_0.conda @@ -368,7 +368,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/2a/fc/6c0374f7503522539e2d4d1b497f5ebad3f8ed07ab51aed2af988dd0fb65/kiwisolver-1.4.7-cp313-cp313-macosx_11_0_arm64.whl - pypi: https://files.pythonhosted.org/packages/2b/6d/9409f3684d3335375d04e5f05744dfe7e9f120062c9857df4ab490a1031a/MarkupSafe-3.0.2-cp313-cp313-macosx_11_0_arm64.whl - - pypi: https://files.pythonhosted.org/packages/9f/90/ebd37143cd3150b6c650ee1580024df3dd649d176e68d346f826b8d24e37/matplotlib-3.9.3-cp313-cp313-macosx_11_0_arm64.whl + - pypi: https://files.pythonhosted.org/packages/87/7b/06a32b13a684977653396a1bfcd34d4e7539c5d55c8cbfaa8ae04d47e4a9/matplotlib-3.9.4-cp313-cp313-macosx_11_0_arm64.whl - pypi: https://files.pythonhosted.org/packages/43/72/92ad4afaa2afc233dc44184adff289c2e77e8cd916b3ddb72ac69495bda3/pillow-11.0.0-cp313-cp313-macosx_11_0_arm64.whl - pypi: https://files.pythonhosted.org/packages/f7/3f/01c8b82017c199075f8f788d0d906b9ffbbc5a47dc9918a945e13d5a2bda/pygments-2.18.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/be/ec/2eb3cd785efd67806c46c13a17339708ddc346cbb684eade7a6e6f79536a/pyparsing-3.2.0-py3-none-any.whl @@ -439,7 +439,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/python_abi-3.13-5_cp313.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytz-2024.1-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.8.2-py313h331c231_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.8.3-py313h331c231_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scikit-learn-1.6.0-py313h4f67946_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.14.1-py313h16bbbb2_2.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.6.0-pyhff2d567_1.conda @@ -453,7 +453,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.12.2-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024b-hc8b5060_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/ucrt-10.0.22621.0-h57928b3_1.conda - - conda: https://conda.anaconda.org/conda-forge/win-64/uv-0.5.7-ha08ef0e_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/uv-0.5.8-ha08ef0e_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/vc-14.3-ha32ba9b_23.conda - conda: https://conda.anaconda.org/conda-forge/win-64/vc14_runtime-14.42.34433-he29a5d6_23.conda - conda: https://conda.anaconda.org/conda-forge/win-64/vs2015_runtime-14.42.34433-hdffcdeb_23.conda @@ -473,7 +473,7 @@ environments: - pypi: https://files.pythonhosted.org/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/0b/db/32e897e43a330eee8e4770bfd2737a9584b23e33587a0812b8e20aac38f7/kiwisolver-1.4.7-cp313-cp313-win_amd64.whl - pypi: https://files.pythonhosted.org/packages/29/88/07df22d2dd4df40aba9f3e402e6dc1b8ee86297dddbad4872bd5e7b0094f/MarkupSafe-3.0.2-cp313-cp313-win_amd64.whl - - pypi: https://files.pythonhosted.org/packages/28/dd/0a5176027c1cb94fe75f69f76cb274180c8abf740df6fc0e6a1e4cbaec3f/matplotlib-3.9.3-cp313-cp313-win_amd64.whl + - pypi: https://files.pythonhosted.org/packages/71/1f/c6e1daea55b7bfeb3d84c6cb1abc449f6a02b181e7e2a5e4db34c3afb793/matplotlib-3.9.4-cp313-cp313-win_amd64.whl - pypi: https://files.pythonhosted.org/packages/fb/01/3755ba287dac715e6afdb333cb1f6d69740a7475220b4637b5ce3d78cec2/pillow-11.0.0-cp313-cp313-win_amd64.whl - pypi: https://files.pythonhosted.org/packages/f7/3f/01c8b82017c199075f8f788d0d906b9ffbbc5a47dc9918a945e13d5a2bda/pygments-2.18.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/be/ec/2eb3cd785efd67806c46c13a17339708ddc346cbb684eade7a6e6f79536a/pyparsing-3.2.0-py3-none-any.whl @@ -3055,10 +3055,10 @@ packages: version: 3.0.2 sha256: ba9527cdd4c926ed0760bc301f6728ef34d841f405abf9d4f959c478421e4efd requires_python: '>=3.9' -- pypi: https://files.pythonhosted.org/packages/28/dd/0a5176027c1cb94fe75f69f76cb274180c8abf740df6fc0e6a1e4cbaec3f/matplotlib-3.9.3-cp313-cp313-win_amd64.whl +- pypi: https://files.pythonhosted.org/packages/49/b1/999f89a7556d101b23a2f0b54f1b6e140d73f56804da1398f2f0bc0924bc/matplotlib-3.9.4-cp313-cp313-macosx_10_13_x86_64.whl name: matplotlib - version: 3.9.3 - sha256: 90a85a004fefed9e583597478420bf904bb1a065b0b0ee5b9d8d31b04b0f3f70 + version: 3.9.4 + sha256: 37eeffeeca3c940985b80f5b9a7b95ea35671e0e7405001f249848d2b62351b6 requires_dist: - contourpy>=1.0.1 - cycler>=0.10 @@ -3070,16 +3070,16 @@ packages: - pyparsing>=2.3.1 - python-dateutil>=2.7 - importlib-resources>=3.2.0 ; python_full_version < '3.10' - - meson-python>=0.13.1 ; extra == 'dev' + - meson-python>=0.13.1,<0.17.0 ; extra == 'dev' - numpy>=1.25 ; extra == 'dev' - pybind11>=2.6,!=2.13.3 ; extra == 'dev' - setuptools-scm>=7 ; extra == 'dev' - setuptools>=64 ; extra == 'dev' requires_python: '>=3.9' -- pypi: https://files.pythonhosted.org/packages/29/09/146a17d37e32313507f11ac984e65311f2d5805d731eb981d4f70eb928dc/matplotlib-3.9.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl +- pypi: https://files.pythonhosted.org/packages/71/1f/c6e1daea55b7bfeb3d84c6cb1abc449f6a02b181e7e2a5e4db34c3afb793/matplotlib-3.9.4-cp313-cp313-win_amd64.whl name: matplotlib - version: 3.9.3 - sha256: 6be0ba61f6ff2e6b68e4270fb63b6813c9e7dec3d15fc3a93f47480444fd72f0 + version: 3.9.4 + sha256: 7c0d8ef442ebf56ff5e206f8083d08252ee738e04f3dc88ea882853a05488799 requires_dist: - contourpy>=1.0.1 - cycler>=0.10 @@ -3091,16 +3091,16 @@ packages: - pyparsing>=2.3.1 - python-dateutil>=2.7 - importlib-resources>=3.2.0 ; python_full_version < '3.10' - - meson-python>=0.13.1 ; extra == 'dev' + - meson-python>=0.13.1,<0.17.0 ; extra == 'dev' - numpy>=1.25 ; extra == 'dev' - pybind11>=2.6,!=2.13.3 ; extra == 'dev' - setuptools-scm>=7 ; extra == 'dev' - setuptools>=64 ; extra == 'dev' requires_python: '>=3.9' -- pypi: https://files.pythonhosted.org/packages/60/04/949640040982822416c471d9ebe4e9e6c69ca9f9bb6ba82ed30808863c02/matplotlib-3.9.3-cp313-cp313-macosx_10_13_x86_64.whl +- pypi: https://files.pythonhosted.org/packages/87/7b/06a32b13a684977653396a1bfcd34d4e7539c5d55c8cbfaa8ae04d47e4a9/matplotlib-3.9.4-cp313-cp313-macosx_11_0_arm64.whl name: matplotlib - version: 3.9.3 - sha256: 203d18df84f5288973b2d56de63d4678cc748250026ca9e1ad8f8a0fd8a75d83 + version: 3.9.4 + sha256: 3e7465ac859ee4abcb0d836137cd8414e7bb7ad330d905abced457217d4f0f45 requires_dist: - contourpy>=1.0.1 - cycler>=0.10 @@ -3112,16 +3112,16 @@ packages: - pyparsing>=2.3.1 - python-dateutil>=2.7 - importlib-resources>=3.2.0 ; python_full_version < '3.10' - - meson-python>=0.13.1 ; extra == 'dev' + - meson-python>=0.13.1,<0.17.0 ; extra == 'dev' - numpy>=1.25 ; extra == 'dev' - pybind11>=2.6,!=2.13.3 ; extra == 'dev' - setuptools-scm>=7 ; extra == 'dev' - setuptools>=64 ; extra == 'dev' requires_python: '>=3.9' -- pypi: https://files.pythonhosted.org/packages/9f/90/ebd37143cd3150b6c650ee1580024df3dd649d176e68d346f826b8d24e37/matplotlib-3.9.3-cp313-cp313-macosx_11_0_arm64.whl +- pypi: https://files.pythonhosted.org/packages/f8/6b/9eb761c00e1cb838f6c92e5f25dcda3f56a87a52f6cb8fdfa561e6cf6a13/matplotlib-3.9.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl name: matplotlib - version: 3.9.3 - sha256: b651b0d3642991259109dc0351fc33ad44c624801367bb8307be9bfc35e427ad + version: 3.9.4 + sha256: 2b8c97917f21b75e72108b97707ba3d48f171541a74aa2a56df7a40626bafc64 requires_dist: - contourpy>=1.0.1 - cycler>=0.10 @@ -3133,7 +3133,7 @@ packages: - pyparsing>=2.3.1 - python-dateutil>=2.7 - importlib-resources>=3.2.0 ; python_full_version < '3.10' - - meson-python>=0.13.1 ; extra == 'dev' + - meson-python>=0.13.1,<0.17.0 ; extra == 'dev' - numpy>=1.25 ; extra == 'dev' - pybind11>=2.6,!=2.13.3 ; extra == 'dev' - setuptools-scm>=7 ; extra == 'dev' @@ -4189,9 +4189,9 @@ packages: - pysocks>=1.5.6,!=1.5.7 ; extra == 'socks' - chardet>=3.0.2,<6 ; extra == 'use-chardet-on-py3' requires_python: '>=3.8' -- conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.8.2-py313he87ea70_0.conda - sha256: 484fc8900a9559f8c02239c1b41664e08d18405ac94fcc213a3799645cf9965f - md5: 3b06e4a10799c25742b109d29d0af0c8 +- conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.8.3-py313he87ea70_0.conda + sha256: 5d4a53cca998fd1d5bb8f3a9487ad60ffdef8a56e04df570a6e785f9edefbaef + md5: f140fdf48951ad6bed3181b64deb34c9 depends: - __glibc >=2.17,<3.0.a0 - libgcc >=13 @@ -4206,11 +4206,11 @@ packages: license_family: MIT purls: - pkg:pypi/ruff?source=hash-mapping - size: 7899611 - timestamp: 1733517003087 -- conda: https://conda.anaconda.org/conda-forge/osx-64/ruff-0.8.2-py313h2493e73_0.conda - sha256: 6cdf2923d25a77d0b2da756c339c481247de8628f9d597a6d4008f73669be3c3 - md5: fd6ba65f9bcc977d70f37c56f7a09d55 + size: 7930518 + timestamp: 1734067017246 +- conda: https://conda.anaconda.org/conda-forge/osx-64/ruff-0.8.3-py313h2493e73_0.conda + sha256: 0d834f7f1f429f082e6b92f157f25998c44b614f14d1dff3cbb2a9acd6c80e2e + md5: 0a9c47ed1504bd6bfa58767a60ee4274 depends: - __osx >=10.13 - libcxx >=18 @@ -4224,11 +4224,11 @@ packages: license_family: MIT purls: - pkg:pypi/ruff?source=hash-mapping - size: 7280382 - timestamp: 1733517681139 -- conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.8.2-py313heab95af_0.conda - sha256: 2fd61f1481cb34676af8ded589d477cc1e8b5b4e5b76045eaefeb16a79485abd - md5: 6fa4b53e24297e7b51c2ac3f60fe34e3 + size: 7312468 + timestamp: 1734067136474 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.8.3-py313heab95af_0.conda + sha256: 608e66e0f0960ac591af5e0b984dbb6ea91eb2718c83d5c160056235fbcd382f + md5: bdb571b33037a1e844df890b0dbcc025 depends: - __osx >=11.0 - libcxx >=18 @@ -4243,11 +4243,11 @@ packages: license_family: MIT purls: - pkg:pypi/ruff?source=hash-mapping - size: 6970556 - timestamp: 1733517514792 -- conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.8.2-py313h331c231_0.conda - sha256: 031f5ad07e28d24c8160aaa981427928b319a87b6093b712210f4e6e0abc6d99 - md5: 370c1bd7b8655aa00f4f54aac884587b + size: 6970719 + timestamp: 1734067761445 +- conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.8.3-py313h331c231_0.conda + sha256: af0833996c191e8ce33efb52491d845cf9c4537a8fa787fd67b2b44ff9fa3f41 + md5: 410e3e4201bc0de6b0f9de9b63e4759e depends: - python >=3.13,<3.14.0a0 - python_abi 3.13.* *_cp313 @@ -4260,8 +4260,8 @@ packages: license_family: MIT purls: - pkg:pypi/ruff?source=hash-mapping - size: 6917688 - timestamp: 1733518073532 + size: 6918580 + timestamp: 1734067315832 - conda: https://conda.anaconda.org/conda-forge/linux-64/scikit-learn-1.6.0-py313h8ef605b_0.conda sha256: 8c56beae5f7561617515b230c3f27b3afa4a6de41c4acc5b83b96c12d98cbe81 md5: 0aa8e3b9e1818cc2e976f74959c8cdb9 @@ -4853,9 +4853,9 @@ packages: - pysocks>=1.5.6,!=1.5.7,<2.0 ; extra == 'socks' - zstandard>=0.18.0 ; extra == 'zstd' requires_python: '>=3.8' -- conda: https://conda.anaconda.org/conda-forge/linux-64/uv-0.5.7-h0f3a69f_0.conda - sha256: 9f75b060a6081e4a7c95211e139488a829aea2df507e52c314e8d9cc7169ad75 - md5: 1411085fd9e2d6fc429d1c7044bfed6c +- conda: https://conda.anaconda.org/conda-forge/linux-64/uv-0.5.8-h0f3a69f_0.conda + sha256: f2e19c099bc628c52c786c0767c6ccfadea038abca7eb64c59dfcf8b779dc23b + md5: 405602a1df0c0667d13a7d35a9869e82 depends: - __glibc >=2.17,<3.0.a0 - libgcc >=13 @@ -4866,11 +4866,11 @@ packages: platform: linux license: Apache-2.0 OR MIT purls: [] - size: 10456289 - timestamp: 1733564626803 -- conda: https://conda.anaconda.org/conda-forge/osx-64/uv-0.5.7-h8de1528_0.conda - sha256: e18580ed3ead682ad9fa222fdcc783f8e7b674a150847918629a53c0488452dd - md5: 1b279a598973f457e236bc9794c7be65 + size: 10382046 + timestamp: 1734058403253 +- conda: https://conda.anaconda.org/conda-forge/osx-64/uv-0.5.8-h8de1528_0.conda + sha256: b98d45dd669ae4cb2079d818d8b7bc2b56d9f9b1f5fd76e061e025ff85286bef + md5: 2451b9242ff261bc90df16e314f6b76e depends: - __osx >=10.13 - libcxx >=18 @@ -4880,11 +4880,11 @@ packages: platform: osx license: Apache-2.0 OR MIT purls: [] - size: 10030090 - timestamp: 1733565224201 -- conda: https://conda.anaconda.org/conda-forge/osx-arm64/uv-0.5.7-h668ec48_0.conda - sha256: aafe001c4a9492b3e31fa78e22494f357020b09ba9aeaa47eb67dea3cdb9d63f - md5: edfec72e28ade5a096c004ea4c6b13d2 + size: 10011460 + timestamp: 1734058877410 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/uv-0.5.8-h668ec48_0.conda + sha256: 10d0e82c4e802c513aacda2dac57786aff3f3b45bd3c6339c4433820f3f779b4 + md5: 9dd358a8ac3163b892b6866a46b0e99a depends: - __osx >=11.0 - libcxx >=18 @@ -4894,11 +4894,11 @@ packages: platform: osx license: Apache-2.0 OR MIT purls: [] - size: 10132765 - timestamp: 1733565399703 -- conda: https://conda.anaconda.org/conda-forge/win-64/uv-0.5.7-ha08ef0e_0.conda - sha256: 03abb45e1eee34c8b13446275a8a9af86d2263591ef38b367ce7a323929850d5 - md5: 810b9171c6ab6c53d138110c026689ef + size: 10186932 + timestamp: 1734058504082 +- conda: https://conda.anaconda.org/conda-forge/win-64/uv-0.5.8-ha08ef0e_0.conda + sha256: 0367208ab34b3eac8f08062f43bc57d1308c6f55f915bdb21185f2d30053c443 + md5: 2cf91bdb0b7af82c1f36721dfce0ec89 depends: - ucrt >=10.0.20348.0 - vc >=14.2,<15 @@ -4907,8 +4907,8 @@ packages: platform: win license: Apache-2.0 OR MIT purls: [] - size: 11401446 - timestamp: 1733565623191 + size: 11470506 + timestamp: 1734058988821 - conda: https://conda.anaconda.org/conda-forge/win-64/vc-14.3-ha32ba9b_23.conda sha256: 986ddaf8feec2904eac9535a7ddb7acda1a1dfb9482088fdb8129f1595181663 md5: 7c10ec3158d1eb4ddff7007c9101adb0 diff --git a/tests/test_narx.py b/tests/test_narx.py index 4c8e062..f632cbf 100644 --- a/tests/test_narx.py +++ b/tests/test_narx.py @@ -5,7 +5,7 @@ from numpy.testing import assert_array_equal from sklearn.utils.estimator_checks import check_estimator -from fastcan import Narx, make_narx, make_poly_ids, make_time_shift_ids, print_narx +from fastcan.narx import Narx, make_narx, make_poly_ids, make_time_shift_ids, print_narx def test_narx_is_sklearn_estimator(): diff --git a/tests/test_ols.py b/tests/test_ols.py deleted file mode 100644 index 544776a..0000000 --- a/tests/test_ols.py +++ /dev/null @@ -1,24 +0,0 @@ -"Test ols" - -import numpy as np -from numpy.testing import assert_almost_equal -from sklearn.linear_model import LinearRegression - -from fastcan import ols - - -def test_sum_errs(): - """Test multiple correlation.""" - rng = np.random.default_rng(12345) - X = rng.random((100, 10)) - y = rng.random(100) - - indices, scores = ols(X, y, 5) - - y_hat = LinearRegression(fit_intercept=False)\ - .fit(X[:, indices], y)\ - .predict(X[:, indices]) - e = y-y_hat - # Sum of Error Reduction Ratio - serrs = 1 - np.dot(e, e)/np.dot(y, y) - assert_almost_equal(actual=scores.sum(), desired=serrs) diff --git a/tests/test_ssc.py b/tests/test_utils.py similarity index 64% rename from tests/test_ssc.py rename to tests/test_utils.py index 7e6160e..ea6fe7c 100644 --- a/tests/test_ssc.py +++ b/tests/test_utils.py @@ -4,9 +4,25 @@ from numpy.testing import assert_almost_equal from sklearn.linear_model import LinearRegression -from fastcan import ssc +from fastcan.utils import ols, ssc +def test_sum_errs(): + """Test multiple correlation.""" + rng = np.random.default_rng(12345) + X = rng.random((100, 10)) + y = rng.random(100) + + indices, scores = ols(X, y, 5) + + y_hat = LinearRegression(fit_intercept=False)\ + .fit(X[:, indices], y)\ + .predict(X[:, indices]) + e = y-y_hat + # Sum of Error Reduction Ratio + serrs = 1 - np.dot(e, e)/np.dot(y, y) + assert_almost_equal(actual=scores.sum(), desired=serrs) + def test_pearson_r(): """Test Pearson's correlation.""" rng = np.random.default_rng(12345)