mod_hdnn¶
Implementation of a general high-dimensional neural network. author: Alexander Knoll
Dependencies¶
Module Variables¶
-
GENERIC_KEYWORDS_HDNN: character (dim: (*))
Derived Types Summary¶
| Name | Description |
|---|---|
HDNN |
A general feed-forward neural network with an arbitrary number of input nodes, hidden layers,... |
Procedures Summary¶
| Name | Type | Description |
|---|---|---|
constructor_hdnn |
Function | |
get_element_index |
Function | |
get_num_parameters_hdnn |
Function | |
get_max_num_hidden_layers |
Function | |
get_num_forward_passes_hdnn |
Function | |
get_num_backward_passes_hdnn |
Function | |
initialize_hdnn |
Subroutine | |
set_optimizer_hdnn |
Subroutine | Set the optimizer_idx on this HDNN. Must be called after initialization. Checks for lines... |
initialize_from_file_hdnn |
Subroutine | Initialize a HDNN object mod_hdnn:HDNN with the lines... |
initialize_from_architecture |
Subroutine | |
initialize_from_nns |
Subroutine | |
reallocate_hdnn |
Subroutine | |
reset_hdnn |
Subroutine | Reset all atomic neural networks in this HDNN. |
reset_prediction_hdnn |
Subroutine | Reset the internal arrays that store the gradient information. This should be called before... |
print_hdnn |
Subroutine | Display information about the object and its members. |
forward_hdnn |
Subroutine | Calculate the output of all atomic NNs for self%input. |
pad |
Subroutine | |
forward_gradient_hdnn |
Subroutine | Calculate the output of all atomic NNs for self%input. |
backward_hdnn |
Subroutine | Perform a backward pass through all atomic NNs individually. |
backward_gradient_hdnn |
Subroutine | Perform a backward pass through all atomic NNs individually. |
calc_jacobian_hdnn |
Subroutine | |
get_parameters_hdnn |
Subroutine | Cast all free parameters of the model in one array of shape (1 x num_parameters). |
set_parameters_hdnn |
Subroutine | Set the free parameters of self based on the flat array parameters. |
get_gradients_wrt_parameters_hdnn |
Subroutine | Cast the gradients of the output with respect to all free parameters into one flat array. |
read_parameters_from_file_hdnn |
Subroutine | Delegate parameter reading to the individual atomic NNs. |
write_parameters_to_file_hdnn |
Subroutine | Delegate parameter writing to the individual atomic NNs. |
precondition_parameters_hdnn |
Subroutine | |
initialize_parameters_hdnn |
Subroutine | |
get_opt_ids_and_targets_hdnn |
Subroutine | Returns the atomic numbers composing the model in the targets array and the indices of their... |
Derived Types Details¶
type HDNN¶
A general feed-forward neural network with an arbitrary number of input nodes, hidden layers, and output nodes.
Components
-
keyword_suffix: character– Inherited from AbstractPropertyModel -
num_output_properties: integer– How many properties this model predicts. – Inherited from AbstractPropertyModel -
max_num_features: integer– Inherited from AbstractPropertyModel -
name: character– Inherited from AbstractPropertyModel -
parameter_file_prefix: character– Prefix of the file from which parameters will be read/written. – Inherited from AbstractPropertyModel -
file_path: character– Path to the directory where parameters are stored and output files will be written. – Inherited from AbstractPropertyModel -
num_parameters: integer– Inherited from AbstractPropertyModel -
num_parameters_mask: integer– The total number of free parameters in the model. This should always be set by the `constructor` procedure of the derived type. – Inherited from AbstractPropertyModel -
batchsize: integer– Inherited from AbstractPropertyModel -
num_forward_passes: integer– Inherited from AbstractPropertyModel -
num_backward_passes: integer– Inherited from AbstractPropertyModel -
optimizer_idx: integer– Inherited from AbstractPropertyModel -
featcalc_index: integer– Inherited from AbstractPropertyModel -
comm_idx: integer– To which committee member this model belongs. – Inherited from AbstractPropertyModel -
output: real(DP) (dim: (:,:))– The output of the model. Dimension (batchsize x num_output_values) – Inherited from AbstractPropertyModel -
jacobian: real(DP) (dim: (:,:,:))– The gradients of the output property with respect to input features. Dimension (max_num_features x batchsize x num_output_values). – Inherited from AbstractPropertyModel -
mask: logical (dim: (:))– A logical array specifying, for each free parameter, whether it should be optimized or not. – Inherited from AbstractPropertyModel -
initialization_method: character– Inherited from AbstractPropertyModel -
lset_initialization_method: logical– Inherited from AbstractPropertyModel -
precondition_method: character– Inherited from AbstractPropertyModel -
lset_precondition_method: logical– Inherited from AbstractPropertyModel -
parameter_min: real(DP)– Inherited from AbstractPropertyModel -
parameter_max: real(DP)– Inherited from AbstractPropertyModel -
lparameter_min: logical– Inherited from AbstractPropertyModel -
lparameter_max: logical– Inherited from AbstractPropertyModel -
atomic_nns: type(NeuralNetwork) (dim: (:))– A list of all atomic neural networks in this `NeuralNetwork`. -
atomic_numbers: integer (dim: (:))
Type-Bound Procedures
| Name | Attributes | Binding |
|---|---|---|
| initialize_parent | public | ⇒ initialize_abstract_property_model |
| initialize_from_file_parent | public | ⇒ initialize_from_file_abstract_property_model |
| reset_results | public | ⇒ reset_results |
| reallocate | public | ⇒ reallocate_hdnn |
| reset | public | ⇒ reset_hdnn |
| reset_prediction | public | ⇒ reset_prediction_hdnn |
| public | ⇒ print_hdnn | |
| get_num_parameters | public | ⇒ get_num_parameters_hdnn |
| get_parameters | public | ⇒ get_parameters_hdnn |
| set_parameters | public | ⇒ set_parameters_hdnn |
| get_gradients_wrt_parameters | public | ⇒ get_gradients_wrt_parameters_hdnn |
| get_opt_ids_and_targets | public | ⇒ get_opt_ids_and_targets_hdnn |
| read_parameters_from_file | public | ⇒ read_parameters_from_file_hdnn |
| write_parameters_to_file | public | ⇒ write_parameters_to_file_hdnn |
| initialize_from_file | public | ⇒ initialize_from_file_hdnn |
| initialize | public | ⇒ initialize_hdnn |
| forward | public | ⇒ forward_hdnn |
| backward | public | ⇒ backward_hdnn |
| forward_gradient | public | ⇒ forward_gradient_hdnn |
| backward_gradient | public | ⇒ backward_gradient_hdnn |
| calc_jacobian | public | ⇒ calc_jacobian_hdnn |
| set_optimizer | public | ⇒ set_optimizer_hdnn |
| get_num_forward_passes | public | ⇒ get_num_forward_passes_hdnn |
| get_num_backward_passes | public | ⇒ get_num_backward_passes_hdnn |
| precondition_parameters | public | ⇒ precondition_parameters_hdnn |
| initialize_parameters | public | ⇒ initialize_parameters_hdnn |
| initialize_from_architecture | private | ⇒ initialize_from_architecture |
| initialize_from_nns | private | ⇒ initialize_from_nns |
Inherits
Interface Details¶
interface HDNN¶
Procedure Details¶
function constructor_hdnn¶
function constructor_hdnn( &
name, &
keyword_suffix, &
parameter_file_prefix, &
comm_idx &
)
Arguments
-
name: character [in] -
keyword_suffix: character [in] -
parameter_file_prefix: character [in] -
comm_idx: integer [in]
Called By
function get_element_index¶
function get_element_index( &
arr, &
elem &
)
Arguments
-
arr: integer (dim: (:)) [in] -
elem: integer [in]
Called By
function get_num_parameters_hdnn¶
function get_num_parameters_hdnn( &
self, &
luse_mask, &
optimizer_idx, &
atomic_numbers &
)
Arguments
-
self: class(HDNN) [in] -
luse_mask: logical [in] -
optimizer_idx: integer [in] -
atomic_numbers: integer (dim: (:)) [in]
function get_max_num_hidden_layers¶
function get_max_num_hidden_layers( &
lines &
)
Arguments
- : character (dim: (:)) [in]– Individual lines from input.nn
Called By
function get_num_forward_passes_hdnn¶
function get_num_forward_passes_hdnn( &
self, &
optimizer_idx, &
atomic_numbers &
)
Arguments
-
self: class(HDNN) [in] -
optimizer_idx: integer [in] -
atomic_numbers: integer (dim: (:)) [in]
function get_num_backward_passes_hdnn¶
function get_num_backward_passes_hdnn( &
self, &
optimizer_idx, &
atomic_numbers &
)
Arguments
-
self: class(HDNN) [in] -
optimizer_idx: integer [in] -
atomic_numbers: integer (dim: (:)) [in]
subroutine initialize_hdnn¶
subroutine initialize_hdnn( &
self, &
file_path, &
initialization_method, &
precondition_method, &
parameter_min, &
parameter_max &
)
Arguments
-
self: class(HDNN) [inout] -
file_path: character [in] -
initialization_method: character [in] -
precondition_method: character [in] -
parameter_min: real(DP) [in] -
parameter_max: real(DP) [in]
Called By
subroutine set_optimizer_hdnn¶
subroutine set_optimizer_hdnn( &
self, &
lines, &
num_parameters_per_optimizer &
)
Set the optimizer_idx on this HDNN. Must be called after initialization.
Checks for lines with the patterns like opt_short 1 or opt_short H 2.
The index is the one of the optimizer in the optimizers array. This is
set in the input file by specfying the index after the optimizer keyword.
In case default_optimizers is used, the index of the default optimizer
is 1.
Arguments
-
self: class(HDNN) [inout] -
lines: character (dim: (:)) [in] -
num_parameters_per_optimizer: integer (dim: (:)) [inout]
subroutine initialize_from_file_hdnn¶
subroutine initialize_from_file_hdnn( &
self, &
file_path, &
lines, &
atomic_numbers, &
num_input_features_per_element, &
num_output_properties, &
batchsize_per_element, &
lsaturation_check &
)
Initialize a HDNN object mod_hdnn:HDNN with the lines read from a
configuration file.
Arguments
-
self: class(HDNN) [inout] -
file_path: character [in]– Path to the folder where the weights files are stored. -
lines: character (dim: (:)) [in]– Individual lines from input.nn -
atomic_numbers: integer (dim: (:)) [in]– The atomic numbers for which atomic NNs are constructed. -
num_input_features_per_element: integer (dim: (:)) [in] -
num_output_properties: integer [in] -
batchsize_per_element: integer (dim: (:)) [in] -
lsaturation_check: logical [in]
subroutine initialize_from_architecture¶
subroutine initialize_from_architecture( &
self, &
file_path, &
atomic_numbers, &
num_input_nodes_per_element, &
input_node_activations_per_element, &
num_hidden_layers_per_element, &
num_hidden_nodes_per_element, &
hidden_layer_activations_per_element, &
num_output_nodes, &
output_node_activations_per_element, &
num_fixed_weights_per_element, &
fixed_weights_per_element, &
num_fixed_biases_per_element, &
fixed_biases_per_element, &
batchsize_atomic_nns, &
lsaturation_check &
)
Arguments
-
self: class(HDNN) [inout] -
file_path: character [in] -
atomic_numbers: integer (dim: (:)) [in] -
num_input_nodes_per_element: integer (dim: (:)) [in] -
input_node_activations_per_element: character (dim: (:,:)) [in] - : integer (dim: (:)) [in]
- : integer (dim: (:,:)) [in]
- : character (dim: (:,:)) [in]
-
num_output_nodes: integer [in] -
output_node_activations_per_element: character (dim: (:,:)) [in] -
num_fixed_weights_per_element: integer (dim: (:)) [in] -
fixed_weights_per_element: integer (dim: (:,:,:)) [in] -
num_fixed_biases_per_element: integer (dim: (:)) [in] -
fixed_biases_per_element: integer (dim: (:,:,:)) [in] -
batchsize_atomic_nns: integer (dim: (:)) [in] -
lsaturation_check: logical [in]
Called By
subroutine initialize_from_nns¶
subroutine initialize_from_nns( &
self, &
file_path, &
atomic_numbers, &
nns, &
num_output_properties &
)
Arguments
-
self: class(HDNN) [inout] -
file_path: character [in] -
atomic_numbers: integer (dim: (:)) [in] -
nns: type(NeuralNetwork) (dim: (size(atomic_numbers))) [in] -
num_output_properties: integer [in]
Called By
subroutine reallocate_hdnn¶
subroutine reallocate_hdnn( &
self, &
batchsize &
)
Arguments
-
self: class(HDNN) [inout] -
batchsize: integer (dim: (MAX_ELEM_NUM)) [in]
subroutine reset_hdnn¶
subroutine reset_hdnn( &
self &
)
Reset all atomic neural networks in this HDNN.
Arguments
-
self: class(HDNN) [inout]
subroutine reset_prediction_hdnn¶
subroutine reset_prediction_hdnn( &
self &
)
Reset the internal arrays that store the gradient information. This should be called before every forward pass.
Arguments
-
self: class(HDNN) [inout]
Called By
subroutine print_hdnn¶
subroutine print_hdnn( &
self &
)
Display information about the object and its members.
Arguments
-
self: class(HDNN) [in]
subroutine forward_hdnn¶
subroutine forward_hdnn( &
self, &
features, &
atomic_numbers, &
num_features &
)
Calculate the output of all atomic NNs for self%input.
Arguments
-
self: class(HDNN) [inout] -
features: real(DP) (dim: (:,:)) [in]– Dimension (max_num_features x batchsize) -
atomic_numbers: integer (dim: (:)) [in]– The atomic number for each entry in the batch. -
num_features: integer (dim: (MAX_ELEM_NUM)) [in]– The number of features for each entry in the batch.
subroutine pad¶
subroutine pad( &
arr, &
target_size, &
arr_padded &
)
Arguments
-
arr: real(DP) (dim: (:,:)) [in] -
target_size: integer [in] -
arr_padded: real(DP) (dim: (:,:)) [out]
Called By
subroutine forward_gradient_hdnn¶
subroutine forward_gradient_hdnn( &
self, &
features, &
feature_gradients, &
atomic_numbers, &
num_features &
)
Calculate the output of all atomic NNs for self%input.
Arguments
-
self: class(HDNN) [inout] -
features: real(DP) (dim: (:,:)) [in] -
feature_gradients: real(DP) (dim: (:,:)) [in] -
atomic_numbers: integer (dim: (:)) [in]– The atomic number for each entry in the batch. -
num_features: integer (dim: (MAX_ELEM_NUM)) [in]– The number of features for each entry in the batch.
subroutine backward_hdnn¶
subroutine backward_hdnn( &
self, &
atomic_numbers, &
loss_gradients &
)
Perform a backward pass through all atomic NNs individually.
Arguments
-
self: class(HDNN) [inout] -
atomic_numbers: integer (dim: (:)) [in] -
loss_gradients: real(DP) (dim: (:,:)) [in]– Loss gradient information.
subroutine backward_gradient_hdnn¶
subroutine backward_gradient_hdnn( &
self, &
atomic_numbers, &
loss_gradients &
)
Perform a backward pass through all atomic NNs individually.
Arguments
-
self: class(HDNN) [inout] -
atomic_numbers: integer (dim: (:)) [in] -
loss_gradients: real(DP) (dim: (:,:)) [in]– Loss gradient information.
subroutine calc_jacobian_hdnn¶
subroutine calc_jacobian_hdnn( &
self, &
atomic_numbers &
)
Arguments
-
self: class(HDNN) [inout] -
atomic_numbers: integer (dim: (:)) [in]
subroutine get_parameters_hdnn¶
subroutine get_parameters_hdnn( &
self, &
parameters, &
luse_mask, &
optimizer_idx &
)
Cast all free parameters of the model in one array of shape
(1 x num_parameters).
Arguments
-
self: class(HDNN) [in] -
parameters: real(DP) (dim: (:)) [inout]– Empty array to which free parameters will be cast. -
luse_mask: logical [in]– Only retrieve those parameters for which `self%mask` is `.true.`. -
optimizer_idx: integer [in]– Only retrieve parameters for those parts of the model which are updated by the optimizer with this index.
subroutine set_parameters_hdnn¶
subroutine set_parameters_hdnn( &
self, &
parameters, &
luse_mask, &
optimizer_idx &
)
Set the free parameters of self based on the flat array
parameters.
Arguments
-
self: class(HDNN) [inout] -
parameters: real(DP) (dim: (:)) [in]– Parameters which will be set on `self`. -
luse_mask: logical [in]– Only set those parameters for which `self%mask` is `.true.`. -
optimizer_idx: integer [in]– Only set parameters for those parts of the model which are updated by the optimizer with this index.
subroutine get_gradients_wrt_parameters_hdnn¶
subroutine get_gradients_wrt_parameters_hdnn( &
self, &
gradients, &
luse_mask, &
optimizer_idx &
)
Cast the gradients of the output with respect to all free parameters into one flat array.
Arguments
-
self: class(HDNN) [inout]– The instance of `Model` or any derived type for which the gradients will be determined. -
gradients: real(DP) (dim: (:)) [inout]– The list of gradients, one for each free parameter in `self`. -
luse_mask: logical [in]– Only retrieve the gradients for those parameters for which `self%mask` is `.true.`. -
optimizer_idx: integer [in]– Only retrieve the gradients for those parts of the model which are updated by the optimizer with this index.
subroutine read_parameters_from_file_hdnn¶
subroutine read_parameters_from_file_hdnn( &
self, &
iteration, &
prefix, &
idx, &
suffix &
)
Delegate parameter reading to the individual atomic NNs.
Arguments
-
self: class(HDNN) [inout] -
iteration: integer [in] -
prefix: character [in] -
idx: integer [in] -
suffix: character [in]
Called By
subroutine write_parameters_to_file_hdnn¶
subroutine write_parameters_to_file_hdnn( &
self, &
iteration, &
prefix, &
idx, &
suffix &
)
Delegate parameter writing to the individual atomic NNs.
Arguments
-
self: class(HDNN) [in] -
iteration: integer [in] -
prefix: character [in] -
idx: integer [in] -
suffix: character [in]
subroutine precondition_parameters_hdnn¶
subroutine precondition_parameters_hdnn( &
self, &
target_mean, &
prediction_mean, &
target_std, &
prediction_std &
)
Arguments
-
self: class(HDNN) [inout] -
target_mean: real(DP) (dim: (:)) [in] -
prediction_mean: real(DP) (dim: (:)) [in] -
target_std: real(DP) (dim: (:)) [in] -
prediction_std: real(DP) (dim: (:)) [in]
subroutine initialize_parameters_hdnn¶
subroutine initialize_parameters_hdnn( &
self, &
target_mean, &
target_range, &
target_std, &
eckhoff_avg_atomic_energy, &
rng &
)
Arguments
-
self: class(HDNN) [inout] -
target_mean: real(DP) (dim: (:)) [in] -
target_range: real(DP) (dim: (:)) [in] -
target_std: real(DP) (dim: (:)) [in] -
eckhoff_avg_atomic_energy: real(DP) (dim: (:)) [in] -
rng: type(RandomNumberGenerator) [inout]
subroutine get_opt_ids_and_targets_hdnn¶
subroutine get_opt_ids_and_targets_hdnn( &
self, &
opt_ids, &
targets &
)
Returns the atomic numbers composing the model in the targets array
and the indices of their optimizers in the opt_ids array.
Arguments
-
self: class(HDNN) [in] -
opt_ids: integer (dim: (:)) [out] -
targets: integer (dim: (:)) [out]