mechanoChemML.src.nn_models¶
Module Contents¶
Classes¶
BNN_user_weak_pde_general |
User defined general weak-pde constrained BNNs. Automatically create a sequential BNN model based on the list of layers. |
BNN_user_weak_pde_general_heter |
User defined general weak-pde constrained BNNs. Automatically create a sequential BNN model based on the list of layers. |
BNN_user_general |
User defined general BNNs. Automatically create a sequential BNN model based on the list of layers. |
NN_user_general |
User defined general NNs. Automatically create a sequential NN model based on the list of layers. |
BNN_user_weak_pde_general_dynamic |
User defined general weak-pde constrained BNNs. Automatically create a sequential BNN model based on the list of layers. |
Functions¶
_build_one_layer(layer_dict, kl_divergence_function=None) |
Return one keras layer based on the layer dictionary |
_is_digit(str0) |
Check if a string is digit or not |
_is_tuple(str0) |
Check if a string is tuple or not |
_is_list(str0) |
Check if a string is list or not |
_form_parameter_value(str0) |
Convert a string to the proper type (int, tuple, list, str) |
_form_NN_dict_from_str(str0) |
Form a list with each item being a dictionary containing the layer configuration |
merge_two_tensor(a) |
-
mechanoChemML.src.nn_models._build_one_layer(layer_dict, kl_divergence_function=None)[source]¶ Return one keras layer based on the layer dictionary
Parameters: - layer_dict (dict) – a dictionary contains configurations of a Keras layer
- kl_divergence_function – scaled kl_divergence_function (default: None)
Returns: A Keras layer
Note
The following layers are supported:
- BatchNormalization
- Conv2D
- Convolution2DFlipout
- Convolution2DReparameterization
- Dense
- DenseFlipout
- DenseReparameterization
- Flatten
- GaussianNoise
- MaxPooling2D
- PDERandom
- Reshape
- UpSampling2D
- PDEZero
-
mechanoChemML.src.nn_models._is_digit(str0)[source]¶ Check if a string is digit or not
Parameters: str0 (str) – a string Returns: True if is digit, false if not. Return type: bool
-
mechanoChemML.src.nn_models._is_tuple(str0)[source]¶ Check if a string is tuple or not
Parameters: str0 (str) – a string Returns: True if is digit, false if not. Return type: bool
-
mechanoChemML.src.nn_models._is_list(str0)[source]¶ Check if a string is list or not
Parameters: str0 (str) – a string Returns: True if is digit, false if not. Return type: bool
-
mechanoChemML.src.nn_models._form_parameter_value(str0)[source]¶ Convert a string to the proper type (int, tuple, list, str)
Parameters: str0 (str) – a string Returns: Variable with the proper type (int, tuple, list, str)
-
mechanoChemML.src.nn_models._form_NN_dict_from_str(str0)[source]¶ Form a list with each item being a dictionary containing the layer configuration
Parameters: str0 (str) – a string Returns: a list of layer dictionary Return type: list_of_layers_dict (dict) Notes
- keys of the layer dictionary: ‘type’, ‘activation’, ‘unit’, ‘padding’, etc
- the keys are different for different Keras layers.
- the keys are defined based on the argument name of each Keras layer
-
class
mechanoChemML.src.nn_models.BNN_user_weak_pde_general(layers_str, NUM_TRAIN_EXAMPLES, Sigma2=0.0001)[source]¶ Bases:
tensorflow.keras.ModelUser defined general weak-pde constrained BNNs. Automatically create a sequential BNN model based on the list of layers.
Parameters: - layers_str (str) – a string contains all info of layers defining the NNs.
- NUM_TRAIN_EXAMPLES (int) – scale factor for the kl-loss. See more explanation: https://www.tensorflow.org/probability/api_docs/python/tfp/layers/Convolution2DFlipout
- Sigma2 (float) – initial value for the variance of residual. Used in the loss.
-
call(self, inputs, training=False)[source]¶ Execute each layer: See https://www.tensorflow.org/api_docs/python/tf/keras/Model
Parameters: - inputs – a keras.Input object or list of keras.Input objects.
- training (bool) – One can use it to specify a different behavior in training and inference.
-
class
mechanoChemML.src.nn_models.BNN_user_weak_pde_general_heter(layers_str, NUM_TRAIN_EXAMPLES, Sigma2=0.0001)[source]¶ Bases:
tensorflow.keras.ModelUser defined general weak-pde constrained BNNs. Automatically create a sequential BNN model based on the list of layers.
Heterogeneous inputs with [image, scalar]
Parameters: - layers_str (str) – a string contains all info of layers defining the NNs.
- NUM_TRAIN_EXAMPLES (int) – scale factor for the kl-loss. See more explanation: https://www.tensorflow.org/probability/api_docs/python/tfp/layers/Convolution2DFlipout
- Sigma2 (float) – initial value for the variance of residual. Used in the loss.
-
call(self, inputs, training=False)[source]¶ Execute each layer: See https://www.tensorflow.org/api_docs/python/tf/keras/Model
It is almost impossible to pass a scalar out without sacrificing the data format. New function call is defined to pass such data.
Parameters: - inputs – a keras.Input object or list of keras.Input objects.
- training (bool) – One can use it to specify a different behavior in training and inference.
-
class
mechanoChemML.src.nn_models.BNN_user_general(layers_str, NUM_TRAIN_EXAMPLES)[source]¶ Bases:
tensorflow.keras.ModelUser defined general BNNs. Automatically create a sequential BNN model based on the list of layers.
Parameters: - layers_str (str) – a string contains all info of layers defining the NNs.
- NUM_TRAIN_EXAMPLES (int) – scale factor for the kl-loss. See more explanation: https://www.tensorflow.org/probability/api_docs/python/tfp/layers/Convolution2DFlipout
-
call(self, inputs, training=False)[source]¶ Execute each layer: See https://www.tensorflow.org/api_docs/python/tf/keras/Model
Parameters: - inputs – a keras.Input object or list of keras.Input objects.
- training (bool) – One can use it to specify a different behavior in training and inference.
-
class
mechanoChemML.src.nn_models.NN_user_general(layers_str)[source]¶ Bases:
tensorflow.keras.ModelUser defined general NNs. Automatically create a sequential NN model based on the list of layers.
Parameters: layers_str (str) – a string contains all info of layers defining the NNs. -
call(self, inputs, training=False)[source]¶ Execute each layer: See https://www.tensorflow.org/api_docs/python/tf/keras/Model
Parameters: - inputs – a keras.Input object or list of keras.Input objects.
- training (bool) – One can use it to specify a different behavior in training and inference.
-
-
class
mechanoChemML.src.nn_models.BNN_user_weak_pde_general_dynamic(layers_str, NUM_TRAIN_EXAMPLES, Sigma2=0.0001)[source]¶ Bases:
tensorflow.keras.ModelUser defined general weak-pde constrained BNNs. Automatically create a sequential BNN model based on the list of layers.
Parameters: - layers_str (str) – a string contains all info of layers defining the NNs.
- NUM_TRAIN_EXAMPLES (int) – scale factor for the kl-loss. See more explanation: https://www.tensorflow.org/probability/api_docs/python/tfp/layers/Convolution2DFlipout
- Sigma2 (float) – initial value for the variance of residual. Used in the loss.
-
call(self, inputs, training=False)[source]¶ Execute each layer: See https://www.tensorflow.org/api_docs/python/tf/keras/Model
Parameters: - inputs – a keras.Input object or list of keras.Input objects.
- training (bool) – One can use it to specify a different behavior in training and inference.
-
mechanoChemML.src.nn_models.example_NN= type=PDERandom; type=Conv2D | filters=8 | kernel_size=5 | activation=relu | padding=same; type=MaxPooling2D | pool_size=(2,2) | padding=same; type=Conv2D | filters=16 | kernel_size=5 | activation=relu | padding=same; type=MaxPooling2D | pool_size=(2,2) | padding=same; type=Flatten; type=Dense | units=64 | activation=relu; type=Dense | units=32 | activation=relu; type=Reshape | target_shape=[4,4,2]; type=Conv2D | filters=8 | kernel_size=5 | activation=relu | padding=same; type=UpSampling2D | size=(2,2); type=Conv2D | filters=8 | kernel_size=5 | activation=relu | padding=same; type=Conv2D | filters=1 | kernel_size=5 | activation=relu | padding=same;[source]¶