PyGamLab 1.7.5__py3-none-any.whl → 1.7.8__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.
- PyGamLab/__init__.py +1 -1
- PyGamLab/ai_core/gam_ai.py +188 -21
- {pygamlab-1.7.5.dist-info → pygamlab-1.7.8.dist-info}/METADATA +1 -1
- {pygamlab-1.7.5.dist-info → pygamlab-1.7.8.dist-info}/RECORD +6 -6
- {pygamlab-1.7.5.dist-info → pygamlab-1.7.8.dist-info}/WHEEL +0 -0
- {pygamlab-1.7.5.dist-info → pygamlab-1.7.8.dist-info}/top_level.txt +0 -0
PyGamLab/__init__.py
CHANGED
PyGamLab/ai_core/gam_ai.py
CHANGED
|
@@ -234,19 +234,10 @@ class Gam_Ai_Workflow:
|
|
|
234
234
|
"""
|
|
235
235
|
def __init__(self, model_name, base_dir=None):
|
|
236
236
|
self.model_name = model_name
|
|
237
|
-
# If no base_dir is passed, use the directory of this script
|
|
238
|
-
if base_dir is None:
|
|
239
|
-
base_dir = os.path.join(os.path.dirname(__file__), "gam_models")
|
|
240
|
-
|
|
241
237
|
|
|
242
|
-
self.base_dir = base_dir
|
|
243
|
-
self.file_path = os.path.join(base_dir, f"{model_name}.gam_ai")
|
|
244
|
-
|
|
245
|
-
if not os.path.exists(self.file_path):
|
|
246
|
-
raise FileNotFoundError(f"❌ .gam_ai file not found: {self.file_path}")
|
|
247
238
|
|
|
248
|
-
self.gam
|
|
249
|
-
self.
|
|
239
|
+
self.gam=GAM_AI_MODEL(model_name,base_dir=base_dir)
|
|
240
|
+
self.ml_model = self.gam.ml_model
|
|
250
241
|
self.model_type = self.gam.model_type.lower()
|
|
251
242
|
|
|
252
243
|
print(f"✅ Loaded model '{self.model_name}' ({self.model_type}) successfully.")
|
|
@@ -287,9 +278,9 @@ class Gam_Ai_Workflow:
|
|
|
287
278
|
ValueError
|
|
288
279
|
If no model is loaded.
|
|
289
280
|
"""
|
|
290
|
-
if self.
|
|
281
|
+
if self.ml_model is None:
|
|
291
282
|
raise ValueError("Model not loaded.")
|
|
292
|
-
return self.
|
|
283
|
+
return self.ml_model.predict(X)
|
|
293
284
|
|
|
294
285
|
def refit(self, X, y):
|
|
295
286
|
"""
|
|
@@ -313,8 +304,8 @@ class Gam_Ai_Workflow:
|
|
|
313
304
|
update the `.gam_ai` file on disk. To persist changes, re-save the model
|
|
314
305
|
using `GamAI_io.save()` after refitting.
|
|
315
306
|
"""
|
|
316
|
-
if hasattr(self.
|
|
317
|
-
self.
|
|
307
|
+
if hasattr(self.ml_model, "fit"):
|
|
308
|
+
self.ml_model.fit(X, y)
|
|
318
309
|
print("🔁 Model refitted successfully.")
|
|
319
310
|
else:
|
|
320
311
|
raise NotImplementedError("This model type cannot be refitted.")
|
|
@@ -343,7 +334,7 @@ class Gam_Ai_Workflow:
|
|
|
343
334
|
- Confusion matrix plot
|
|
344
335
|
"""
|
|
345
336
|
|
|
346
|
-
y_pred = self.
|
|
337
|
+
y_pred = self.ml_model.predict(X)
|
|
347
338
|
acc = np.mean(y_pred == y_true)
|
|
348
339
|
print(f"🎯 Accuracy: {acc:.4f}\n")
|
|
349
340
|
print("📊 Classification Report:\n")
|
|
@@ -379,7 +370,7 @@ class Gam_Ai_Workflow:
|
|
|
379
370
|
- Mean Squared Error (MSE)
|
|
380
371
|
- Predicted vs. True value scatter plot
|
|
381
372
|
"""
|
|
382
|
-
y_pred = self.
|
|
373
|
+
y_pred = self.ml_model.predict(X)
|
|
383
374
|
r2 = r2_score(y_true, y_pred)
|
|
384
375
|
mae = mean_absolute_error(y_true, y_pred)
|
|
385
376
|
mse = mean_squared_error(y_true, y_pred)
|
|
@@ -423,13 +414,13 @@ class Gam_Ai_Workflow:
|
|
|
423
414
|
- This visualization assumes that the first two components or features
|
|
424
415
|
are suitable for 2D projection.
|
|
425
416
|
"""
|
|
426
|
-
if hasattr(self.
|
|
427
|
-
y_pred = self.
|
|
417
|
+
if hasattr(self.ml_model, "predict"):
|
|
418
|
+
y_pred = self.ml_model.predict(X)
|
|
428
419
|
plt.scatter(X[:, 0], X[:, 1], c=y_pred, cmap="viridis", s=30)
|
|
429
420
|
plt.title(f"Cluster Visualization — {self.gam.model_name}")
|
|
430
421
|
plt.show()
|
|
431
|
-
elif hasattr(self.
|
|
432
|
-
X_trans = self.
|
|
422
|
+
elif hasattr(self.ml_model, "transform"):
|
|
423
|
+
X_trans = self.ml_model.transform(X)
|
|
433
424
|
plt.scatter(X_trans[:, 0], X_trans[:, 1], s=30)
|
|
434
425
|
plt.title(f"Feature Space — {self.gam.model_name}")
|
|
435
426
|
plt.show()
|
|
@@ -475,6 +466,47 @@ class Gam_Ai_Workflow:
|
|
|
475
466
|
self.visualize_unsupervised(X)
|
|
476
467
|
else:
|
|
477
468
|
raise ValueError(f"Unknown model_type: {self.model_type}")
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def get_GAM_AI_MODEL(self):
|
|
473
|
+
"""
|
|
474
|
+
Retrieve the fully loaded `.gam_ai` model instance associated with this workflow.
|
|
475
|
+
|
|
476
|
+
Returns
|
|
477
|
+
-------
|
|
478
|
+
GAM_AI_MODEL
|
|
479
|
+
The `GAM_AI_MODEL` object currently managed by this workflow instance.
|
|
480
|
+
This object encapsulates both the model’s metadata (e.g., author info,
|
|
481
|
+
training details, performance metrics) and the deserialized scikit-learn model
|
|
482
|
+
accessible via the attribute `ml_model`.
|
|
483
|
+
|
|
484
|
+
Examples
|
|
485
|
+
--------
|
|
486
|
+
>>> workflow = Gam_Ai_Workflow("cu-nanocomposites-poisson-ratio-lr")
|
|
487
|
+
✅ Loaded model 'cu-nanocomposites-poisson-ratio-lr' (train/test) successfully.
|
|
488
|
+
|
|
489
|
+
>>> gam_model = workflow.get_GAM_AI_MODEL()
|
|
490
|
+
>>> type(gam_model)
|
|
491
|
+
<class 'PyGamLab.ai_core.gam_ai.GAM_AI_MODEL'>
|
|
492
|
+
|
|
493
|
+
>>> gam_model.summary()
|
|
494
|
+
📘 MODEL METADATA SUMMARY
|
|
495
|
+
model_name: cu-nanocomposites-poisson-ratio-lr
|
|
496
|
+
author_name: Shaoyu Zhao, Yingyan Zhang, Yihe Zhang et al.
|
|
497
|
+
best_accuracy: {'MAE': 0.0541, 'MSE': 0.0042, 'R2': 0.39}
|
|
498
|
+
⚙️ ML Model: <class 'sklearn.linear_model._base.LinearRegression'>
|
|
499
|
+
|
|
500
|
+
Notes
|
|
501
|
+
-----
|
|
502
|
+
This method serves as a safe accessor for the underlying `GAM_AI_MODEL` instance
|
|
503
|
+
(`self.gam`) loaded during `Gam_Ai_Workflow` initialization.
|
|
504
|
+
It can be used to directly inspect model metadata, retrieve the raw ML model,
|
|
505
|
+
or perform low-level analysis without invoking higher-level workflow methods.
|
|
506
|
+
"""
|
|
507
|
+
return self.gam
|
|
508
|
+
|
|
509
|
+
|
|
478
510
|
|
|
479
511
|
|
|
480
512
|
|
|
@@ -484,6 +516,141 @@ class Gam_Ai_Workflow:
|
|
|
484
516
|
|
|
485
517
|
|
|
486
518
|
|
|
519
|
+
import os, json, io, base64, joblib
|
|
520
|
+
|
|
521
|
+
class GAM_AI_MODEL:
|
|
522
|
+
"""
|
|
523
|
+
A unified data structure for loading and representing `.gam_ai` model packages.
|
|
524
|
+
|
|
525
|
+
The `.gam_ai` format encapsulates both the machine learning model (serialized
|
|
526
|
+
via `joblib` and encoded in Base64) and its accompanying metadata.
|
|
527
|
+
This class provides a standardized interface for deserializing, inspecting,
|
|
528
|
+
and utilizing such packaged models within the PyGamLab AI ecosystem.
|
|
529
|
+
|
|
530
|
+
The class dynamically attaches metadata fields (e.g., `author_name`,
|
|
531
|
+
`model_type`, `best_accuracy`, etc.) as instance attributes and exposes
|
|
532
|
+
the trained ML model under the attribute `ml_model`.
|
|
533
|
+
|
|
534
|
+
Parameters
|
|
535
|
+
----------
|
|
536
|
+
model_name : str
|
|
537
|
+
The name of the model file (without the `.gam_ai` extension) to be loaded.
|
|
538
|
+
|
|
539
|
+
base_dir : str, optional
|
|
540
|
+
The base directory containing `.gam_ai` model files. If not provided,
|
|
541
|
+
the class automatically defaults to the `gam_models` directory located
|
|
542
|
+
alongside this module file.
|
|
543
|
+
|
|
544
|
+
Attributes
|
|
545
|
+
----------
|
|
546
|
+
model_name : str
|
|
547
|
+
The identifier of the loaded `.gam_ai` model.
|
|
548
|
+
|
|
549
|
+
file_path : str
|
|
550
|
+
Full path to the `.gam_ai` file on disk.
|
|
551
|
+
|
|
552
|
+
ml_model : object
|
|
553
|
+
The deserialized scikit-learn model instance (e.g., LinearRegression, RandomForestRegressor, etc.).
|
|
554
|
+
|
|
555
|
+
<dynamic_metadata_fields> : Any
|
|
556
|
+
All key-value pairs from the `"metadata"` section of the `.gam_ai` file are
|
|
557
|
+
dynamically added as attributes (e.g., `author_name`, `description`, `best_accuracy`, etc.).
|
|
558
|
+
|
|
559
|
+
Raises
|
|
560
|
+
------
|
|
561
|
+
FileNotFoundError
|
|
562
|
+
If the specified `.gam_ai` file cannot be found at the resolved `file_path`.
|
|
563
|
+
|
|
564
|
+
Examples
|
|
565
|
+
--------
|
|
566
|
+
>>> from PyGamLab.ai_core.gam_ai import GAM_AI_MODEL
|
|
567
|
+
>>> model = GAM_AI_MODEL("cu-nanocomposites-poisson-ratio-lr")
|
|
568
|
+
✅ Loaded GAM_AI_MODEL: 'cu-nanocomposites-poisson-ratio-lr'
|
|
569
|
+
|
|
570
|
+
>>> model.summary()
|
|
571
|
+
📘 MODEL METADATA SUMMARY
|
|
572
|
+
model_name: cu-nanocomposites-poisson-ratio-lr
|
|
573
|
+
model_type: train/test
|
|
574
|
+
author_name: Shaoyu Zhao, Yingyan Zhang, Yihe Zhang et al.
|
|
575
|
+
best_accuracy: {'MAE': 0.0541, 'MSE': 0.0042, ...}
|
|
576
|
+
⚙️ ML Model: <class 'sklearn.linear_model._base.LinearRegression'>
|
|
577
|
+
|
|
578
|
+
Notes
|
|
579
|
+
-----
|
|
580
|
+
- The `.gam_ai` file format is designed to preserve reproducibility of ML experiments.
|
|
581
|
+
- Metadata is stored in JSON format, while the ML model itself is serialized using `joblib`
|
|
582
|
+
and encoded with Base64 for portability.
|
|
583
|
+
- This class does not train or evaluate models; it only loads and interprets
|
|
584
|
+
pre-trained model artifacts.
|
|
585
|
+
|
|
586
|
+
See Also
|
|
587
|
+
--------
|
|
588
|
+
Gam_Ai_Workflow : High-level workflow manager that builds upon this class to
|
|
589
|
+
provide evaluation, visualization, and retraining utilities.
|
|
590
|
+
"""
|
|
591
|
+
|
|
592
|
+
def __init__(self, model_name, base_dir=None):
|
|
593
|
+
self.model_name = model_name
|
|
594
|
+
|
|
595
|
+
# Default directory if none provided
|
|
596
|
+
if base_dir is None:
|
|
597
|
+
base_dir = os.path.join(os.path.dirname(__file__), "gam_models")
|
|
598
|
+
|
|
599
|
+
self.file_path = os.path.join(base_dir, f"{model_name}.gam_ai")
|
|
600
|
+
|
|
601
|
+
if not os.path.exists(self.file_path):
|
|
602
|
+
raise FileNotFoundError(f"❌ File not found: {self.file_path}")
|
|
603
|
+
|
|
604
|
+
# --- Load JSON file ---
|
|
605
|
+
with open(self.file_path, "r") as f:
|
|
606
|
+
data = json.load(f)
|
|
607
|
+
|
|
608
|
+
metadata = data.get("metadata", {})
|
|
609
|
+
model_data = data.get("model_data", None)
|
|
610
|
+
|
|
611
|
+
# --- Assign metadata attributes dynamically ---
|
|
612
|
+
for key, value in metadata.items():
|
|
613
|
+
setattr(self, key, value)
|
|
614
|
+
|
|
615
|
+
# --- Decode Base64 model ---
|
|
616
|
+
if model_data:
|
|
617
|
+
model_bytes = base64.b64decode(model_data)
|
|
618
|
+
buffer = io.BytesIO(model_bytes)
|
|
619
|
+
self.ml_model = joblib.load(buffer)
|
|
620
|
+
else:
|
|
621
|
+
self.ml_model = None
|
|
622
|
+
|
|
623
|
+
print(f"✅ Loaded GAM_AI_MODEL: '{self.model_name}'")
|
|
624
|
+
|
|
625
|
+
def summary(self):
|
|
626
|
+
"""
|
|
627
|
+
Print a structured overview of all model metadata.
|
|
628
|
+
|
|
629
|
+
This method displays the dynamically loaded metadata attributes
|
|
630
|
+
(e.g., author information, accuracy metrics, DOI, etc.) and the
|
|
631
|
+
associated machine learning model type.
|
|
632
|
+
|
|
633
|
+
Examples
|
|
634
|
+
--------
|
|
635
|
+
>>> model.summary()
|
|
636
|
+
📘 MODEL METADATA SUMMARY
|
|
637
|
+
model_name: cu-nanocomposites-poisson-ratio-lr
|
|
638
|
+
model_type: train/test
|
|
639
|
+
author_name: Shaoyu Zhao
|
|
640
|
+
best_accuracy: {'MAE': 0.054, 'MSE': 0.0042}
|
|
641
|
+
⚙️ ML Model: <class 'sklearn.linear_model._base.LinearRegression'>
|
|
642
|
+
"""
|
|
643
|
+
|
|
644
|
+
print("\n📘 MODEL METADATA SUMMARY\n")
|
|
645
|
+
for k, v in self.__dict__.items():
|
|
646
|
+
if k not in ("ml_model", "file_path"):
|
|
647
|
+
print(f"{k}: {v}")
|
|
648
|
+
print("\n⚙️ ML Model:", type(self.ml_model))
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
487
654
|
|
|
488
655
|
|
|
489
656
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyGamLab
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.8
|
|
4
4
|
Summary: A scientific Python library with constants, unit convertors, formulas, and data analysis tools.
|
|
5
5
|
Home-page: https://github.com/APMaii/pygamlab/tree/main
|
|
6
6
|
Author: Ali Pilehvar Meibody
|
|
@@ -2,9 +2,9 @@ PyGamLab/Constants.py,sha256=SrKmilorNEOXB-4TTYjJGroAmh6Ric7KIPiEXQS7eZg,121229
|
|
|
2
2
|
PyGamLab/Converters.py,sha256=ZZxqOP4SgHjq4mUsmhwShZbcd_hxX2iLfWbJpDimra0,48060
|
|
3
3
|
PyGamLab/Data_Analysis.py,sha256=albkIouUhqHr0NK73I0tipCoNkWchurs1iM9oud2Hig,227565
|
|
4
4
|
PyGamLab/Functions.py,sha256=kbktgvBwbZfoqhdIvObCaEQuR9CK64baRs_4lI30Eqc,146200
|
|
5
|
-
PyGamLab/__init__.py,sha256=
|
|
5
|
+
PyGamLab/__init__.py,sha256=ad0siZK_tr-Lex5cULkL8m6W6jG5IhLe_j_rz8Ldzyo,2000
|
|
6
6
|
PyGamLab/ai_core/__init__.py,sha256=2h3hnypSsMA8sb9jZrfEfAMoCb-6fZQifMJk4ZxGr54,122
|
|
7
|
-
PyGamLab/ai_core/gam_ai.py,sha256=
|
|
7
|
+
PyGamLab/ai_core/gam_ai.py,sha256=EXsCHKIDHen1PXn49bZ6qcWkmbCNWS6yAKmeUzzfyNw,22127
|
|
8
8
|
PyGamLab/ai_core/gam_models/Graphene-armchair-decision-tree-pipe.gam_ai,sha256=Js0k8n1d6mQg9fgKZAGqRvbsRjenw91R-HqM5a85SAU,1871
|
|
9
9
|
PyGamLab/ai_core/gam_models/Graphene-armchair-decision-tree.gam_ai,sha256=hkf46B4dwkCQaEkztyTgAtzsK6OIfx9WUHYMZIuxO7k,6132
|
|
10
10
|
PyGamLab/ai_core/gam_models/Graphene-armchair-knn-pipe.gam_ai,sha256=N71yKhyMhf8M8ZG1d2xjvso1FfJF58EfQKL_NPQZTYI,1517
|
|
@@ -179,7 +179,7 @@ PyGamLab/structures/io/checker.py,sha256=mpSSPX0PoOA2E43pFMj7zpVG4kbUQDRak6ixNCW
|
|
|
179
179
|
PyGamLab/structures/io/conversions.py,sha256=z_bIzF5SNNNzUUYvnmR5rPsMKfODmOB2dN51RDhzHi4,13457
|
|
180
180
|
PyGamLab/structures/io/export.py,sha256=mput2AN7qGD2LlaUVffCQOllWtSVpWN-ilh7eOWg8FQ,13747
|
|
181
181
|
PyGamLab/structures/io/read.py,sha256=JD6WUZolqdRWXdYOHqaw2GXCBwp-OGDyjJaBChfRyQM,21955
|
|
182
|
-
pygamlab-1.7.
|
|
183
|
-
pygamlab-1.7.
|
|
184
|
-
pygamlab-1.7.
|
|
185
|
-
pygamlab-1.7.
|
|
182
|
+
pygamlab-1.7.8.dist-info/METADATA,sha256=ODGnVOrlIEyRs7ldBpeRLJo7FpfYB3TnSWRBGER3QVU,12419
|
|
183
|
+
pygamlab-1.7.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
184
|
+
pygamlab-1.7.8.dist-info/top_level.txt,sha256=E5IBZwx9PoAR8NyXgNAT3iUIuGvYfJlfyOKQY1sNkXU,9
|
|
185
|
+
pygamlab-1.7.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|