Encoder-Decoder Networks#

Classes#

class BaseEncoder(save_num, states_dir, net, *, overwrite=False, mix_precision=False, learning_rate=0.001, description='', verbose='epoch', classes=None, loss_func=None, transform=None, in_transform=None, optimiser_kwargs=None, scheduler_kwargs=None)[source]#

Bases: BaseArchitecture

Base encoder architecture for predicting low-dimensional data from high-dimensional inputs.

Attributes:
descriptionstr

Description of the architecture

versionstr

Version of the architecture

lossestuple[list[LossCT], list[LossCT]]

Architecture training and validation losses as a float or dictionary of losses for each loss function

transformsdict[str, list[BaseTransform] | BaseTransform | NoneType]

Keys for the output data from predict and corresponding transforms

idxs: ndarray | None

Training data indices with shape (N) and type int, where N is the number of elements in the training dataset

classesTensor | NoneType

Unique classes of shape (C) and type int/float, where C is the number of classes

optimiserOptimizer

Architecture optimiser

schedulerLRScheduler

Optimiser scheduler

netBaseNetwork

Neural network

Parameters:
save_numint | str

File number or name to save the architecture

states_dirstr

Directory to save the architecture

netModule | BaseNetwork

Network to predict low-dimensional data

overwritebool, Optional

If saving can overwrite an existing save file, if True and file with the same name exists, an error will be raised, default = False

mix_precision: bool, Optional

If mixed precision should be used, default = False

learning_ratefloat, Optional

Optimiser initial learning rate, if None, no optimiser or scheduler will be set, default = 1e-3

descriptionstr, Optional

Description of the architecture training

verbose{‘full’, ‘progress’, NoneType}

If details about epoch should be printed (‘full’), just a progress bar (‘progress’), or nothing (None)

classesTensor, Optional

Unique classes of shape (C) and type int/float, where C is the number of classes, if using class classification

loss_funcBaseLoss | NoneType, Optional

Loss function for the encoder, if None MSELoss will be used if classes is None, else CrossEntropyLoss will be used

transformBaseTransform, Optional

Transformation of the low-dimensional data

in_transformBaseTransform, Optional

Transformation for the input data

optimiser_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_optimiser

scheduler_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_scheduler

extra_repr()[source]#

Additional representation of the architecture.

Returns:
str

Architecture specific representation

get_hyperparams()[source]#

Get the hyperparameters of the encoder.

Returns:
dict[str, Any]

Hyperparameters of the encoder

to(*args, **kwargs)[source]#

See torch.nn.Module.to().

class Autoencoder(save_num, states_dir, net, *, overwrite=False, mix_precision=False, learning_rate=0.001, description='', verbose='epoch', transform=None, latent_transform=None, optimiser_kwargs=None, scheduler_kwargs=None)[source]#

Bases: BaseArchitecture

Architecture handler for autoencoder type architectures.

Attributes:
descriptionstr

Description of the architecture

lossestuple[list[LossCT], list[LossCT]]

Architecture training and validation losses as a float or dictionary of losses for each loss function

transformsdict[str, list[BaseTransform] | BaseTransform | NoneType]

Keys for the output data from predict and corresponding transforms

idxs: ndarray | None

Training data indices with shape (N) and type int, where N is the number of elements in the training dataset

optimiserOptimizer

Architecture optimiser

schedulerLRScheduler

Optimiser scheduler

netBaseNetwork

Neural network

reconstruct_funcBaseLoss

Loss function for the reconstruction loss

latent_funcBaseLoss

Loss function for the latent loss

Parameters:
save_numint | str

File number or name to save the architecture

states_dirstr

Directory to save the architecture

netModule | BaseNetwork

Network to predict low-dimensional data

overwritebool, Optional

If saving can overwrite an existing save file, if True and file with the same name exists, an error will be raised, default = False

mix_precision: bool, Optional

If mixed precision should be used, default = False

learning_ratefloat, Optional

Optimiser initial learning rate, default = 1e-3

descriptionstr, Optional

Description of the architecture training

verbose{‘full’, ‘progress’, NoneType}

If details about epoch should be printed (‘full’), just a progress bar (‘progress’), or nothing (None)

transformBaseTransform, Optional

Transformation applied to the input data

latent_transformBaseTransform, Optional

Transformation applied to the latent space

optimiser_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_optimiser

scheduler_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_scheduler

batch_predict(data, **_)[source]#

Generates predictions for the given data batch.

Parameters:
dataTensorListLike

Data to generate predictions for of shape (N, …) and type float, where N is the batch size

Returns:
tuple[NDArrayListLike | NoneType, …]

Predictions of shape (N, …) and type float for the given data

extra_repr()[source]#

Additional representation of the architecture.

Returns:
str

Architecture specific representation

get_hyperparams()[source]#

Get the hyperparameters of the autoencoder.

Returns:
dict[str, Any]

Hyperparameters of the autoencoder

class Decoder(save_num, states_dir, net, *, overwrite=False, mix_precision=False, learning_rate=0.001, description='', verbose='epoch', transform=None, in_transform=None, optimiser_kwargs=None, scheduler_kwargs=None)[source]#

Bases: BaseArchitecture

Decoder architecture for predicting high-dimensional data from low-dimensional inputs.

Attributes:
descriptionstr

Description of the architecture

lossestuple[list[LossCT], list[LossCT]]

Architecture training and validation losses as a float or dictionary of losses for each loss function

transformsdict[str, list[BaseTransform] | BaseTransform | NoneType]

Keys for the output data from predict and corresponding transforms

loss_funcBaseLoss

Loss function for the reconstructions

idxs: ndarray | None

Training data indices with shape (N) and type int, where N is the number of elements in the training dataset

optimiserOptimizer

Architecture optimiser

schedulerLRScheduler

Optimiser scheduler

netBaseNetwork

Neural network

Parameters:
save_numint | str

File number or name to save the architecture

states_dirstr

Directory to save the architecture

netModule | BaseNetwork

Network to predict low-dimensional data

overwritebool, Optional

If saving can overwrite an existing save file, if True and file with the same name exists, an error will be raised, default = False

mix_precision: bool, Optional

If mixed precision should be used, default = False

learning_ratefloat, Optional

Optimiser initial learning rate, if None, no optimiser or scheduler will be set, default = 1e-3

descriptionstr, Optional

Description of the architecture

verbose{‘epoch’, ‘full’, ‘progress’, NoneType}

If details about each epoch should be printed (‘epoch’), details about epoch and epoch progress (full), just total progress (‘progress’), or nothing (None)

transformBaseTransform, Optional

Transformation of the architecture’s output

in_transformBaseTransform, Optional

Transformation for the input data

optimiser_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_optimiser

scheduler_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_scheduler

extra_repr()[source]#

Additional representation of the architecture.

Returns:
str

Architecture specific representation

get_hyperparams()[source]#

Get the hyperparameters of the decoder.

Returns:
dict[str, Any]

Hyperparameters of the decoder

class Encoder(save_num, states_dir, net, *, overwrite=False, mix_precision=False, learning_rate=0.001, description='', verbose='epoch', classes=None, loss_func=None, transform=None, in_transform=None, optimiser_kwargs=None, scheduler_kwargs=None)[source]#

Bases: BaseEncoder

Encoder architecture for predicting low-dimensional data from high-dimensional inputs.

Attributes:
descriptionstr

Description of the architecture

lossestuple[list[LossCT], list[LossCT]]

Architecture training and validation losses as a float or dictionary of losses for each loss function

transformsdict[str, list[BaseTransform] | BaseTransform | NoneType]

Keys for the output data from predict and corresponding transforms

idxs: ndarray | None

Training data indices with shape (N) and type int, where N is the number of elements in the training dataset

classesTensor | NoneType

Unique classes of shape (C) and type int/float, where C is the number of classes

optimiserOptimizer

Architecture optimiser

schedulerLRScheduler

Optimiser scheduler

netBaseNetwork

Neural network

Parameters:
save_numint | str

File number or name to save the architecture

states_dirstr

Directory to save the architecture

netModule | BaseNetwork

Network to predict low-dimensional data

overwritebool, Optional

If saving can overwrite an existing save file, if True and file with the same name exists, an error will be raised, default = False

mix_precision: bool, Optional

If mixed precision should be used, default = False

learning_ratefloat, Optional

Optimiser initial learning rate, if None, no optimiser or scheduler will be set, default = 1e-3

descriptionstr, Optional

Description of the architecture training

verbose{‘full’, ‘progress’, NoneType}

If details about epoch should be printed (‘full’), just a progress bar (‘progress’), or nothing (None)

classesTensor, Optional

Unique classes of shape (C) and type int/float, where C is the number of classes, if using class classification

loss_funcBaseLoss | NoneType, Optional

Loss function for the encoder, if None MSELoss will be used if classes is None, else CrossEntropyLoss will be used

transformBaseTransform, Optional

Transformation of the low-dimensional data

in_transformBaseTransform, Optional

Transformation for the input data

optimiser_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_optimiser

scheduler_kwargsdict[str, Any] | NoneType, Optional

Optional keyword arguments to pass to init_scheduler

batch_predict(data, **_)[source]#

Generates predictions for the given data.

Parameters:
dataTensorListLike

Data to generate predictions for of shape (N, …) and type float, where N is the batch size

Returns:
tuple[NDArrayListLike | NoneType, …]

Predictions of shape (N,…) and type float for the given data