This module provides the DataBatcher class, which handles the logic for
organizing data indices into batches.
DataBatcher class, which handles the logic for organizing data indices
into batches. It does not handle the physical data directly, but rather
the indices pointing to that data.
It supports:
1. Naive batching: Grouping indices purely by count.
2. Grouped batching: Grouping indices based on species or types (e.g.,
creating batches that only contain specific chemical elements).
3. Splitting: Dividing datasets into training, testing, and validation sets.
4. Shuffling: Reproducible randomization using dedicated random number
generators.
Nodes of different colours represent the following:
Solid arrows point from a submodule to the (sub)module which it is
descended from. Dashed arrows point from a module or program unit to
modules which it uses.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a submodule to the (sub)module which it is
descended from. Dashed arrows point from a module or program unit to
modules which it uses.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a derived type to the parent type which it
extends. Dashed arrows point from a derived type to the other
types it contains as a components, with a label listing the name(s) of
said component(s).
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a derived type to the parent type which it
extends. Dashed arrows point from a derived type to the other
types it contains as a components, with a label listing the name(s) of
said component(s).
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
This routine performs "naive" batching. It takes a 1D list of indices
and separates them into smaller batches based solely on the batchsize.
It does not discriminate based on the content of the indices (e.g.,
atom types).
Use this when every sample is structurally equivalent (e.g., batching
whole atomic structures).
sample_indices :
integer (dim: (:)) [in]– The indices that will be batched.
batchsize :
integer [in]– The maximum number of samples in one batch.
fraction :
real(DP) [in]– The fraction of the input samples to use. If provided, only this
percentage of indices will be batched.
shuffle :
logical [in]– Whether to shuffle the indices before batching. Helpful when using
`fraction` to get a random subset.
If `shuffle` is false and `fraction` is given, the first samples
in `sample_indices` are batched.
num_batches :
integer [out]– The total number of batches created.
num_samples_per_batch :
integer (dim: (:)) [out]– The number of samples in each specific batch (size: num_batches).
batch_indices :
integer (dim: (:,:)) [out]– The actual indices assigned to each batch.
Dimensions: batchsize x num_batches
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Create grouped batches from a given list of input samples.
This routine is an extension of batch_naive that respects group
identities (e.g., atomic numbers).
Unlike naive batching, where any two samples can end up in the same
batch, this routine ensures that a batch only contains samples belonging
to the same group.
sample_indices :
integer (dim: (:)) [in]– The primary indices to be batched.
batchsize :
integer (dim: (:)) [in]– An array of batch sizes. The index of this array corresponds to the
group ID.
Example: If batching atoms with atomic numbers 1 (H) and 8 (O),
`batchsize` must be at least size 8.
`batchsize(1)` sets the size for H batches, `batchsize(8)` for O
batches.
fractions :
real(DP) (dim: (:)) [in]– Percentage of samples to use per group. Follows the same
indexing rules as `batchsize`.
groups :
integer (dim: (size(sample_indices))) [in]– An array determining the group ID for each entry in `sample_indices`.
fraction_groups :
integer (dim: (size(sample_indices))) [in]– Determines which group a sample belongs to when we apply the `fraction`.\
This is helpful if we want to select subset of samples based on their
group, but still want to batch all of them together in group-agnostic
batches. In this case `groups` may be set to the same value for all
samples.
Must only be given when `fractions` are given.
In most cases, this is chosen to be the same as `groups`.
shuffle :
logical [in]– Whether to shuffle indices before batching.
num_batches :
integer [out]– Total number of batches created.
num_samples_per_batch :
integer (dim: (:)) [out]– Number of samples in each batch.
batch_indices :
integer (dim: (:,:)) [out]– The indices assigned to each batch.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Split a list of indices into an arbitrary number of parts.
This is typically used to create training, testing, and validation
sets from a global list of indices.
The upper limit for the size of each part is estimated based on
fractions. If the sum of these limits exceeds the total number of
samples due to rounding, the final part is shrunk to fit.
This ensures all samples are accounted for, though the final fraction
might deviate slightly for very small datasets.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.