diff --git a/deepof/hypermodels.py b/deepof/hypermodels.py index 5904092ebd45bd5026feb27440dbaac10dc1b75d..4962642f879cab09aa9c942ba255cd95da6fb323 100644 --- a/deepof/hypermodels.py +++ b/deepof/hypermodels.py @@ -92,7 +92,7 @@ class SEQ_2_SEQ_AE(HyperModel): ENCODING, activation="relu", kernel_constraint=UnitNorm(axis=1), - activity_regularizer=UncorrelatedFeaturesConstraint(3, weightage=1.0), + activity_regularizer=uncorrelated_features_constraint(3, weightage=1.0), kernel_initializer=Orthogonal(), ) @@ -340,7 +340,7 @@ class SEQ_2_SEQ_GMVAE(HyperModel): for k in range(self.number_of_components) ], ), - activity_regularizer=UncorrelatedFeaturesConstraint(3, weightage=1.0), + activity_regularizer=uncorrelated_features_constraint(3, weightage=1.0), )([z_cat, z_gauss]) if "ELBO" in self.loss: diff --git a/deepof/model_utils.py b/deepof/model_utils.py index a2778d758de7d2424eace5ca7b7736abfd9d7142..60a263185240d0baecdbc07efb96d7ecee97f1a9 100644 --- a/deepof/model_utils.py +++ b/deepof/model_utils.py @@ -172,7 +172,14 @@ class one_cycle_scheduler(tf.keras.callbacks.Callback): K.set_value(self.model.optimizer.lr, rate) -class UncorrelatedFeaturesConstraint(Constraint): +class uncorrelated_features_constraint(Constraint): + """ + + Tensorflow Constraint subclass that forces a layer to have uncorrelated features. + Useful, among others, for auto encoder bottleneck layers + + """ + def __init__(self, encoding_dim, weightage=1.0): self.encoding_dim = encoding_dim self.weightage = weightage diff --git a/deepof/models.py b/deepof/models.py index e07069e1c54fb1fb9018aa7f96c909d89a1c8c16..6ac1cc6efc2e15c4e0e540492fe6cd8a1b2b98f8 100644 --- a/deepof/models.py +++ b/deepof/models.py @@ -92,7 +92,7 @@ class SEQ_2_SEQ_AE: self.ENCODING, activation="elu", kernel_constraint=UnitNorm(axis=1), - activity_regularizer=UncorrelatedFeaturesConstraint(2, weightage=1.0), + activity_regularizer=uncorrelated_features_constraint(2, weightage=1.0), kernel_initializer=Orthogonal(), )