diff --git a/.github/workflows/run-test-coverage.yml b/.github/workflows/run-test-coverage.yml index 91b3b9e..5dd10ec 100644 --- a/.github/workflows/run-test-coverage.yml +++ b/.github/workflows/run-test-coverage.yml @@ -16,10 +16,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up Python 3.8 + - name: Set up Python 3.11 uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: '3.11' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 929f011..d4bac54 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -13,13 +13,8 @@ jobs: build: strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: ['3.8', '3.9', '3.10', '3.11'] os: [ubuntu-latest, windows-latest, macos-latest] - exclude: - - os: windows-latest - python-version: 3.9 - - os: ubuntu-latest - python-version: 3.6 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index 959e9b5..801db12 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ docs_build/ docs/html/ docs/doctrees/ adapt/datasets.py -datasets/ \ No newline at end of file +datasets/ +debug.ipynb \ No newline at end of file diff --git a/README.md b/README.md index 133c0f6..baac5bc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ADAPT [![PyPI version](https://badge.fury.io/py/adapt.svg)](https://pypi.org/project/adapt) -[![Build Status](https://github.com/adapt-python/adapt/workflows/build/badge.svg)](https://github.com/adapt-python/adapt/actions) +[![Build Status](https://github.com/adapt-python/adapt/actions/workflows/run-test.yml/badge.svg)](https://github.com/adapt-python/adapt/actions) [![Python Version](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8|%203.9-blue)](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8|%203.9-blue) [![Codecov Status](https://codecov.io/gh/adapt-python/adapt/branch/master/graph/badge.svg?token=IWQXMYGY2Q)](https://codecov.io/gh/adapt-python/adapt) @@ -72,11 +72,12 @@ The following dependencies are required and will be installed with the library: - `tensorflow` (>= 2.0) - `scikit-learn` - `cvxopt` +- `scikeras` If for some reason, these packages failed to install, you can do it manually with: ``` -pip install numpy scipy tensorflow scikit-learn cvxopt +pip install numpy scipy tensorflow scikit-learn cvxopt scikeras ``` Finally import the module in your python scripts with: @@ -87,6 +88,15 @@ import adapt A simple example of usage is given in the [Quick-Start](#Quick-Start) below. +### Stable environments [Updated Dec 2023] + +ADAPT sometimes encounters incompatibility issue after a new Tensorflow release. In this case, you can use the following environment, which has passed all tests. ADAPT should work well on it: +- OS: `ubuntu-22.04, windows-2022, macos-12` +- Python versions: `3.8 to 3.11` + +``` +pip install numpy==1.26.2 scipy==1.11.4 tensorflow==2.15.0 scikit-learn==1.3.2 cvxopt==1.3.2 scikeras==0.12.0 +``` ## ADAPT Guideline diff --git a/adapt/base.py b/adapt/base.py index cfe2e8b..e953955 100644 --- a/adapt/base.py +++ b/adapt/base.py @@ -13,7 +13,10 @@ from sklearn.metrics.pairwise import KERNEL_PARAMS from sklearn.exceptions import NotFittedError from tensorflow.keras import Model -from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor +try: + from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor +except: + from scikeras.wrappers import KerasClassifier, KerasRegressor try: from tensorflow.keras.optimizers.legacy import RMSprop except: @@ -1623,7 +1626,7 @@ def _get_length_dataset(self, dataset, domain="src"): def _check_for_batch(self, dataset): - if dataset.__class__.__name__ == "BatchDataset": + if "BatchDataset" in dataset.__class__.__name__: return True if hasattr(dataset, "_input_dataset"): return self._check_for_batch(dataset._input_dataset) diff --git a/adapt/instance_based/_iwc.py b/adapt/instance_based/_iwc.py index 55af9ac..6278d77 100644 --- a/adapt/instance_based/_iwc.py +++ b/adapt/instance_based/_iwc.py @@ -170,7 +170,7 @@ def fit_weights(self, Xs, Xt, warm_start=False, **kwargs): else: y_pred = self.classifier_.predict(Xs).ravel() - self.weights_ = 1. / (y_pred + EPS) - 1. + self.weights_ = 1. / np.clip(y_pred, EPS, 1.) - 1. return self.weights_ diff --git a/adapt/instance_based/_tradaboost.py b/adapt/instance_based/_tradaboost.py index 5b3f10b..4a869f2 100644 --- a/adapt/instance_based/_tradaboost.py +++ b/adapt/instance_based/_tradaboost.py @@ -218,7 +218,7 @@ def fit(self, X, y, Xt=None, yt=None, self : returns an instance of self """ set_random_seed(self.random_state) - tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) + # tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) Xs, ys = check_arrays(X, y, accept_sparse=True) Xt, yt = self._get_target_data(Xt, yt) @@ -757,9 +757,9 @@ class TwoStageTrAdaBoostR2(TrAdaBoostR2): -------- >>> from sklearn.linear_model import Ridge >>> from adapt.utils import make_regression_da - >>> from adapt.instance_based import TrAdaBoostR2 + >>> from adapt.instance_based import TwoStageTrAdaBoostR2 >>> Xs, ys, Xt, yt = make_regression_da() - >>> model = TrAdaBoostR2(Ridge(), n_estimators=10, Xt=Xt[:10], yt=yt[:10], random_state=0) + >>> model = TwoStageTrAdaBoostR2(Ridge(), n_estimators=10, Xt=Xt[:10], yt=yt[:10], random_state=0) >>> model.fit(Xs, ys) Iteration 0 - Cross-validation score: 0.2956 (0.0905) Iteration 1 - Cross-validation score: 0.2956 (0.0905) @@ -814,7 +814,7 @@ def fit(self, X, y, Xt=None, yt=None, sample_weight_tgt=None, **fit_params): set_random_seed(self.random_state) - tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) + # tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) Xs, ys = check_arrays(X, y, accept_sparse=True) Xt, yt = self._get_target_data(Xt, yt) diff --git a/adapt/utils.py b/adapt/utils.py index 1e7f7ed..c6f37a1 100644 --- a/adapt/utils.py +++ b/adapt/utils.py @@ -11,7 +11,10 @@ from sklearn.utils import check_array from sklearn.linear_model import LinearRegression, LogisticRegression from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin, clone -from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor +try: + from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor +except: + from scikeras.wrappers import KerasClassifier, KerasRegressor import tensorflow as tf import tensorflow.keras.backend as K from tensorflow.keras import Sequential, Model diff --git a/requirements.txt b/requirements.txt index 79f1b5b..d788280 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ numpy scipy -tensorflow < 2.12 +tensorflow scikit-learn -cvxopt <= 1.3.0 +cvxopt +scikeras diff --git a/setup.py b/setup.py index 5b96692..8989d59 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ author_email='antoine.demat@gmail.com', license='BSD-2', packages=find_packages(exclude=["tests"]), - install_requires=["numpy>=1.16", "scipy>=1.0", "tensorflow<2.12", "scikit-learn>=0.2", "cvxopt<=1.3.0"], + install_requires=["numpy", "scipy", "tensorflow", "scikit-learn", "cvxopt", "scikeras"], zip_safe=False, long_description=long_description, long_description_content_type='text/markdown' diff --git a/src_docs/_templates/class.rst b/src_docs/_templates/class.rst index d70f3ea..47e923c 100644 --- a/src_docs/_templates/class.rst +++ b/src_docs/_templates/class.rst @@ -21,28 +21,35 @@ 'add_weight', 'apply', 'build', + 'build_from_config', 'call', + 'compile_from_config', 'compute_mask', 'compute_output_shape', 'compute_output_signature', 'count_params', 'evaluate', 'evaluate_generator', + 'export', 'finalize_state', 'fit_generator', 'from_config', + 'get_build_config', + 'get_compile_config', 'get_config', 'get_input_at', 'get_input_mask_at', 'get_input_shape_at', 'get_layer', 'get_losses_for', + 'get_metrics_result', 'get_output_at', 'get_output_mask_at', 'get_output_shape_at', 'get_updates_for', 'get_weights', - 'load_weights', + 'get_weight_paths', + 'load_own_variables', 'make_predict_function', 'make_test_function', 'make_train_function', @@ -53,7 +60,7 @@ 'reset_states', 'save', 'save_spec', - 'save_weights', + 'save_own_variables', 'set_weights', 'summary', 'test_on_batch',