Skip to content

Commit

Permalink
Migrate to v1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
earthai-tech committed Nov 20, 2024
1 parent 92ae91e commit 2b9c035
Show file tree
Hide file tree
Showing 15 changed files with 1,796 additions and 110 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from hwm.estimators import HammersteinWienerClassifier
from hwm.estimators import HWClassifier
from hwm.metrics import prediction_stability_score

# Generate synthetic data
X, y = make_classification(n_samples=10000, n_features=20)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# Initialize the model
hw_model = HammersteinWienerClassifier(
hw_model = HWClassifier(
nonlinear_input_estimator=StandardScaler(),
nonlinear_output_estimator=StandardScaler(),
p=2,
Expand Down
26 changes: 13 additions & 13 deletions doc/source/estimators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ for fine-tuning the model's behavior during training. These include:
Hammerstein-Wiener Classifier
===============================

The `HammersteinWienerClassifier` is a dynamic system model for
The `HammersteinWienerClassifier`( :class:`hwm.estimators.HWClassifier` ) is a dynamic system model for
classification tasks. It utilizes the Hammerstein-Wiener model
structure, which is composed of a nonlinear input block, a linear
dynamic block, and a nonlinear output block. This allows it to capture
Expand Down Expand Up @@ -225,7 +225,7 @@ and a system dynamics dataset.
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from hwm.estimators import HammersteinWienerClassifier
from hwm.estimators import HWClassifier
# Generate synthetic data
X, y = make_classification(n_samples=1000, n_features=20,
Expand All @@ -235,7 +235,7 @@ and a system dynamics dataset.
)
# Initialize classifier with nonlinear transformations
hw_classifier = HammersteinWienerClassifier(
hw_classifier = HWClassifier(
nonlinear_input_estimator=StandardScaler(),
nonlinear_output_estimator=StandardScaler(),
p=2,
Expand Down Expand Up @@ -277,7 +277,7 @@ performance using `twa_score` and `prediction_stability_score`.
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from hwm.estimators import HammersteinWienerClassifier
from hwm.estimators import HWClassifier
from hwm.datasets import make_system_dynamics
from hwm.metrics import twa_score, prediction_stability_score
Expand All @@ -303,7 +303,7 @@ performance using `twa_score` and `prediction_stability_score`.
)
# Initialize classifier
hw_classifier = HammersteinWienerClassifier(
hw_classifier = HWClassifier(
p=3,
nonlinear_input_estimator=StandardScaler(),
nonlinear_output_estimator=StandardScaler(),
Expand Down Expand Up @@ -378,7 +378,7 @@ performance using `twa_score` and `prediction_stability_score`.
Hammerstein-Wiener Regressor
==============================

The :class:`~hwm.estimators.dynamic_system.HammersteinWienerRegressor` class implements a nonlinear regression
The :class:`~hwm.estimators.dynamic_system.HWRegressor` class implements a nonlinear regression
model based on the Hammerstein-Wiener (HW) architecture. This block-structured model combines a nonlinear
input transformation, a linear dynamic system block, and a nonlinear output transformation, making it highly
suitable for regression tasks where data exhibit complex, time-dependent relationships. The HW model is
Expand Down Expand Up @@ -443,19 +443,19 @@ Attributes
Example Usage
---------------

Below are example applications of `HammersteinWienerRegressor`,
Below are example applications of :class:`hwm.estimators.HWRegressor`,
demonstrating initialization, training, and evaluation on synthetic data.
The first example shows time-series data, while the second highlights
financial trend forecasting.

**Example 1: Basic Time-Series Regression**

This example demonstrates using `HammersteinWienerRegressor` to train
This example demonstrates using `HWRegressor` to train
and predict on synthetic time-series data.

.. code-block:: python
from hwm.estimators import HammersteinWienerRegressor
from hwm.estimators import HWRegressor
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
Expand Down Expand Up @@ -498,12 +498,12 @@ and predict on synthetic time-series data.
**Example 2: Financial Market Trend Forecasting**

This example demonstrates using `HammersteinWienerRegressor` on synthetic financial
This example demonstrates using `HWRegressor` on synthetic financial
trend data, emphasizing the model’s adaptability to financial forecasting tasks.

.. code-block:: python
from hwm.estimators import HammersteinWienerRegressor
from hwm.estimators import HWRegressor
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from hwm.datasets import make_financial_market_trends
Expand All @@ -530,7 +530,7 @@ trend data, emphasizing the model’s adaptability to financial forecasting task
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize Hammerstein-Wiener Regressor
hw_regressor = HammersteinWienerRegressor(
hw_regressor = HWRegressor(
p=3,
nonlinear_input_estimator=StandardScaler(),
nonlinear_output_estimator=StandardScaler(),
Expand Down Expand Up @@ -580,7 +580,7 @@ trend data, emphasizing the model’s adaptability to financial forecasting task

.. seealso::

- :class:`~hwm.estimators.HammersteinWienerClassifier`
- :class:`~hwm.estimators.HWClassifier`
- :class:`~sklearn.linear_model.SGDRegressor`


Expand Down
69 changes: 60 additions & 9 deletions doc/source/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.. _release_notes:

Release Notes
=============
===============

hwm v1.1.0
----------
hwm v1.1.4
------------

**Released on 2024-04-27**

Expand Down Expand Up @@ -51,26 +51,77 @@ hwm v1.1.0
.. code-block:: python
import numpy as np
from hwm.estimators import HammersteinWienerRegressor
from hwm.estimators import HWRegressor
# Generate large synthetic dataset
X = np.random.rand(1000000, 10)
y = np.random.rand(1000000)
# Initialize and fit the regressor with batch computation
model = HammersteinWienerRegressor(batch_size=10000)
model = HWRegressor(batch_size=10000)
model.fit(X, y)
# Make predictions
predictions = model.predict(X)
print(predictions[:5])
# Output: [0.523, 0.489, 0.501, 0.478, 0.495]
**Enhancements**

- *Renamed Classes for Improved Usability*

The class names :class:`hwm.estimators.HammersteinWienerRegressor` and
:class:`hwm.estimators.HammersteinWienerClassifier` have been renamed to
:class:`hwm.estimators.HWRegressor` and :class:`hwm.estimators.HWClassifier`
respectively for brevity and ease of use.

**Deprecation Notice:**

- The old class names `HammersteinWienerRegressor` and
`HammersteinWienerClassifier` are now deprecated and will
be removed in version **1.1.3**. Users are encouraged to
transition to the new class names to ensure future compatibility.

*Example:*

.. code-block:: python
from hwm.estimators import HWRegressor, HWClassifier
# Initialize the regressor
regressor = HWRegressor(batch_size=10000)
regressor.fit(X_train, y_train)
predictions = regressor.predict(X_test)
# Initialize the classifier
classifier = HWClassifier(batch_size=10000)
classifier.fit(X_train, y_train)
class_predictions = classifier.predict(X_test)
class_probabilities = classifier.predict_proba(X_test)
**Using Deprecated Class Names:**

.. code-block:: python
import warnings
from hwm.estimators import HammersteinWienerRegressor
# To display deprecation warnings
warnings.simplefilter('default', DeprecationWarning)
# Initialize the deprecated regressor
regressor = HammersteinWienerRegressor(batch_size=5000)
# Output: DeprecationWarning: HammersteinWienerRegressor is deprecated
# and will be removed in version 1.2. Use HWRegressor instead.
**Bug Fixes**

- **Resolved Memory Errors in :class:`hwm.estimators.HammersteinWienerRegressor`**
- **Resolved Memory Errors in :class:`hwm.estimators.HWRegressor` **
Addressed memory consumption issues in the `HammersteinWienerRegressor` when processing
Addressed memory consumption issues in the `HWRegressor` when processing
large datasets by introducing batch processing mechanisms. This fix ensures stable and
efficient model training and prediction without exhausting system memory.

Expand All @@ -83,8 +134,8 @@ hwm v1.1.0

**Upgrade Notes**

- Users upgrading from version 1.0.1 to 1.1.0 should ensure that their workflows
accommodate the new batch processing parameters in :class:`hwm.estimators.HammersteinWienerRegressor`.
- Users upgrading from version 1.0.1 to 1.1.4 should ensure that their workflows
accommodate the new batch processing parameters in :class:`hwm.estimators.HWRegressor`.
- The :func:`hwm.metrics.twa_score` function now accepts both label arrays and
probability arrays. Ensure that the input
format aligns with the desired usage.
Expand Down
6 changes: 3 additions & 3 deletions examples/kdd_cup_1999.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from tensorflow.keras.layers import Dense, LSTM
from tensorflow.keras.models import Sequential

from hwm.estimators import HammersteinWienerClassifier
from hwm.estimators import HWClassifier
from hwm.metrics import prediction_stability_score, twa_score
from hwm.utils import resample_data

Expand Down Expand Up @@ -145,7 +145,7 @@ def transform(self, X):

# %%
# Initialize the Hammerstein-Wiener Classifier
hw_model = HammersteinWienerClassifier(
hw_model = HWClassifier(
nonlinear_input_estimator=ReLUTransformer(),
nonlinear_output_estimator=ReLUTransformer(),
p=9,
Expand Down Expand Up @@ -176,7 +176,7 @@ def transform(self, X):
}

# Initialize the Hammerstein-Wiener Classifier with fixed components
fixed_hw_model = HammersteinWienerClassifier(
fixed_hw_model = HWClassifier(
nonlinear_input_estimator=ReLUTransformer(),
nonlinear_output_estimator=ReLUTransformer(),
loss="cross_entropy",
Expand Down
3 changes: 2 additions & 1 deletion hwm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _lazy_loader():
try:
from ._version import version as __version__
except ImportError:
__version__ = "1.1.0"
__version__ = "1.1.4"

# Dependency management
_required_dependencies = [
Expand Down Expand Up @@ -66,6 +66,7 @@ def _lazy_loader():

# Suppression of non-critical warnings, adjustable by the user
_warnings_state = {"FutureWarning": "ignore"}

def suppress_warnings(suppress=True):
"""Enable or disable future/syntax warnings."""
for warning, action in _warnings_state.items():
Expand Down
Loading

0 comments on commit 2b9c035

Please sign in to comment.