Skip to content

Commit

Permalink
Validation set for Gradient Based Models woohoo
Browse files Browse the repository at this point in the history
  • Loading branch information
jameschapman19 committed Oct 6, 2023
1 parent 20f2190 commit 0dc556d
Showing 1 changed file with 12 additions and 39 deletions.
51 changes: 12 additions & 39 deletions test/test_deepmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ def test_DCCA_methods():
max_epochs = 100
latent_dimensions = 2
cca = CCA(latent_dimensions=latent_dimensions).fit((X, Y))
# DCCA_NOI
encoder_1 = architectures.Encoder(latent_dimensions=latent_dimensions, feature_size=10)
encoder_2 = architectures.Encoder(latent_dimensions=latent_dimensions, feature_size=12)
dcca_noi = DCCA_NOI(latent_dimensions, encoders=[encoder_1, encoder_2], rho=0.2, lr=1e-2)
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dcca_noi, train_loader)
assert (
np.testing.assert_array_less(cca.score((X, Y)), dcca_noi.score(train_loader))
is None
)
# DCCA
encoder_1 = architectures.Encoder(
latent_dimensions=latent_dimensions, feature_size=10
Expand All @@ -176,9 +166,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dcca, train_loader, val_dataloaders=val_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), dcca.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), dcca.score(train_loader))
is None
)
# DCCA_GHA
Expand All @@ -196,9 +184,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dcca_gha, train_loader, val_dataloaders=val_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), dcca_gha.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), dcca_gha.score(train_loader))
is None
)
# DCCA_SVD
Expand All @@ -216,9 +202,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dcca_svd, train_loader, val_dataloaders=val_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), dcca_svd.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), dcca_svd.score(train_loader))
is None
)
# DCCA_EY
Expand All @@ -236,9 +220,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dcca_ey, train_loader, val_dataloaders=val_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), dcca_ey.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), dcca_ey.score(train_loader))
is None
)
# DCCA_NOI
Expand All @@ -248,13 +230,13 @@ def test_DCCA_methods():
encoder_2 = architectures.Encoder(
latent_dimensions=latent_dimensions, feature_size=12
)
dcca_noi = DCCA_NOI(latent_dimensions, encoders=[encoder_1, encoder_2], rho=0.2)
dcca_noi = DCCA_NOI(
latent_dimensions, encoders=[encoder_1, encoder_2], rho=0.2, lr=1e-2
)
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dcca_noi, train_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), dcca_noi.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), dcca_noi.score(train_loader))
is None
)
# Soft Decorrelation (_stochastic Decorrelation Loss)
Expand All @@ -270,10 +252,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(sdl, train_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), sdl.score(train_loader)
)
is None
np.testing.assert_array_less(cca.score((X, Y)), sdl.score(train_loader)) is None
)
# Barlow Twins
encoder_1 = architectures.Encoder(
Expand All @@ -289,9 +268,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(barlowtwins, train_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), barlowtwins.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), barlowtwins.score(train_loader))
is None
)
# DGCCA
Expand All @@ -309,9 +286,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dgcca, train_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), dgcca.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), dgcca.score(train_loader))
is None
)
# DMCCA
Expand All @@ -329,9 +304,7 @@ def test_DCCA_methods():
trainer = pl.Trainer(max_epochs=max_epochs, **trainer_kwargs)
trainer.fit(dmcca, train_loader)
assert (
np.testing.assert_array_less(
cca.score((X, Y)), dmcca.score(train_loader)
)
np.testing.assert_array_less(cca.score((X, Y)), dmcca.score(train_loader))
is None
)

Expand Down

0 comments on commit 0dc556d

Please sign in to comment.