pyNNsMD package¶
Subpackages¶
Submodules¶
pyNNsMD.NNsMD module¶
-
class
pyNNsMD.NNsMD.
NeuralNetEnsemble
(directory: str, number_models: int = 2, logger=None)[source]¶ Bases:
object
Main class NeuralNetPes that keeps multiple keras models and manages training and prediction.
Main class for neural network (NN) container to provide multiple NN instances.
Enables uncertainty estimate as well as training and prediction of arbitrary tf.keras models for potentials plus gradients and couplings. The python class is supposed to allow parallel training.
The individual model types are further stored to file in the directory specified in initialization.
The information and models are passed via file to training scripts.
from pyNNsMD.NNsMD import NeuralNetEnsemble nn = NeuralNetEnsemble("TestEnergy/", 2)
-
__init__
(directory: str, number_models: int = 2, logger=None)[source]¶ Initialize empty
NeuralNetEnsemble
instance.
-
create
(models: list, scalers: list)[source]¶ Initialize and build a list of keras models. Missing hyperparameter are filled from default.
- Parameters
- Returns
self
-
data
(atoms: Optional[list] = None, geometries: Optional[list] = None, forces: Optional[list] = None, energies: Optional[list] = None, couplings: Optional[list] = None)[source]¶
-
fit
(training_scripts: list, gpu_dist: Optional[list] = None, proc_async=True, fit_mode='training')[source]¶ Fit NN to data. Model weights and hyperparameter must always be saved to file before fit.
The fit routine calls training scripts on the data_folder in parallel. The type of execution is found in src.fit with the training src.training_ scripts.
- Parameters
training_scripts (list) – List of training scripts for each model.
gpu_dist (list, optional) – List of GPUs for each NN. Default is [].
proc_async (bool, optional) – Try to run parallel. Default is True.
fit_mode (str, optional) – Whether to do ‘training’ or ‘retraining’ the existing model in hyperparameter category. Default is ‘training’. In principle every reasonable category can be created in hyperparameters.
- Returns
Fitting Error.
- Return type
-
load
(load_model: bool = False, load_scaler: bool = False)[source]¶ Load model from file that are stored in class folder.
The tensorflow.keras.model is not loaded itself but created new from hyperparameter.
- Parameters
- Raises
FileNotFoundError – If Directory not found.
- Returns
self.
-
save
(save_weights: bool = True, save_model: bool = True, save_scaler: bool = True)[source]¶ Save models, scaler and hyperparameter into class folder.
-