toolbox module

DIRESA helper functions

Author:

Geert De Paepe

Email:

geert.de.paepe@vub.be

License:

MIT License

toolbox.cut_sub_model(model, sub_model_name)

Cuts a sub-model out of a keras model Limitations: does not work for a sub-model of a sub-model

Parameters:
  • model – keras model

  • sub_model_name – name of the sub-model

Returns:

submodel

toolbox.latent_component_r2_scores(dataset, latent, decoder, cumulated=False)

Calculate R2 score of latent components

Parameters:
  • dataset – dataset

  • latent – latent (encoded) dataset

  • decoder – decoder model

  • cumulated – if True, cumulated R2 score is calculated (assumes that latent components are ordered!)

Returns:

list with R2 scores of latent components

toolbox.encoder_decoder(model, dataset=None, encoder_name='Encoder', decoder_name='Recon', verbose=True)

Returns encoder and decoder out of DIRESA model If dataset is not None: adds ordering layers after encoder and before decoder

Parameters:
  • model – keras model

  • dataset – dataset

  • encoder_name – name of the encoder

  • decoder_name – name of the decoder

  • verbose – if True, prints R2 score

Returns:

encoder and decoder model

toolbox.decoded_latent_components(latent, decode, factor=0.5)
Parameters:
  • latent – latent dataset

  • decode – decoder model

  • factor – factor to multiply with standard deviation

Returns:

decoded latent components

toolbox.set_encoder_trainable(model, trainable=True, encoder_name='Encoder')

Set trainable attribute of encoder

Parameters:
  • model – keras DIRESA/AE model

  • trainable – True or False

  • encoder_name – name of the encoder