classy-szfast 0.0.14__tar.gz → 0.0.16__tar.gz
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.
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/.gitignore +1 -0
- {classy_szfast-0.0.14/classy_szfast.egg-info → classy_szfast-0.0.16}/PKG-INFO +1 -1
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/restore_nn.py +172 -35
- {classy_szfast-0.0.14 → classy_szfast-0.0.16/classy_szfast.egg-info}/PKG-INFO +1 -1
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/setup.py +1 -1
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/MANIFEST.in +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/README.md +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/__init__.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/classy_sz.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/classy_szfast.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/config.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/cosmopower.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/cosmosis_classy_szfast_interface.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/custom_bias/__init__.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/custom_bias/custom_bias.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/custom_profiles/__init__.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/custom_profiles/custom_profiles.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/pks_and_sigmas.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/suppress_warnings.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/utils.py +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast.egg-info/SOURCES.txt +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast.egg-info/dependency_links.txt +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast.egg-info/requires.txt +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast.egg-info/top_level.txt +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/pypi_upload.sh +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/pyproject.toml +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/requirements.txt +0 -0
- {classy_szfast-0.0.14 → classy_szfast-0.0.16}/setup.cfg +0 -0
@@ -87,26 +87,82 @@ class Restore_NN(tf.keras.Model):
|
|
87
87
|
print(multiline_str)
|
88
88
|
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
):
|
90
|
+
|
91
|
+
# from https://github.com/HTJense/cosmopower/blob/packaging-paper/cosmopower/cosmopower_NN.py
|
92
|
+
def restore(self, filename: str, allow_pickle: bool = False) -> None:
|
94
93
|
r"""
|
95
|
-
Load pre-trained model
|
94
|
+
Load pre-trained model.
|
95
|
+
The default file format is compressed numpy files (.npz). The
|
96
|
+
Module will attempt to use this as a file extension and restore
|
97
|
+
from there (i.e. look for `filename.npz`). If this file does
|
98
|
+
not exist, and `allow_pickle` is set to True, then the file
|
99
|
+
`filename.pkl` will be attempted to be read by `restore_pickle`.
|
100
|
+
|
101
|
+
The function will trim the file extension from `filename`, so
|
102
|
+
`restore("filename")` and `restore("filename.npz")` are identical.
|
96
103
|
|
97
104
|
Parameters:
|
98
|
-
|
99
|
-
|
105
|
+
:param filename: filename (without suffix) where model was saved.
|
106
|
+
:param allow_pickle: whether or not to permit passing this filename
|
107
|
+
to the `restore_pickle` function.
|
100
108
|
"""
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
109
|
+
# Check if npz file exists.
|
110
|
+
filename_npz = filename + ".npz"
|
111
|
+
if not os.path.exists(filename_npz):
|
112
|
+
# Can we load this file as a pickle file?
|
113
|
+
filename_pkl = filename + ".pkl"
|
114
|
+
if allow_pickle and os.path.exists(filename_pkl):
|
115
|
+
self.restore_pickle(filename_pkl)
|
116
|
+
return
|
117
|
+
|
118
|
+
raise IOError(f"Failed to restore network from {filename}: "
|
119
|
+
+ (" is a pickle file, try setting 'allow_pickle = \
|
120
|
+
True'" if os.path.exists(filename_pkl) else
|
121
|
+
" does not exist."))
|
122
|
+
|
123
|
+
with open(filename_npz, "rb") as fp:
|
124
|
+
fpz = np.load(fp, allow_pickle=True)["arr_0"].flatten()[0]
|
125
|
+
|
126
|
+
# print('filename_npz:', filename_npz)
|
127
|
+
# print("Keys in the .npz file:", list(fpz.keys()))
|
128
|
+
|
129
|
+
self.architecture = fpz["architecture"]
|
130
|
+
self.n_layers = fpz["n_layers"]
|
131
|
+
self.n_hidden = fpz["n_hidden"]
|
132
|
+
self.n_parameters = fpz["n_parameters"]
|
133
|
+
self.n_modes = fpz["n_modes"]
|
134
|
+
|
135
|
+
self.parameters = list(fpz["parameters"])
|
136
|
+
self.modes = fpz["modes"]
|
137
|
+
|
138
|
+
# self.parameters_mean_ = fpz["parameters_mean"]
|
139
|
+
# self.parameters_std_ = fpz["parameters_std"]
|
140
|
+
# self.features_mean_ = fpz["features_mean"]
|
141
|
+
# self.features_std_ = fpz["features_std"]
|
142
|
+
|
143
|
+
# Attempt to load 'parameters_mean' or fall back to 'param_train_mean'
|
144
|
+
self.parameters_mean_ = fpz.get("parameters_mean", fpz.get("param_train_mean"))
|
145
|
+
self.parameters_std_ = fpz.get("parameters_std", fpz.get("param_train_std"))
|
146
|
+
self.features_mean_ = fpz.get("features_mean", fpz.get("feature_train_mean"))
|
147
|
+
self.features_std_ = fpz.get("features_std", fpz.get("feature_train_std"))
|
148
|
+
|
149
|
+
|
150
|
+
# Fallback to 'weights_' if individual 'W_i' are not found
|
151
|
+
if "weights_" in fpz:
|
152
|
+
# Assign the list of weight arrays from 'weights_' directly
|
153
|
+
self.W_ = fpz["weights_"]
|
154
|
+
else:
|
155
|
+
# Use individual weight arrays if available
|
156
|
+
self.W_ = [fpz[f"W_{i}"] for i in range(self.n_layers)]
|
157
|
+
|
158
|
+
# Fallback to 'biases_' if individual 'b_i' are not found
|
159
|
+
if "biases_" in fpz:
|
160
|
+
self.b_ = fpz["biases_"]
|
161
|
+
else:
|
162
|
+
self.b_ = [fpz[f"b_{i}"] for i in range(self.n_layers)]
|
163
|
+
|
164
|
+
self.alphas_ = fpz[f"alphas_"]
|
165
|
+
self.betas_ = fpz[f"betas_"]
|
110
166
|
|
111
167
|
|
112
168
|
# auxiliary function to sort input parameters
|
@@ -274,29 +330,110 @@ class Restore_PCAplusNN(tf.keras.Model):
|
|
274
330
|
|
275
331
|
|
276
332
|
|
277
|
-
#
|
278
|
-
def restore(self,
|
279
|
-
filename,
|
280
|
-
):
|
333
|
+
# from https://github.com/HTJense/cosmopower/blob/packaging-paper/cosmopower/cosmopower_PCAplusNN.py
|
334
|
+
def restore(self, filename: str, allow_pickle: bool = False) -> None:
|
281
335
|
r"""
|
282
|
-
Load pre-trained model
|
336
|
+
Load pre-trained model.
|
337
|
+
The default file format is compressed numpy files (.npz). The
|
338
|
+
Module will attempt to use this as a file extension and restore
|
339
|
+
from there (i.e. look for `filename.npz`). If this file does
|
340
|
+
not exist, and `allow_pickle` is set to True, then the file
|
341
|
+
`filename.pkl` will be attempted to be read by `restore_pickle`.
|
342
|
+
|
343
|
+
The function will trim the file extension from `filename`, so
|
344
|
+
`restore("filename")` and `restore("filename.npz")` are identical.
|
283
345
|
|
284
346
|
Parameters:
|
285
|
-
|
286
|
-
|
347
|
+
:param filename: filename (without suffix) where model was saved.
|
348
|
+
:param allow_pickle: whether or not to permit passing this filename to
|
349
|
+
the `restore_pickle` function.
|
287
350
|
"""
|
288
|
-
#
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
351
|
+
# Check if npz file exists.
|
352
|
+
filename_npz = filename + ".npz"
|
353
|
+
if not os.path.exists(filename_npz):
|
354
|
+
# Can we load this file as a pickle file?
|
355
|
+
filename_pkl = filename + ".pkl"
|
356
|
+
if allow_pickle and os.path.exists(filename_pkl):
|
357
|
+
self.restore_pickle(filename_pkl)
|
358
|
+
return
|
359
|
+
|
360
|
+
raise IOError(f"Failed to restore network from {filename}: "
|
361
|
+
+ (" is a pickle file, try setting 'allow_pickle = \
|
362
|
+
True'" if os.path.exists(filename_pkl) else
|
363
|
+
" does not exist."))
|
364
|
+
|
365
|
+
with open(filename_npz, "rb") as fp:
|
366
|
+
fpz = np.load(fp, allow_pickle=True)["arr_0"].flatten()[0]
|
367
|
+
|
368
|
+
# print('filename_npz:', filename_npz)
|
369
|
+
# print("Keys in the .npz file:", list(fpz.keys()))
|
370
|
+
|
371
|
+
|
372
|
+
self.architecture = fpz["architecture"]
|
373
|
+
self.n_layers = fpz["n_layers"]
|
374
|
+
self.n_hidden = fpz["n_hidden"]
|
375
|
+
self.n_parameters = fpz["n_parameters"]
|
376
|
+
self.n_modes = fpz["n_modes"]
|
377
|
+
|
378
|
+
self.parameters = fpz["parameters"]
|
379
|
+
self.modes = fpz["modes"]
|
380
|
+
|
381
|
+
# Attempt to load 'parameters_mean' or fall back to 'param_train_mean'
|
382
|
+
self.parameters_mean_ = fpz.get("parameters_mean", fpz.get("param_train_mean"))
|
383
|
+
self.parameters_std_ = fpz.get("parameters_std", fpz.get("param_train_std"))
|
384
|
+
self.features_mean_ = fpz.get("features_mean", fpz.get("feature_train_mean"))
|
385
|
+
self.features_std_ = fpz.get("features_std", fpz.get("feature_train_std"))
|
386
|
+
|
387
|
+
# Handle PCA-related keys
|
388
|
+
# self.pca_mean_ = fpz["pca_mean"]
|
389
|
+
# self.pca_std_ = fpz["pca_std"]
|
390
|
+
# self.n_pcas = fpz["n_pcas"]
|
391
|
+
|
392
|
+
self.pca_mean_ = fpz["pca_mean"]
|
393
|
+
self.pca_std_ = fpz["pca_std"]
|
394
|
+
self.n_pcas = fpz["n_pcas"]
|
395
|
+
self.pca_transform_matrix_ = fpz["pca_transform_matrix"]
|
396
|
+
|
397
|
+
# print('n_pcas:', self.n_pcas)
|
398
|
+
|
399
|
+
# filename = "/Users/boris/Work/CLASS-SZ/SO-SZ/cosmopower-organization/lcdm/TTTEEE/TE_v1.pkl"
|
400
|
+
# f = open(filename, 'rb')
|
401
|
+
# self.W_, self.b_, self.alphas_, self.betas_, \
|
402
|
+
# self.parameters_mean_, self.parameters_std_, \
|
403
|
+
# self.pca_mean_, self.pca_std_, \
|
404
|
+
# self.features_mean_, self.features_std_, \
|
405
|
+
# self.parameters, self.n_parameters, \
|
406
|
+
# self.modes, self.n_modes, \
|
407
|
+
# self.n_pcas, self.pca_transform_matrix_, \
|
408
|
+
# self.n_hidden, self.n_layers, self.architecture = pickle.load(f)
|
409
|
+
|
410
|
+
# print('self.n_pcas:', self.n_pcas)
|
411
|
+
# print('self.pca_transform_matrix_:', self.pca_transform_matrix_)
|
412
|
+
# print('PCA mean:', self.pca_mean_)
|
413
|
+
# print('PCA std:', self.pca_std_)
|
414
|
+
# f.close()
|
415
|
+
# import sys
|
416
|
+
# sys.exit(0)
|
417
|
+
|
418
|
+
# self.pca_transform_matrix_ = fpz["pca_transform_matrix"]
|
419
|
+
|
420
|
+
# Fallback to 'weights_' if individual 'W_i' are not found
|
421
|
+
if "weights_" in fpz:
|
422
|
+
# Assign the list of weight arrays from 'weights_' directly
|
423
|
+
self.W_ = fpz["weights_"]
|
424
|
+
else:
|
425
|
+
# Use individual weight arrays if available
|
426
|
+
self.W_ = [fpz[f"W_{i}"] for i in range(self.n_layers)]
|
427
|
+
|
428
|
+
# Fallback to 'biases_' if individual 'b_i' are not found
|
429
|
+
if "biases_" in fpz:
|
430
|
+
self.b_ = fpz["biases_"]
|
431
|
+
else:
|
432
|
+
self.b_ = [fpz[f"b_{i}"] for i in range(self.n_layers)]
|
433
|
+
|
434
|
+
# Handle alphas and betas
|
435
|
+
self.alphas_ = fpz.get("alphas_", [fpz.get(f"alphas_{i}") for i in range(self.n_layers - 1)])
|
436
|
+
self.betas_ = fpz.get("betas_", [fpz.get(f"betas_{i}") for i in range(self.n_layers - 1)])
|
300
437
|
|
301
438
|
|
302
439
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/cosmosis_classy_szfast_interface.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{classy_szfast-0.0.14 → classy_szfast-0.0.16}/classy_szfast/custom_profiles/custom_profiles.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|