Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/gfdl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class GFDLClassifier(ClassifierMixin, GFDL):

Parameters
----------
hidden_layer_sizes : array-like of shape(n_layers,), default=(100,)
hidden_layer_sizes : array-like of shape (n_layers,), default=(100,)
The ith element represents the number of neurons in the ith
hidden layer.

Expand Down Expand Up @@ -169,7 +169,8 @@ class GFDLClassifier(ClassifierMixin, GFDL):

- 'zeros': set weights to zeros (:func:`zeros <gfdl.weights.zeros>`).

- 'range': discrete uniform distribution (:func:`range <gfdl.weights.range>`).
- 'range': set weights to normalized np.arange
(:func:`range <gfdl.weights.range>`).

- 'uniform': uniform distribution (:func:`uniform <gfdl.weights.uniform>`).

Expand Down Expand Up @@ -232,7 +233,7 @@ class GFDLClassifier(ClassifierMixin, GFDL):
bias term corresponding to layer i.

coeff_ : ndarray of shape (n_features_out, n_outputs)
Output weight matrix learned by linear regression.
Output weight matrix learned by fit method.

See Also
--------
Expand Down Expand Up @@ -480,7 +481,8 @@ class EnsembleGFDLClassifier(ClassifierMixin, EnsembleGFDL):

- 'zeros': set weights to zeros (:func:`zeros <gfdl.weights.zeros>`).

- 'range': discrete uniform distribution (:func:`range <gfdl.weights.range>`).
- 'range': set weights to normalized np.arange
(:func:`range <gfdl.weights.range>`).

- 'uniform': uniform distribution (:func:`uniform <gfdl.weights.uniform>`).

Expand Down Expand Up @@ -674,7 +676,7 @@ class GFDLRegressor(RegressorMixin, MultiOutputMixin, GFDL):

Parameters
----------
hidden_layer_sizes : array-like of shape(n_layers,), default=(100,)
hidden_layer_sizes : array-like of shape (n_layers,), default=(100,)
The ith element represents the number of neurons in the ith
hidden layer.

Expand Down Expand Up @@ -707,7 +709,8 @@ class GFDLRegressor(RegressorMixin, MultiOutputMixin, GFDL):

- 'zeros': set weights to zeros (:func:`zeros <gfdl.weights.zeros>`).

- 'range': discrete uniform distribution (:func:`range <gfdl.weights.range>`).
- 'range': set weights to normalized np.arange
(:func:`range <gfdl.weights.range>`).

- 'uniform': uniform distribution (:func:`uniform <gfdl.weights.uniform>`).

Expand Down Expand Up @@ -768,7 +771,7 @@ class GFDLRegressor(RegressorMixin, MultiOutputMixin, GFDL):
bias term corresponding to layer i.

coeff_ : ndarray of shape (n_features_out, n_outputs)
Output weight matrix learned by linear regression.
Output weight matrix learned by the fit method.

See Also
--------
Expand Down
56 changes: 24 additions & 32 deletions src/gfdl/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def zeros(d, h, **kwargs):
Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.
"""
return np.zeros((h, d))

Expand Down Expand Up @@ -58,20 +59,15 @@ def uniform(d, h, *, rng, **kwargs):
Other Parameters
----------------
**kwargs : dict
Other keyword arguments.

Notes
-----
uniform() had to be split out for pickle/serialization
for conformance with the sklearn estimator API:
https://scikit-learn.org/stable/developers/develop.html#developing-scikit-learn-estimators
Other keyword arguments. Placeholder for exposing distribution
parameters later on.
"""
return rng.uniform(0, 1, (h, d))


def range(d, h, **kwargs):
"""
The weight function returning samples drawn from discrete uniform distribution.
The weight function setting weights to a normalized np.arange.

Parameters
----------
Expand All @@ -85,12 +81,13 @@ def range(d, h, **kwargs):
Returns
-------
ndarray or scalar
Drawn samples from the discrete uniform distribution ``[0, d*h)``.
Set the weights to normalized np.arange over the range ``[0, d*h)``.

Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.
"""
s = np.arange(d * h)
s = np.subtract(s, np.mean(s))
Expand Down Expand Up @@ -124,20 +121,12 @@ def he_uniform(d, h, *, rng, **kwargs):
Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.

Notes
-----
This implementation deviates from the standard expression where
the number of input features (d) are used to compute the limit.
https://faroit.com/keras-docs/2.0.0/initializers/#he_uniform
However, using the standard form returned a different
answer from GrafoRVFL, which uses the output size i.e. hidden
layer size instead (from ChatGPT). Needs further exploration
of why they deviate from the standard form.
If we choose to use the standard form, then our tests cannot be
used to compare against GrafoRVFL as the results could be order
one difference or higher.
"""

limit = np.sqrt(6 / h)
Expand Down Expand Up @@ -169,11 +158,11 @@ def lecun_uniform(d, h, *, rng, **kwargs):
Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.

Notes
-----
Same comment as "he_uniform"
https://faroit.com/keras-docs/2.0.0/initializers/#lecun_uniform
"""

Expand Down Expand Up @@ -206,7 +195,8 @@ def glorot_uniform(d, h, *, rng, **kwargs):
Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.

Notes
-----
Expand Down Expand Up @@ -243,7 +233,8 @@ def normal(d, h, *, rng, **kwargs):
Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Other keyword arguments. Placeholder for exposing distribution
parameters later on.
"""
return rng.normal(0, 1, (h, d))

Expand All @@ -268,16 +259,16 @@ def he_normal(d, h, *, rng, **kwargs):
-------
ndarray or scalar
Draw samples from the He normal distribution with
mean ``0`` and standard deviation ``sqrt(2/d)``.
mean ``0`` and standard deviation ``sqrt(2/h)``.

Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.

Notes
-----
Same comment as "he_uniform"
https://faroit.com/keras-docs/2.0.0/initializers/#he_normal
"""

Expand Down Expand Up @@ -305,16 +296,16 @@ def lecun_normal(d, h, *, rng, **kwargs):
-------
ndarray or scalar
Draw samples from the Lecun normal distribution
with mean ``0`` and standard deviation ``1/sqrt(h)``.
with mean ``0`` and standard deviation ``sqrt(1/h)``.

Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.

Notes
-----
Same comment as "he_uniform"
https://www.tensorflow.org/api_docs/python/tf/keras/initializers/LecunNormal
"""

Expand Down Expand Up @@ -347,7 +338,8 @@ def glorot_normal(d, h, *, rng, **kwargs):
Other Parameters
----------------
**kwargs : dict
Other keyword arguments.
Needed for keyword arguments and compatibility with other weight function apis
but not relevant for this function.

Notes
-----
Expand Down