-
-
Notifications
You must be signed in to change notification settings - Fork 890
Closed
Description
Is your feature request related to a problem? Please describe.
Save example models stored in BIF format as Python objects using the pickle library (or joblib).
This reduces the loading time for pgmpy's example models.
It also reduces the CI test execution time in GitHub Actions.
Thanks.
- Example script for measuring model load time
import pickle
import os
from pgmpy.utils import get_example_model
import time
start_time = time.time()
origin_model = get_example_model("diabetes")
end_time = time.time()
print("Model Loading Time(BIF)", end_time - start_time)
# Save as Pickle
file_pkl = f"{"model_name"}_test.pkl"
with open(file_pkl, 'wb') as f:
pickle.dump(origin_model, f)
start_time = time.time()
with open(file_pkl, 'rb') as f:
pkl_model = pickle.load(f)
end_time = time.time()
print("Model Loading Time(Python Object)", end_time - start_time)
print("Model Equal Check: ", origin_model.__eq__(pkl_model))- Output
Model Loading Time(BIF) 55.59602880477905
Model Loading Time(Python Object) 0.01642322540283203
Model Equal Check: True
Describe the solution you'd like
- Step:
- Create
TestPickleReaderandTestPickleWriterclasses in thepgmpy/test_readwrite/path. - Create
PickleReaderandPickleWriterclasses in thepgmpy/readwrite/path. - Save the example model as a Python object (
*.pkl) usingpickle. - Modify the
filenamespath in theget_example_modelfunction to the file path created in step 3. - Add code to the
get_example_modelfunction to load the Python object usingPickleReader. - Check if the execution time of the
get_example_modelfunction has been reduced.
Describe alternatives you've considered
picklejoblib
Metadata
Metadata
Assignees
Labels
No labels