gfdl 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gfdl/weights.py ADDED
@@ -0,0 +1,378 @@
1
+ """
2
+ Weight functions for Gradient Free Deep Learning estimators.
3
+ """
4
+
5
+ import numpy as np
6
+
7
+
8
+ def zeros(d, h, **kwargs):
9
+ """
10
+ The weight function setting all weights to zero.
11
+
12
+ This function is useful to test out the effect of
13
+ the data features in isolation.
14
+
15
+ Parameters
16
+ ----------
17
+ d : int
18
+ Number of features in a sample or number of neurons in the previous
19
+ hidden layer.
20
+
21
+ h : int
22
+ Number of neurons in the current hidden layer.
23
+
24
+ Returns
25
+ -------
26
+ ndarray or scalar
27
+ All zeros.
28
+
29
+ Other Parameters
30
+ ----------------
31
+ **kwargs : dict
32
+ Needed for keyword arguments and compatibility with other weight function apis
33
+ but not relevant for this function.
34
+ """
35
+ return np.zeros((h, d))
36
+
37
+
38
+ def uniform(d, h, *, rng, **kwargs):
39
+ """
40
+ The weight function returning samples drawn from uniform distribution.
41
+
42
+ Parameters
43
+ ----------
44
+ d : int
45
+ Number of features in a sample or number of neurons in the previous
46
+ hidden layer.
47
+
48
+ h : int
49
+ Number of neurons in the current hidden layer.
50
+
51
+ rng : np.random.Generator
52
+ A NumPy random number generator instance.
53
+
54
+ Returns
55
+ -------
56
+ ndarray or scalar
57
+ Draw samples from the uniform distribution between ``[0, 1)``.
58
+
59
+ Other Parameters
60
+ ----------------
61
+ **kwargs : dict
62
+ Other keyword arguments. Placeholder for exposing distribution
63
+ parameters later on.
64
+ """
65
+ return rng.uniform(0, 1, (h, d))
66
+
67
+
68
+ def range(d, h, **kwargs):
69
+ """
70
+ The weight function setting weights to a normalized np.arange.
71
+
72
+ Parameters
73
+ ----------
74
+ d : int
75
+ Number of features in a sample or number of neurons in the previous
76
+ hidden layer.
77
+
78
+ h : int
79
+ Number of neurons in the current hidden layer.
80
+
81
+ Returns
82
+ -------
83
+ ndarray or scalar
84
+ Set the weights to normalized np.arange over the range ``[0, d*h)``.
85
+
86
+ Other Parameters
87
+ ----------------
88
+ **kwargs : dict
89
+ Needed for keyword arguments and compatibility with other weight function apis
90
+ but not relevant for this function.
91
+ """
92
+ s = np.arange(d * h)
93
+ s = np.subtract(s, np.mean(s))
94
+ s /= np.std(s)
95
+ s = np.nan_to_num(s)
96
+ return s.reshape(h, d)
97
+
98
+
99
+ def he_uniform(d, h, *, rng, **kwargs):
100
+ """
101
+ The weight function returning samples drawn from He uniform distribution.
102
+
103
+ Parameters
104
+ ----------
105
+ d : int
106
+ Number of features in a sample or number of neurons in the previous
107
+ hidden layer.
108
+
109
+ h : int
110
+ Number of neurons in the current hidden layer.
111
+
112
+ rng : np.random.Generator
113
+ A NumPy random number generator instance.
114
+
115
+ Returns
116
+ -------
117
+ ndarray or scalar
118
+ Draw samples from the He uniform distribution between
119
+ ``[sqrt(6/h), sqrt(6/h))``.
120
+
121
+ Other Parameters
122
+ ----------------
123
+ **kwargs : dict
124
+ Needed for keyword arguments and compatibility with other weight function apis
125
+ but not relevant for this function.
126
+
127
+ Notes
128
+ -----
129
+ https://faroit.com/keras-docs/2.0.0/initializers/#he_uniform
130
+ """
131
+
132
+ limit = np.sqrt(6 / h)
133
+ return rng.uniform(-limit, limit, (h, d))
134
+
135
+
136
+ def lecun_uniform(d, h, *, rng, **kwargs):
137
+ """
138
+ The weight function returning samples drawn from Lecun uniform distribution.
139
+
140
+ Parameters
141
+ ----------
142
+ d : int
143
+ Number of features in a sample or number of neurons in the previous
144
+ hidden layer.
145
+
146
+ h : int
147
+ Number of neurons in the current hidden layer.
148
+
149
+ rng : np.random.Generator
150
+ A NumPy random number generator instance.
151
+
152
+ Returns
153
+ -------
154
+ ndarray or scalar
155
+ Draw samples from the Lecun uniform distribution between
156
+ ``[sqrt(3/h), sqrt(3/h))``.
157
+
158
+ Other Parameters
159
+ ----------------
160
+ **kwargs : dict
161
+ Needed for keyword arguments and compatibility with other weight function apis
162
+ but not relevant for this function.
163
+
164
+ Notes
165
+ -----
166
+ https://faroit.com/keras-docs/2.0.0/initializers/#lecun_uniform
167
+ """
168
+
169
+ limit = np.sqrt(3 / h)
170
+ return rng.uniform(-limit, limit, (h, d))
171
+
172
+
173
+ def glorot_uniform(d, h, *, rng, **kwargs):
174
+ """
175
+ The weight function returning samples drawn from Glorot uniform distribution.
176
+
177
+ Parameters
178
+ ----------
179
+ d : int
180
+ Number of features in a sample or number of neurons in the previous
181
+ hidden layer.
182
+
183
+ h : int
184
+ Number of neurons in the current hidden layer.
185
+
186
+ rng : np.random.Generator
187
+ A NumPy random number generator instance.
188
+
189
+ Returns
190
+ -------
191
+ ndarray or scalar
192
+ Draw samples from the Glorot uniform distribution between
193
+ ``[-sqrt(6/(d+h)), sqrt(6/(d+h)))``.
194
+
195
+ Other Parameters
196
+ ----------------
197
+ **kwargs : dict
198
+ Needed for keyword arguments and compatibility with other weight function apis
199
+ but not relevant for this function.
200
+
201
+ Notes
202
+ -----
203
+ https://faroit.com/keras-docs/2.0.0/initializers/#glorot_uniform
204
+ """
205
+
206
+ fan_avg = 0.5 * (d + h)
207
+ limit = np.sqrt(3 / fan_avg)
208
+ return rng.uniform(-limit, limit, (h, d))
209
+
210
+
211
+ def normal(d, h, *, rng, **kwargs):
212
+ """
213
+ The weight function returning samples drawn from normal distribution.
214
+
215
+ Parameters
216
+ ----------
217
+ d : int
218
+ Number of features in a sample or number of neurons in the previous
219
+ hidden layer.
220
+
221
+ h : int
222
+ Number of neurons in the current hidden layer.
223
+
224
+ rng : np.random.Generator
225
+ A NumPy random number generator instance.
226
+
227
+ Returns
228
+ -------
229
+ ndarray or scalar
230
+ Draw samples from the normal distribution with
231
+ mean ``0`` and standard deviation ``1``.
232
+
233
+ Other Parameters
234
+ ----------------
235
+ **kwargs : dict
236
+ Other keyword arguments. Placeholder for exposing distribution
237
+ parameters later on.
238
+ """
239
+ return rng.normal(0, 1, (h, d))
240
+
241
+
242
+ def he_normal(d, h, *, rng, **kwargs):
243
+ """
244
+ The weight function returning samples drawn from He normal distribution.
245
+
246
+ Parameters
247
+ ----------
248
+ d : int
249
+ Number of features in a sample or number of neurons in the previous
250
+ hidden layer.
251
+
252
+ h : int
253
+ Number of neurons in the current hidden layer.
254
+
255
+ rng : np.random.Generator
256
+ A NumPy random number generator instance.
257
+
258
+ Returns
259
+ -------
260
+ ndarray or scalar
261
+ Draw samples from the He normal distribution with
262
+ mean ``0`` and standard deviation ``sqrt(2/h)``.
263
+
264
+ Other Parameters
265
+ ----------------
266
+ **kwargs : dict
267
+ Needed for keyword arguments and compatibility with other weight function apis
268
+ but not relevant for this function.
269
+
270
+ Notes
271
+ -----
272
+ https://faroit.com/keras-docs/2.0.0/initializers/#he_normal
273
+ """
274
+
275
+ var = np.sqrt(2 / h)
276
+ return rng.normal(0, var, (h, d))
277
+
278
+
279
+ def lecun_normal(d, h, *, rng, **kwargs):
280
+ """
281
+ The weight function returning samples drawn from Lecun normal distribution.
282
+
283
+ Parameters
284
+ ----------
285
+ d : int
286
+ Number of features in a sample or number of neurons in the previous
287
+ hidden layer.
288
+
289
+ h : int
290
+ Number of neurons in the current hidden layer.
291
+
292
+ rng : np.random.Generator
293
+ A NumPy random number generator instance.
294
+
295
+ Returns
296
+ -------
297
+ ndarray or scalar
298
+ Draw samples from the Lecun normal distribution
299
+ with mean ``0`` and standard deviation ``sqrt(1/h)``.
300
+
301
+ Other Parameters
302
+ ----------------
303
+ **kwargs : dict
304
+ Needed for keyword arguments and compatibility with other weight function apis
305
+ but not relevant for this function.
306
+
307
+ Notes
308
+ -----
309
+ https://www.tensorflow.org/api_docs/python/tf/keras/initializers/LecunNormal
310
+ """
311
+
312
+ var = 1 / np.sqrt(h)
313
+ return rng.normal(0, var, (h, d))
314
+
315
+
316
+ def glorot_normal(d, h, *, rng, **kwargs):
317
+ """
318
+ The weight function returning samples drawn from Glorot normal distribution.
319
+
320
+ Parameters
321
+ ----------
322
+ d : int
323
+ Number of features in a sample or number of neurons in the previous
324
+ hidden layer.
325
+
326
+ h : int
327
+ Number of neurons in the current hidden layer.
328
+
329
+ rng : np.random.Generator
330
+ A NumPy random number generator instance.
331
+
332
+ Returns
333
+ -------
334
+ ndarray or scalar
335
+ Draw samples from the Glorot normal distribution with
336
+ mean ``0`` and standard deviation ``sqrt(2/(d+h))``.
337
+
338
+ Other Parameters
339
+ ----------------
340
+ **kwargs : dict
341
+ Needed for keyword arguments and compatibility with other weight function apis
342
+ but not relevant for this function.
343
+
344
+ Notes
345
+ -----
346
+ https://faroit.com/keras-docs/2.0.0/initializers/#glorot_normal
347
+ """
348
+
349
+ fan_avg = 0.5 * (d + h)
350
+ var = np.sqrt(1 / fan_avg)
351
+ return rng.normal(0, var, (h, d))
352
+
353
+
354
+ WEIGHTS = {
355
+ "zeros": zeros,
356
+ "uniform": uniform,
357
+ "range": range,
358
+ "normal": normal,
359
+ "he_uniform": he_uniform,
360
+ "lecun_uniform": lecun_uniform,
361
+ "glorot_uniform": glorot_uniform,
362
+ "he_normal": he_normal,
363
+ "lecun_normal": lecun_normal,
364
+ "glorot_normal": glorot_normal,
365
+ }
366
+
367
+
368
+ def resolve_weight(weight):
369
+ # numpydoc ignore=GL08
370
+ name = weight.strip().lower()
371
+ try:
372
+ w = WEIGHTS[name]
373
+ except KeyError as e:
374
+ allowed = sorted(WEIGHTS.keys())
375
+ raise ValueError(
376
+ f"weight scheme='{weight}' is not supported; choose from {allowed}"
377
+ ) from e
378
+ return w
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: gfdl
3
+ Version: 0.1.0
4
+ Summary: Gradient Free Deep Learning (GFDL) networks including single and multi layer random vector functional link (RVFL) networks and extreme learning machines (ELMs)
5
+ Project-URL: source, https://github.com/lanl/GFDL
6
+ Project-URL: download, https://github.com/lanl/GFDL/releases
7
+ Project-URL: tracker, https://github.com/lanl/GFDL/issues
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Software Development :: Libraries
17
+ Classifier: Topic :: Scientific/Engineering
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: Operating System :: POSIX :: Linux
20
+ Classifier: Operating System :: POSIX
21
+ Classifier: Operating System :: Unix
22
+ Classifier: Operating System :: MacOS
23
+ Requires-Python: >=3.12
24
+ License-File: COPYING
25
+ Requires-Dist: numpy<2.7,>=2.0.0
26
+ Requires-Dist: scikit-learn<1.11,>=1.5.0
27
+ Requires-Dist: scipy<1.20,>=1.13.0
28
+ Requires-Dist: packaging<27.0,>=24.0
29
+ Provides-Extra: test
30
+ Requires-Dist: ucimlrepo; extra == "test"
31
+ Requires-Dist: pytest; extra == "test"
32
+ Requires-Dist: pytest-cov; extra == "test"
33
+ Dynamic: license-file
@@ -0,0 +1,12 @@
1
+ gfdl/__init__.py,sha256=RZGxuS1S6CtWVb78TfscnwBXPNGTdT55DHVFiO5plFc,1156
2
+ gfdl/activations.py,sha256=V5_49AEV8rhGHjk56Lml-bUqiN0_kKqWs3Qsl_UJscw,3483
3
+ gfdl/model.py,sha256=d-rhxJi454yqW0Cz4bxBrjxX-F6XTfkwRo_mYReaTzg,28758
4
+ gfdl/weights.py,sha256=PFcO2C-IppP3b_EvukwPIWwqyJROpWje-JsGz9HIbe8,9397
5
+ gfdl/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ gfdl/tests/test_model.py,sha256=FtUAVHlDAXB6kidhiVTPqSvkclRwlhpkHdEpwhK_glU,20304
7
+ gfdl/tests/test_regression.py,sha256=00FSkqw1WFVhoi3APtypUaNYmKZjgqvpwl3rpHsP6J4,6465
8
+ gfdl-0.1.0.dist-info/licenses/COPYING,sha256=SyvHPYvDWhkWHrNALv0ppjB9yJhLi9mMRdemPF9wYPA,1535
9
+ gfdl-0.1.0.dist-info/METADATA,sha256=SiATGBdeGXFbFmtb5uDUqA08LCPvo3sypnLn5FPnjLw,1438
10
+ gfdl-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
11
+ gfdl-0.1.0.dist-info/top_level.txt,sha256=Sdh-XBQCopJ8FC1mqqCi5dxuzGibAGEPUCTtzltZ84c,5
12
+ gfdl-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025-2026 Los Alamos National Laboratory.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ gfdl