diff --git a/pyproject.toml b/pyproject.toml index a40a727..aed2303 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "growthcurves" # See the section below: [tools.setuptools.dynamic] dynamic = [ "version", # version is loaded from the package - "dependencies", # add if using requirements.txt + # "dependencies", # add if using requirements.txt ] readme = "README.md" requires-python = ">=3.9" # test all higher Python versions @@ -19,12 +19,14 @@ classifiers = [ # Also update LICENSE file if you pick another one license = "GPL-3.0-or-later" # https://choosealicense.com/licenses/gpl-3.0/ # # add dependencies here: (use one of the two) -# dependencies = ["numpy", "pandas", "scipy", "matplotlib", "seaborn"] +dependencies = [ + "numpy", "scipy", "plotly", "scikit-learn", +] # use requirements.txt instead of pyproject.toml for dependencies # https://stackoverflow.com/a/73600610/9684872 # ! uncomment also dependencies in the dynamic section above -[tool.setuptools.dynamic] -dependencies = {file = ["requirements.txt"]} +# [tool.setuptools.dynamic] +# dependencies = {file = ["requirements.txt"]} [project.urls] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8296a3f..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -numpy>=1.20.0 -scipy>=1.7.0 -plotly>=5.0.0 diff --git a/src/growthcurves/non_parametric.py b/src/growthcurves/non_parametric.py index f7bae0e..79cf24e 100644 --- a/src/growthcurves/non_parametric.py +++ b/src/growthcurves/non_parametric.py @@ -9,11 +9,14 @@ from logging import getLogger import numpy as np +import sklearn.linear_model from scipy.interpolate import make_smoothing_spline -from scipy.stats import theilslopes from .inference import bad_fit_stats +# from scipy.stats import theilslopes + + logger = getLogger(__name__) # Default settings for the auto-spline (sigma-based smoothing + OD weights). @@ -79,7 +82,7 @@ def fit_sliding_window(t, N, window_points=15, step=None, n_fits=None, **kwargs) step = 1 else: step = max(1, int(len(t) / n_fits)) - + huber_regressor = sklearn.linear_model.HuberRegressor() # limit number of fits to avoid excessive computation using step parameter for i in range(0, len(t) - w + 1, step): t_win = t[i : i + w] @@ -88,9 +91,13 @@ def fit_sliding_window(t, N, window_points=15, step=None, n_fits=None, **kwargs) if np.ptp(t_win) <= 0: continue - # Use Theil-Sen estimator for robust line fitting - result = theilslopes(y_log_win, t_win) - slope, intercept = result.slope, result.intercept + # # Use Theil-Sen estimator for robust line fitting + # result = theilslopes(y_log_win, t_win) + # slope, intercept = result.slope, result.intercept + # # Use HuberRegressor which uses L2 regularization and is twice as fast as + # # Theil-Sen. + result = huber_regressor.fit(t_win.reshape(-1, 1), y_log_win) + slope, intercept = result.coef_[0], result.intercept_ if slope > best_slope: best_slope = slope