Autoencoder

Model

class ParticleAutoencoder(*args, **kwargs)[source]

Bases: Model

Autoencoder model for dimensionality reduction.

input_shape[source]

shape of input, default (100,3)

Type:

tuple, optional

latent_dim[source]

size of the latent dimension, default 6

Type:

int, optional

x_mean_stdev[source]

mean and standard deviation of inputs, default (0,1)

Type:

tuple, optional

kernel_n[source]

number of kernels, default 16

Type:

int, optional

kernel_sz[source]

kernel size, default 3

Type:

int, optional

activation[source]

activation function, default “elu”

Type:

string, optional

activation_latent[source]

activation before bottleneck, default :class:tensorflow.keras.activations.linear`

Type:

tensorflow.keras.activations, optional

build_encoder(mean, stdev)[source]

Builds encoder model

Parameters:
  • mean (float) – Mean of data.

  • stdev (float) – Standard deviation of data.

Returns:

encoder

Return type:

tensorflow.keras.Model

build_decoder(mean, stdev)[source]

Builds decoder model

Parameters:
  • mean (float) – Mean of data.

  • stdev (float) – Standard deviation of data.

Returns:

decoder

Return type:

tensorflow.keras.Model

classmethod load(path)[source]

Loads autoencoder.

Parameters:

path (str) – Model path.

Returns:

autoencoder

Return type:

tensorflow.keras.Model

compile(optimizer, reco_loss)[source]

Compiles the autoencoder - set model’s configuration.

Parameters:
  • optimizer (tensorflow.keras.Optimizer) – optimizer.

  • reco_loss (Callable) – reconstruction loss function

call(x)[source]

Calls the model.

Parameters:

x (numpy.ndarray) – inputs

Returns:

outputs

Return type:

numpy.ndarray

train_step(x)[source]

Training step.

Parameters:

x (numpy.ndarray) – inputs

Returns:

loss dictionary

Return type:

dict

test_step(x)[source]

Inference step.

Parameters:

x (numpy.ndarray) – inputs

Returns:

loss dictionary

Return type:

dict

Layers

class Conv1DTranspose(*args, **kwargs)[source]

Bases: Layer

Custom 1d transposed convolution that expands to 2d output for vae decoder

activation[source]

activation

Type:

tensorflow.keras.activation

ConvTranspose[source]

sublayer

Type:

tensorflow.keras.Layer

ExpandChannel[source]

sublayer

Type:

tensorflow.keras.Lambda

filters[source]

number kernels

Type:

int

kernel_initializer[source]

kernel init

Type:

tensorflow.keras.Initializer

kernel_sz[source]

kernel size

Type:

int

SqueezeChannel[source]

sublayer

Type:

tensorflow.keras.Layer

__init__(filters, kernel_sz, activation, kernel_initializer, **kwargs)[source]

Construtor.

Parameters:
  • filters (int) – number kernels

  • activation (tensorflow.keras.activation) – activation

  • kernel_initializer (tensorflow.keras.Initializer) – kernel init

  • kernel_sz (int) – kernel size

call(inputs)[source]

Call.

Parameters:

inputs (tensorflow.Tensor) – call

Returns:

outputs

Return type:

tensorflow.Tensor

get_config()[source]

Get configuration of layer.

Returns:

dictionary containing configuration used to initialize this layer

Return type:

dict

class StdNormalization(*args, **kwargs)[source]

Bases: Layer

Normalizing input feature to std Gauss (mean 0, var 1).

mean_x[source]

mean of inputs

Type:

float

std_x[source]

standard deviation of inputs

Type:

float

__init__(mean_x, std_x, name='Std_Normalize', **kwargs)[source]

Constructor.

Parameters:
  • mean_x (float) – mean of inputs

  • std_x (float) – standard deviation of inputs

  • name (str, optional) – name

get_config()[source]

Get configuration for layer.

Returns:

dictionary containing configuration used to initialize this layer

Return type:

dict

call(x)[source]

Call.

Parameters:

inputs (tensorflow.Tensor) – call

Returns:

outputs

Return type:

tensorflow.Tensor

class StdUnnormalization(*args, **kwargs)[source]

Bases: StdNormalization

Rescaling feature to original domain

__init__(mean_x, std_x, name='Un_Normalize', **kwargs)[source]

Constructor.

Parameters:
  • mean_x (float) – mean of inputs

  • std_x (float) – standard deviation of inputs

  • name (str, optional) – name

call(x)[source]

Call.

Parameters:

inputs (tensorflow.Tensor) – call

Returns:

outputs

Return type:

tensorflow.Tensor

Train

train(data_sample, input_shape=(100, 3), read_n=10000, batch_size=256, latent_dim=6, epochs=10, act_latent=None)[source]

Trains autoencoder

Parameters:
  • data_sample (numpy.ndarray) – inputs

  • input_shape (tuple, optional) – shape, default (100, 3)

  • batch_size (int, optional) – batch size, default 256

  • latent_dim (int, optional) – latent dim, default 6

  • epochs (int, optional) – number of epochs, default 10

  • act_latent (tensorflow.keras.Actication, optional) – latent activation, default None

Predict

map_to_latent_space(data_sample, model) ndarray[source]

Autoencoder mapping input space to latent representation.

Parameters:
  • data_sample (tensorflow.data.Dataset) – tensorflow.data.Dataset.from_tensor_slices(input_sample (:class:`numpy.ndarray)).batch(batch_size)`

  • model (tensorflow.keras.Model) – the autoencoder

Returns:

latent representation

Return type:

numpy.ndarray