Commit c2e74b1a authored by lucas_miranda's avatar lucas_miranda
Browse files

Added tests for model_utils.py and models.py

parent cae7ee68
......@@ -9,7 +9,7 @@ test:
- pip install -r ./deepof/requirements.txt
- pip install -e deepof/
- coverage run --source deepof -m pytest
- coverage report -m --include deepof/utils.py,deepof/preprocess.py,deepof/model_utils.py,deepof/visuals.py
- coverage report -m --include deepof/utils.py,deepof/preprocess.py,deepof/model_utils.py,deepof/visuals.py,deepof/models.py
- coverage xml -o deepof_cov.xml
artifacts:
reports:
......
......@@ -351,7 +351,7 @@ class MMDiscrepancyLayer(Layer):
return z
class Gaussian_mixture_overlap(Layer): # pragma: no cover
class Gaussian_mixture_overlap(Layer):
"""
Identity layer that measures the overlap between the components of the latent Gaussian Mixture
using a specified metric (MMD, Wasserstein, Fischer-Rao)
......@@ -381,7 +381,7 @@ class Gaussian_mixture_overlap(Layer): # pragma: no cover
dists = []
for k in range(self.n_components):
locs = (target[..., : self.lat_dims, k],)
scales = tf.keras.activations.softplus(target[..., self.lat_dims:, k])
scales = tf.keras.activations.softplus(target[..., self.lat_dims :, k])
dists.append(
tfd.BatchReshape(tfd.MultivariateNormalDiag(locs, scales), [-1])
......
# @author lucasmiranda42
# encoding: utf-8
# module deepof
"""
Testing module for deepof.models
"""
from hypothesis import given
from hypothesis import settings
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
import deepof.models
import deepof.model_utils
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
from tensorflow.python.framework.ops import EagerTensor
@settings(deadline=None)
@given(
input_shape=st.tuples(
st.integers(min_value=100, max_value=1000),
st.integers(min_value=5, max_value=15),
st.integers(min_value=5, max_value=15),
)
)
def test_SEQ_2_SEQ_AE_build(input_shape):
deepof.models.SEQ_2_SEQ_AE(input_shape=input_shape)
@settings(deadline=None)
@given(
input_shape=st.tuples(
st.integers(min_value=100, max_value=1000),
st.integers(min_value=5, max_value=15),
st.integers(min_value=5, max_value=15),
),
loss=st.one_of(st.just("ELBO"), st.just("MMD"), st.just("ELBO+MMD")),
kl_warmup_epochs=st.integers(min_value=0, max_value=5),
mmd_warmup_epochs=st.integers(min_value=0, max_value=5),
number_of_components=st.integers(min_value=1, max_value=5),
predictor=st.booleans(),
overlap_loss=st.booleans(),
entropy_reg_weight=st.floats(min_value=0.0, max_value=1.0),
)
def test_SEQ_2_SEQ_GMVAE_build(
input_shape,
loss,
kl_warmup_epochs,
mmd_warmup_epochs,
number_of_components,
predictor,
overlap_loss,
entropy_reg_weight,
):
deepof.models.SEQ_2_SEQ_GMVAE(
input_shape=input_shape,
loss=loss,
kl_warmup_epochs=kl_warmup_epochs,
mmd_warmup_epochs=mmd_warmup_epochs,
number_of_components=number_of_components,
predictor=predictor,
overlap_loss=overlap_loss,
entropy_reg_weight=entropy_reg_weight,
)
......@@ -230,5 +230,17 @@ def test_dead_neuron_control():
assert type(fit) == tf.python.keras.callbacks.History
# def test_entropy_regulariser():
# pass
def test_entropy_regulariser():
X = np.random.uniform(0, 10, [1500, 5])
y = np.random.randint(0, 2, [1500, 1])
test_model = tf.keras.Sequential()
test_model.add(tf.keras.layers.Dense(1))
test_model.add(deepof.model_utils.Entropy_regulariser(1.0))
test_model.compile(
loss=tf.keras.losses.binary_crossentropy, optimizer=tf.keras.optimizers.SGD(),
)
fit = test_model.fit(X, y, epochs=10, batch_size=100)
assert type(fit) == tf.python.keras.callbacks.History
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment