PyGamLab 1.6.1__tar.gz → 1.7.0__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.
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PKG-INFO +1 -1
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/__init__.py +2 -2
- pygamlab-1.7.0/PyGamLab/ai_core/__init__.py +18 -0
- pygamlab-1.7.0/PyGamLab/ai_core/gam_ai.py +490 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/GAM_architectures/GAM_Graphene.py +34 -29
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/gamvis/gamvis_engine.py +1 -1
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab.egg-info/PKG-INFO +1 -1
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab.egg-info/SOURCES.txt +2 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/pyproject.toml +1 -1
- {pygamlab-1.6.1 → pygamlab-1.7.0}/setup.py +1 -1
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/Constants.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/Converters.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/Data_Analysis.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/Functions.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/databases/Aflow.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/databases/COD.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/databases/Jarvis.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/databases/Main_DB.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/databases/Material_projects.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/databases/__init__.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/GAM_architectures/GAM_nano_particles.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/GAM_architectures/GAM_nanotubes.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/GAM_architectures/GAM_phosphorene.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/GAM_architectures/GAM_sillicene.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/GAM_architectures/__init__.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Generators/__init__.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Generators/auto_bulk.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Generators/one_d.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Generators/two_d.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Generators/zero_d.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Primatom/__init__.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Primatom/gam_molecule.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/Primatom/gam_universe.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/__init__.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/gamvis/__init__.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/gamvis/gamvis.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/io/__init__.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/io/checker.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/io/conversions.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/io/export.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/io/read.py +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab.egg-info/dependency_links.txt +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab.egg-info/requires.txt +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab.egg-info/top_level.txt +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/README.md +0 -0
- {pygamlab-1.6.1 → pygamlab-1.7.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyGamLab
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
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
|
|
@@ -43,11 +43,11 @@ Y88b. 88 Y88..88PP. 888 888 888 888...... Y88..88PP. 888 888
|
|
|
43
43
|
'''
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
__version__ = "1.
|
|
46
|
+
__version__ = "1.7.0"
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
__all__ = ["Constants", "Converters", "Functions", "Data_Analysis","structures","databases"]
|
|
50
|
+
__all__ = ["Constants", "Converters", "Functions", "Data_Analysis","structures","databases","ai_core"]
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import json, base64, joblib, io, os
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
from sklearn.metrics import (
|
|
6
|
+
confusion_matrix, ConfusionMatrixDisplay,
|
|
7
|
+
classification_report, r2_score, mean_absolute_error, mean_squared_error
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
class GamAI_io:
|
|
11
|
+
"""
|
|
12
|
+
A unified input/output handler for saving and loading `.gam_ai` model packages.
|
|
13
|
+
|
|
14
|
+
This class encapsulates both machine learning model serialization and
|
|
15
|
+
relevant metadata (e.g., author info, model parameters, training details)
|
|
16
|
+
into a single portable `.gam_ai` file. It enables seamless model deployment,
|
|
17
|
+
archival, and reproducibility by combining the binary model object and
|
|
18
|
+
human-readable metadata in one structured JSON container.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
model_name : str, optional
|
|
23
|
+
A short, descriptive name for the model. Used as the filename during saving.
|
|
24
|
+
model_type : str, optional
|
|
25
|
+
The algorithmic or architectural family of the model
|
|
26
|
+
(e.g., "RandomForest", "XGBoost", "CNN", "Transformer").
|
|
27
|
+
description : str, optional, default=""
|
|
28
|
+
A brief summary describing the model’s purpose, training dataset,
|
|
29
|
+
or key features.
|
|
30
|
+
author_name : str, optional, default=""
|
|
31
|
+
Full name of the model creator.
|
|
32
|
+
author_email : str, optional, default=""
|
|
33
|
+
Contact email for correspondence or citation.
|
|
34
|
+
trainer_name : str, optional, default=""
|
|
35
|
+
The individual or system responsible for model training.
|
|
36
|
+
best_accuracy : float, optional
|
|
37
|
+
The highest validation or test accuracy achieved during training.
|
|
38
|
+
doi : str, optional
|
|
39
|
+
Digital Object Identifier (DOI) associated with the published model or dataset.
|
|
40
|
+
hyperparam_range : dict, optional, default={}
|
|
41
|
+
Dictionary defining hyperparameter search ranges used during optimization.
|
|
42
|
+
best_params : dict, optional, default={}
|
|
43
|
+
Dictionary of the final optimized hyperparameter values.
|
|
44
|
+
ml_model : object, optional
|
|
45
|
+
The trained machine learning model instance (e.g., scikit-learn estimator).
|
|
46
|
+
|
|
47
|
+
Notes
|
|
48
|
+
-----
|
|
49
|
+
The `.gam_ai` file format consists of a JSON object with two main sections:
|
|
50
|
+
|
|
51
|
+
- **metadata**: Contains descriptive fields such as author, model type,
|
|
52
|
+
and hyperparameters.
|
|
53
|
+
- **model_data**: Contains the Base64-encoded binary serialization of the
|
|
54
|
+
trained model, produced via `joblib`.
|
|
55
|
+
|
|
56
|
+
This approach ensures full portability and JSON readability, enabling
|
|
57
|
+
both programmatic and manual inspection of model metadata.
|
|
58
|
+
|
|
59
|
+
Examples
|
|
60
|
+
--------
|
|
61
|
+
>>> from gamai_io import GamAI_io
|
|
62
|
+
>>> from sklearn.ensemble import RandomForestClassifier
|
|
63
|
+
>>> model = RandomForestClassifier(n_estimators=100, random_state=42)
|
|
64
|
+
>>> model.fit(X_train, y_train)
|
|
65
|
+
>>>
|
|
66
|
+
>>> package = GamAI_io(
|
|
67
|
+
... model_name="rf_classifier_v1",
|
|
68
|
+
... model_type="RandomForest",
|
|
69
|
+
... description="Predicts material phases using compositional data",
|
|
70
|
+
... author_name="John Doe",
|
|
71
|
+
... author_email="john.doe@example.com",
|
|
72
|
+
... best_accuracy=0.94,
|
|
73
|
+
... hyperparam_range={"n_estimators": [50, 100, 200]},
|
|
74
|
+
... best_params={"n_estimators": 100, "max_depth": 10},
|
|
75
|
+
... ml_model=model
|
|
76
|
+
... )
|
|
77
|
+
>>>
|
|
78
|
+
>>> # Save to file
|
|
79
|
+
>>> package.save(save_dir="models")
|
|
80
|
+
💾 Saved ml_model package: models/rf_classifier_v1.gam_ai
|
|
81
|
+
>>>
|
|
82
|
+
>>> # Load from file
|
|
83
|
+
>>> loaded_package = GamAI_io.load("models/rf_classifier_v1.gam_ai")
|
|
84
|
+
>>> restored_model = loaded_package.ml_model
|
|
85
|
+
>>> restored_model.predict(X_test[:5])
|
|
86
|
+
|
|
87
|
+
See Also
|
|
88
|
+
--------
|
|
89
|
+
joblib.dump : Efficient serialization of Python objects.
|
|
90
|
+
json : Standard JSON encoder/decoder.
|
|
91
|
+
base64 : Encoding binary model data for safe JSON storage.
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
def __init__(self, **kwargs):
|
|
96
|
+
self.model_name = kwargs.get("model_name")
|
|
97
|
+
self.model_type = kwargs.get("model_type")
|
|
98
|
+
self.description = kwargs.get("description", "")
|
|
99
|
+
self.author_name = kwargs.get("author_name", "")
|
|
100
|
+
self.author_email = kwargs.get("author_email", "")
|
|
101
|
+
self.trainer_name = kwargs.get("trainer_name", "")
|
|
102
|
+
self.best_accuracy = kwargs.get("best_accuracy", None)
|
|
103
|
+
self.doi=kwargs.get("doi", None)
|
|
104
|
+
self.hyperparam_range = kwargs.get("hyperparam_range", {})
|
|
105
|
+
self.best_params = kwargs.get("best_params", {})
|
|
106
|
+
self.ml_model = kwargs.get("ml_model", None)
|
|
107
|
+
|
|
108
|
+
# ----------- Save ----------
|
|
109
|
+
def save(self, save_dir="models"):
|
|
110
|
+
"""
|
|
111
|
+
Serialize and save the current model and metadata as a `.gam_ai` package.
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
save_dir : str, optional, default="models"
|
|
116
|
+
The target directory to save the `.gam_ai` file.
|
|
117
|
+
The directory will be created if it does not exist.
|
|
118
|
+
|
|
119
|
+
Raises
|
|
120
|
+
------
|
|
121
|
+
ValueError
|
|
122
|
+
If no model (`ml_model`) is attached to the current instance.
|
|
123
|
+
|
|
124
|
+
Notes
|
|
125
|
+
-----
|
|
126
|
+
The model is serialized via `joblib` and encoded with Base64 to
|
|
127
|
+
ensure JSON compatibility. The resulting file can be safely shared
|
|
128
|
+
or uploaded to repositories without binary corruption.
|
|
129
|
+
|
|
130
|
+
"""
|
|
131
|
+
os.makedirs(save_dir, exist_ok=True)
|
|
132
|
+
filename = f"{self.model_name}.gam_ai"
|
|
133
|
+
filepath = os.path.join(save_dir, filename)
|
|
134
|
+
|
|
135
|
+
if self.ml_model is None:
|
|
136
|
+
raise ValueError("No ml_model attached to save inside .gam_ai.")
|
|
137
|
+
|
|
138
|
+
buffer = io.BytesIO()
|
|
139
|
+
joblib.dump(self.ml_model, buffer)
|
|
140
|
+
buffer.seek(0)
|
|
141
|
+
encoded_model = base64.b64encode(buffer.read()).decode("utf-8")
|
|
142
|
+
|
|
143
|
+
data = {
|
|
144
|
+
"metadata": {k: v for k, v in self.__dict__.items() if k != "ml_model"},
|
|
145
|
+
"model_data": encoded_model
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
with open(filepath, "w") as f:
|
|
149
|
+
json.dump(data, f, indent=4)
|
|
150
|
+
print(f"💾 Saved ml_model package: {filepath}")
|
|
151
|
+
|
|
152
|
+
# ----------- Load ----------
|
|
153
|
+
@staticmethod
|
|
154
|
+
def load(filepath):
|
|
155
|
+
"""
|
|
156
|
+
Load a `.gam_ai` model package from disk.
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
filepath : str
|
|
161
|
+
Full path to the `.gam_ai` file to be loaded.
|
|
162
|
+
|
|
163
|
+
Returns
|
|
164
|
+
-------
|
|
165
|
+
GamAI_io
|
|
166
|
+
A `GamAI_io` instance containing both metadata and the
|
|
167
|
+
deserialized machine learning model (`ml_model`).
|
|
168
|
+
|
|
169
|
+
Notes
|
|
170
|
+
-----
|
|
171
|
+
The loading process reverses the Base64 encoding and `joblib`
|
|
172
|
+
serialization to reconstruct the original model object.
|
|
173
|
+
|
|
174
|
+
"""
|
|
175
|
+
with open(filepath, "r") as f:
|
|
176
|
+
data = json.load(f)
|
|
177
|
+
metadata = data["metadata"]
|
|
178
|
+
model_data = base64.b64decode(data["model_data"])
|
|
179
|
+
buffer = io.BytesIO(model_data)
|
|
180
|
+
model = joblib.load(buffer)
|
|
181
|
+
return GamAI_io(**metadata, model=model)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
class Gam_Ai_Workflow:
|
|
187
|
+
"""
|
|
188
|
+
Intelligent, type-aware workflow manager for `.gam_ai` model packages.
|
|
189
|
+
|
|
190
|
+
This class provides a unified interface for loading, evaluating, refitting,
|
|
191
|
+
and visualizing machine learning models saved in the `.gam_ai` format.
|
|
192
|
+
It automatically detects the model type (classifier, regressor, or
|
|
193
|
+
unsupervised) and routes the evaluation pipeline accordingly.
|
|
194
|
+
|
|
195
|
+
Parameters
|
|
196
|
+
----------
|
|
197
|
+
model_name : str
|
|
198
|
+
The name (without extension) of the `.gam_ai` file to be loaded.
|
|
199
|
+
base_dir : str, optional, default="gam_models"
|
|
200
|
+
Directory containing saved `.gam_ai` model files.
|
|
201
|
+
|
|
202
|
+
Raises
|
|
203
|
+
------
|
|
204
|
+
FileNotFoundError
|
|
205
|
+
If the specified `.gam_ai` file cannot be located within `base_dir`.
|
|
206
|
+
|
|
207
|
+
Notes
|
|
208
|
+
-----
|
|
209
|
+
This class depends on the `GamAI_io` handler for deserializing `.gam_ai` files.
|
|
210
|
+
Each `.gam_ai` file contains both model metadata and a serialized model object.
|
|
211
|
+
Once loaded, `Gam_Ai_Workflow` provides:
|
|
212
|
+
- Smart evaluation (`evaluate()`)
|
|
213
|
+
- Visualization (`visualize_unsupervised()`)
|
|
214
|
+
- Refit capabilities (`refit()`)
|
|
215
|
+
- Summaries (`summary()`)
|
|
216
|
+
|
|
217
|
+
Examples
|
|
218
|
+
--------
|
|
219
|
+
>>> workflow = Gam_Ai_Workflow("rf_classifier_v1", base_dir="models")
|
|
220
|
+
✅ Loaded model 'rf_classifier_v1' (classifier) successfully.
|
|
221
|
+
>>>
|
|
222
|
+
>>> workflow.summary()
|
|
223
|
+
📘 MODEL SUMMARY
|
|
224
|
+
model_name: rf_classifier_v1
|
|
225
|
+
model_type: classifier
|
|
226
|
+
author_name: John Doe
|
|
227
|
+
best_accuracy: 0.94
|
|
228
|
+
...
|
|
229
|
+
>>>
|
|
230
|
+
>>> workflow.evaluate(X_test, y_test)
|
|
231
|
+
🎯 Accuracy: 0.9470
|
|
232
|
+
📊 Classification Report:
|
|
233
|
+
...
|
|
234
|
+
"""
|
|
235
|
+
def __init__(self, model_name, base_dir="gam_models"):
|
|
236
|
+
self.model_name = model_name
|
|
237
|
+
self.base_dir = base_dir
|
|
238
|
+
self.file_path = os.path.join(base_dir, f"{model_name}.gam_ai")
|
|
239
|
+
|
|
240
|
+
if not os.path.exists(self.file_path):
|
|
241
|
+
raise FileNotFoundError(f"❌ .gam_ai file not found: {self.file_path}")
|
|
242
|
+
|
|
243
|
+
self.gam = GamAI_io.load(self.file_path)
|
|
244
|
+
self.model = self.gam.model
|
|
245
|
+
self.model_type = self.gam.model_type.lower()
|
|
246
|
+
|
|
247
|
+
print(f"✅ Loaded model '{self.model_name}' ({self.model_type}) successfully.")
|
|
248
|
+
|
|
249
|
+
# ---------- General ----------
|
|
250
|
+
def summary(self):
|
|
251
|
+
"""
|
|
252
|
+
Display a concise summary of the loaded model and its metadata.
|
|
253
|
+
|
|
254
|
+
Prints all metadata fields stored in the `.gam_ai` file,
|
|
255
|
+
including model type, author information, and hyperparameters.
|
|
256
|
+
|
|
257
|
+
Returns
|
|
258
|
+
-------
|
|
259
|
+
None
|
|
260
|
+
"""
|
|
261
|
+
print("\n📘 MODEL SUMMARY")
|
|
262
|
+
for k, v in self.gam.__dict__.items():
|
|
263
|
+
if k != "model":
|
|
264
|
+
print(f"{k}: {v}")
|
|
265
|
+
|
|
266
|
+
def predict(self, X):
|
|
267
|
+
"""
|
|
268
|
+
Run model inference on input data.
|
|
269
|
+
|
|
270
|
+
Parameters
|
|
271
|
+
----------
|
|
272
|
+
X : array-like
|
|
273
|
+
Input features compatible with the trained model.
|
|
274
|
+
|
|
275
|
+
Returns
|
|
276
|
+
-------
|
|
277
|
+
np.ndarray
|
|
278
|
+
Model predictions corresponding to `X`.
|
|
279
|
+
|
|
280
|
+
Raises
|
|
281
|
+
------
|
|
282
|
+
ValueError
|
|
283
|
+
If no model is loaded.
|
|
284
|
+
"""
|
|
285
|
+
if self.model is None:
|
|
286
|
+
raise ValueError("Model not loaded.")
|
|
287
|
+
return self.model.predict(X)
|
|
288
|
+
|
|
289
|
+
def refit(self, X, y):
|
|
290
|
+
"""
|
|
291
|
+
Retrain (refit) the loaded model on new data.
|
|
292
|
+
|
|
293
|
+
Parameters
|
|
294
|
+
----------
|
|
295
|
+
X : array-like
|
|
296
|
+
Training features.
|
|
297
|
+
y : array-like
|
|
298
|
+
Corresponding training labels or targets.
|
|
299
|
+
|
|
300
|
+
Raises
|
|
301
|
+
------
|
|
302
|
+
NotImplementedError
|
|
303
|
+
If the model does not support the `.fit()` method.
|
|
304
|
+
|
|
305
|
+
Notes
|
|
306
|
+
-----
|
|
307
|
+
This method modifies the current model in place and does not automatically
|
|
308
|
+
update the `.gam_ai` file on disk. To persist changes, re-save the model
|
|
309
|
+
using `GamAI_io.save()` after refitting.
|
|
310
|
+
"""
|
|
311
|
+
if hasattr(self.model, "fit"):
|
|
312
|
+
self.model.fit(X, y)
|
|
313
|
+
print("🔁 Model refitted successfully.")
|
|
314
|
+
else:
|
|
315
|
+
raise NotImplementedError("This model type cannot be refitted.")
|
|
316
|
+
|
|
317
|
+
# ---------- Classifier ----------
|
|
318
|
+
def evaluate_classifier(self, X, y_true):
|
|
319
|
+
"""
|
|
320
|
+
Evaluate a classification model and display key performance metrics.
|
|
321
|
+
|
|
322
|
+
Parameters
|
|
323
|
+
----------
|
|
324
|
+
X : array-like
|
|
325
|
+
Input test features.
|
|
326
|
+
y_true : array-like
|
|
327
|
+
Ground-truth class labels.
|
|
328
|
+
|
|
329
|
+
Returns
|
|
330
|
+
-------
|
|
331
|
+
None
|
|
332
|
+
|
|
333
|
+
Notes
|
|
334
|
+
-----
|
|
335
|
+
This method computes and displays:
|
|
336
|
+
- Accuracy score
|
|
337
|
+
- Classification report
|
|
338
|
+
- Confusion matrix plot
|
|
339
|
+
"""
|
|
340
|
+
|
|
341
|
+
y_pred = self.model.predict(X)
|
|
342
|
+
acc = np.mean(y_pred == y_true)
|
|
343
|
+
print(f"🎯 Accuracy: {acc:.4f}\n")
|
|
344
|
+
print("📊 Classification Report:\n")
|
|
345
|
+
print(classification_report(y_true, y_pred))
|
|
346
|
+
|
|
347
|
+
cm = confusion_matrix(y_true, y_pred)
|
|
348
|
+
disp = ConfusionMatrixDisplay(cm)
|
|
349
|
+
disp.plot(cmap="Blues")
|
|
350
|
+
plt.title(f"Confusion Matrix: {self.gam.model_name}")
|
|
351
|
+
plt.show()
|
|
352
|
+
|
|
353
|
+
# ---------- Regressor ----------
|
|
354
|
+
def evaluate_regressor(self, X, y_true):
|
|
355
|
+
"""
|
|
356
|
+
Evaluate a regression model and visualize performance trends.
|
|
357
|
+
|
|
358
|
+
Parameters
|
|
359
|
+
----------
|
|
360
|
+
X : array-like
|
|
361
|
+
Input test features.
|
|
362
|
+
y_true : array-like
|
|
363
|
+
True continuous target values.
|
|
364
|
+
|
|
365
|
+
Returns
|
|
366
|
+
-------
|
|
367
|
+
None
|
|
368
|
+
|
|
369
|
+
Notes
|
|
370
|
+
-----
|
|
371
|
+
This method prints and plots:
|
|
372
|
+
- Coefficient of determination (R²)
|
|
373
|
+
- Mean Absolute Error (MAE)
|
|
374
|
+
- Mean Squared Error (MSE)
|
|
375
|
+
- Predicted vs. True value scatter plot
|
|
376
|
+
"""
|
|
377
|
+
y_pred = self.model.predict(X)
|
|
378
|
+
r2 = r2_score(y_true, y_pred)
|
|
379
|
+
mae = mean_absolute_error(y_true, y_pred)
|
|
380
|
+
mse = mean_squared_error(y_true, y_pred)
|
|
381
|
+
|
|
382
|
+
print(f"📈 R²: {r2:.4f}")
|
|
383
|
+
print(f"📉 MAE: {mae:.4f}")
|
|
384
|
+
print(f"📉 MSE: {mse:.4f}\n")
|
|
385
|
+
|
|
386
|
+
plt.figure(figsize=(6, 4))
|
|
387
|
+
plt.scatter(y_true, y_pred, alpha=0.6)
|
|
388
|
+
plt.plot([min(y_true), max(y_true)], [min(y_true), max(y_true)], 'r--')
|
|
389
|
+
plt.xlabel("True Values")
|
|
390
|
+
plt.ylabel("Predicted Values")
|
|
391
|
+
plt.title(f"Prediction Trend — {self.gam.model_name}")
|
|
392
|
+
plt.grid(True)
|
|
393
|
+
plt.show()
|
|
394
|
+
|
|
395
|
+
# ---------- Unsupervised ----------
|
|
396
|
+
def visualize_unsupervised(self, X):
|
|
397
|
+
"""
|
|
398
|
+
Visualize cluster assignments or feature transformations for unsupervised models.
|
|
399
|
+
|
|
400
|
+
Parameters
|
|
401
|
+
----------
|
|
402
|
+
X : array-like of shape (n_samples, n_features)
|
|
403
|
+
Input data to visualize.
|
|
404
|
+
|
|
405
|
+
Returns
|
|
406
|
+
-------
|
|
407
|
+
None
|
|
408
|
+
|
|
409
|
+
Raises
|
|
410
|
+
------
|
|
411
|
+
NotImplementedError
|
|
412
|
+
If the model lacks both `predict()` and `transform()` methods.
|
|
413
|
+
|
|
414
|
+
Notes
|
|
415
|
+
-----
|
|
416
|
+
- If the model has a `.predict()` method, cluster assignments are plotted.
|
|
417
|
+
- If the model has a `.transform()` method, the transformed feature space is shown.
|
|
418
|
+
- This visualization assumes that the first two components or features
|
|
419
|
+
are suitable for 2D projection.
|
|
420
|
+
"""
|
|
421
|
+
if hasattr(self.model, "predict"):
|
|
422
|
+
y_pred = self.model.predict(X)
|
|
423
|
+
plt.scatter(X[:, 0], X[:, 1], c=y_pred, cmap="viridis", s=30)
|
|
424
|
+
plt.title(f"Cluster Visualization — {self.gam.model_name}")
|
|
425
|
+
plt.show()
|
|
426
|
+
elif hasattr(self.model, "transform"):
|
|
427
|
+
X_trans = self.model.transform(X)
|
|
428
|
+
plt.scatter(X_trans[:, 0], X_trans[:, 1], s=30)
|
|
429
|
+
plt.title(f"Feature Space — {self.gam.model_name}")
|
|
430
|
+
plt.show()
|
|
431
|
+
else:
|
|
432
|
+
raise NotImplementedError("This unsupervised model has no visualization method.")
|
|
433
|
+
|
|
434
|
+
# ---------- Smart Evaluation ----------
|
|
435
|
+
def evaluate(self, X, y_true=None):
|
|
436
|
+
"""
|
|
437
|
+
Automatically dispatch model evaluation based on its declared type.
|
|
438
|
+
|
|
439
|
+
Parameters
|
|
440
|
+
----------
|
|
441
|
+
X : array-like
|
|
442
|
+
Input data.
|
|
443
|
+
y_true : array-like, optional
|
|
444
|
+
Ground-truth labels or target values (required for supervised models).
|
|
445
|
+
|
|
446
|
+
Raises
|
|
447
|
+
------
|
|
448
|
+
ValueError
|
|
449
|
+
If the model type is not recognized.
|
|
450
|
+
|
|
451
|
+
Notes
|
|
452
|
+
-----
|
|
453
|
+
This method intelligently determines which evaluation routine to run:
|
|
454
|
+
- `evaluate_classifier()` for classification models
|
|
455
|
+
- `evaluate_regressor()` for regression models
|
|
456
|
+
- `visualize_unsupervised()` for unsupervised models
|
|
457
|
+
|
|
458
|
+
Examples
|
|
459
|
+
--------
|
|
460
|
+
>>> workflow.evaluate(X_test, y_test)
|
|
461
|
+
🎯 Accuracy: 0.9470
|
|
462
|
+
📊 Classification Report:
|
|
463
|
+
...
|
|
464
|
+
"""
|
|
465
|
+
if self.model_type == "classifier":
|
|
466
|
+
self.evaluate_classifier(X, y_true)
|
|
467
|
+
elif self.model_type == "regressor":
|
|
468
|
+
self.evaluate_regressor(X, y_true)
|
|
469
|
+
elif self.model_type == "unsupervised":
|
|
470
|
+
self.visualize_unsupervised(X)
|
|
471
|
+
else:
|
|
472
|
+
raise ValueError(f"Unknown model_type: {self.model_type}")
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
@@ -29,6 +29,40 @@ except ImportError:
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def graphene_unit_cell(lattice_constant: float = 2.46) -> Tuple[np.ndarray, np.ndarray]:
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
Flexible graphene nanostructure generator.
|
|
35
|
+
|
|
36
|
+
Supports both periodic unit cells and finite flakes with various edge types,
|
|
37
|
+
rotations, and coordinate transformations. Designed for extensibility to
|
|
38
|
+
multilayers, defects, and strain.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
a = lattice_constant
|
|
45
|
+
|
|
46
|
+
# Two-atom basis in graphene unit cell
|
|
47
|
+
basis = np.array([
|
|
48
|
+
[0.0, 0.0, 0.0], # First carbon
|
|
49
|
+
[a / 2.0, a * np.sqrt(3) / 6.0, 0.0] # Second carbon
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
# Lattice vectors for hexagonal lattice
|
|
53
|
+
lattice_vectors = np.array([
|
|
54
|
+
[a, 0.0, 0.0], # a1
|
|
55
|
+
[a / 2.0, a * np.sqrt(3) / 2.0, 0.0] # a2
|
|
56
|
+
])
|
|
57
|
+
|
|
58
|
+
return basis, lattice_vectors
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Graphene:
|
|
32
66
|
"""
|
|
33
67
|
Class for constructing and manipulating monolayer graphene nanostructures.
|
|
34
68
|
|
|
@@ -121,35 +155,6 @@ def graphene_unit_cell(lattice_constant: float = 2.46) -> Tuple[np.ndarray, np.n
|
|
|
121
155
|
>>> atoms = g.to_ase()
|
|
122
156
|
>>> print(len(atoms), "atoms in graphene flake")
|
|
123
157
|
"""
|
|
124
|
-
a = lattice_constant
|
|
125
|
-
|
|
126
|
-
# Two-atom basis in graphene unit cell
|
|
127
|
-
basis = np.array([
|
|
128
|
-
[0.0, 0.0, 0.0], # First carbon
|
|
129
|
-
[a / 2.0, a * np.sqrt(3) / 6.0, 0.0] # Second carbon
|
|
130
|
-
])
|
|
131
|
-
|
|
132
|
-
# Lattice vectors for hexagonal lattice
|
|
133
|
-
lattice_vectors = np.array([
|
|
134
|
-
[a, 0.0, 0.0], # a1
|
|
135
|
-
[a / 2.0, a * np.sqrt(3) / 2.0, 0.0] # a2
|
|
136
|
-
])
|
|
137
|
-
|
|
138
|
-
return basis, lattice_vectors
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
class Graphene:
|
|
146
|
-
"""
|
|
147
|
-
Flexible graphene nanostructure generator.
|
|
148
|
-
|
|
149
|
-
Supports both periodic unit cells and finite flakes with various edge types,
|
|
150
|
-
rotations, and coordinate transformations. Designed for extensibility to
|
|
151
|
-
multilayers, defects, and strain.
|
|
152
|
-
"""
|
|
153
158
|
|
|
154
159
|
def __init__(self, lattice_constant: float = 2.46, width: float = 10.0,
|
|
155
160
|
length: float = 10.0, edge_type: str = 'armchair',
|
|
@@ -218,7 +218,7 @@ class GAMVisualizer(QMainWindow):
|
|
|
218
218
|
# Create logo overlay
|
|
219
219
|
self.logo_label = QLabel(vtk_container)
|
|
220
220
|
try:
|
|
221
|
-
pixmap = QPixmap("
|
|
221
|
+
pixmap = QPixmap("./pygamlab_gamvis.png")
|
|
222
222
|
# Scale the logo 3 times bigger
|
|
223
223
|
scaled_pixmap = pixmap.scaled(300, 150, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
|
224
224
|
self.logo_label.setPixmap(scaled_pixmap)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyGamLab
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
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
|
|
@@ -11,6 +11,8 @@ PyGamLab.egg-info/SOURCES.txt
|
|
|
11
11
|
PyGamLab.egg-info/dependency_links.txt
|
|
12
12
|
PyGamLab.egg-info/requires.txt
|
|
13
13
|
PyGamLab.egg-info/top_level.txt
|
|
14
|
+
PyGamLab/ai_core/__init__.py
|
|
15
|
+
PyGamLab/ai_core/gam_ai.py
|
|
14
16
|
PyGamLab/databases/Aflow.py
|
|
15
17
|
PyGamLab/databases/COD.py
|
|
16
18
|
PyGamLab/databases/Jarvis.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "PyGamLab"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.7.0"
|
|
8
8
|
description = "A scientific Python library with constants, unit convertors, formulas, and data analysis tools."
|
|
9
9
|
authors = [
|
|
10
10
|
{ name="Ali Pilehvar Meibody", email="alipilehvar1999@Gmail.com" }
|
|
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name="PyGamLab",
|
|
8
|
-
version="1.
|
|
8
|
+
version="1.7.0",
|
|
9
9
|
author="Ali Pilehvar Meibody",
|
|
10
10
|
author_email="alipilehvar1999@gmail.com",
|
|
11
11
|
description="A scientific Python library with constants, unit convertors, formulas, and data analysis tools.",
|
|
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
|
{pygamlab-1.6.1 → pygamlab-1.7.0}/PyGamLab/structures/GAM_architectures/GAM_nano_particles.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
|
|
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
|
|
File without changes
|
|
File without changes
|