def test_outputShapes(self): network = DescriminatorNet(DEFAULT_CONFIG) preds = network(self.X) self.assertEqual(preds.logits.shape, (20, 1)) self.assertEqual(preds.logprob.shape, (20, 1)) self.assertEqual(preds.prob.shape, (20, 1)) self.assertEqual(preds.entropy.shape, (20, 1)) preds_with_y = network(self.X, False, self.y) self.assertEqual(preds_with_y.logits.shape, (20, 1)) self.assertEqual(preds_with_y.logprob.shape, (20, 1)) self.assertEqual(preds_with_y.prob.shape, (20, 1)) self.assertEqual(preds_with_y.entropy.shape, (20, 1))
def test_no_nans_for_simple_inputs(self): network = DescriminatorNet(DEFAULT_CONFIG) preds = network(self.X) # No Nans self.assertEqual(np.count_nonzero(np.isnan(preds.logits)), 0) self.assertEqual(np.count_nonzero(np.isnan(preds.logprob)), 0) self.assertEqual(np.count_nonzero(np.isnan(preds.prob)), 0) self.assertEqual(np.count_nonzero(np.isnan(preds.entropy)), 0) preds_with_y = network(self.X, False, self.y) self.assertEqual(np.count_nonzero(np.isnan(preds_with_y.logits)), 0) self.assertEqual(np.count_nonzero(np.isnan(preds_with_y.logprob)), 0) self.assertEqual(np.count_nonzero(np.isnan(preds_with_y.prob)), 0) self.assertEqual(np.count_nonzero(np.isnan(preds_with_y.entropy)), 0)
def test_probs_between_0_and_1(self): network = DescriminatorNet(DEFAULT_CONFIG) preds = network(self.X) # No Nans self.assertEqual(tf.reduce_sum(tf.cast((preds.prob < 0.0), "float32")), 0) self.assertEqual(tf.reduce_sum(tf.cast((preds.prob > 1.0), "float32")), 0) self.assertEqual( tf.reduce_sum(tf.cast((preds.logprob > 1.0), "float32")), 0) preds_with_y = network(self.X, False, self.y) self.assertEqual( tf.reduce_sum(tf.cast((preds_with_y.prob < 0.0), "float32")), 0) self.assertEqual( tf.reduce_sum(tf.cast((preds_with_y.prob > 1.0), "float32")), 0) self.assertEqual( tf.reduce_sum(tf.cast((preds_with_y.logprob > 1.0), "float32")), 0)
def __init__(self, config: GanNet.Config, fake_getter=None, real_getter=None, **kwargs): super().__init__(**kwargs) self.descriminator = DescriminatorNet(config.descriminator) self.generatornet = config.generator.get_generatornet_type()( config.generator) self.fake_getter = (fake_getter if fake_getter else config.generator.get_fake_output_getter()()) self.real_getter = (real_getter if real_getter else config.generator.get_real_output_getter()()) self.gan_generative = GanGenerativeNet(self.descriminator, self.generatornet, self.fake_getter) self.gan_descriminative = GanDescriminativeNet( self.descriminator, self.generatornet, self.fake_getter, self.real_getter, )
from deeper.models.adversarial_autoencoder.network import ( AdversarialAuoencoderNet, ) from deeper.models.adversarial_autoencoder.network_loss import ( AdverasrialAutoencoderLossNet, ) N_ROWS = 25 DIM_REG = 10 DIM_BOOL = 15 DIM_ORD = (5, ) DIM_CAT = (10, 8) DIM_X = DIM_REG + DIM_BOOL + sum(DIM_ORD) + sum(DIM_CAT) EMB_DIM = 10 LAT_DIM = 5 NCATS = 5 desciminatorConfig = DescriminatorNet.Config(embedding_dimensions=[EMB_DIM]) vaeConfig = VaeNet.Config( input_dimensions=MultipleObjectiveDimensions( regression=DIM_REG, boolean=DIM_BOOL, ordinal=DIM_ORD, categorical=DIM_CAT, ), output_dimensions=MultipleObjectiveDimensions( regression=DIM_REG, boolean=DIM_BOOL, ordinal=DIM_ORD, categorical=DIM_CAT, ), encoder_embedding_dimensions=[EMB_DIM],
X_test = (X_test > 0.5).astype(float) #%% Filter to a single label if False: LABEL = 9 X_train_og = X_train_og[y_train == LABEL] X_test_og = X_test_og[y_test == LABEL] X_train = X_train[y_train == LABEL] X_test = X_test[y_test == LABEL] #%% Instantiate the model BATCH_SIZE = 12 desciminatorConfig = DescriminatorNet.Config( embedding_dimensions=[24, 16, 12, 8], activation=tf.keras.layers.Activation("relu"), # embedding_dropout=0.25, # bn_before=True, ) vaeConfig = StackedGmvae.Config( components=20, cat_embedding_dimensions=[512, 512, 256, 128, 64], input_dimensions=MultipleObjectiveDimensions( regression=0, boolean=X_train.shape[-1], ordinal=(0, ), categorical=(0, ), ), output_dimensions=MultipleObjectiveDimensions( regression=0, boolean=X_train.shape[-1], ordinal=(0, ),
import tensorflow as tf import pytest import unittest import numpy as np import os from deeper.models.gan.descriminator import DescriminatorNet DEFAULT_CONFIG = DescriminatorNet.Config(embedding_dimensions=[20, 15], ) class TestDescriminatorNet(unittest.TestCase): def setUp(self): self.X = np.random.random((20, 25)) self.y = (np.random.random((20, 1)) > 0.5).astype("float32") def test_outputShapes(self): network = DescriminatorNet(DEFAULT_CONFIG) preds = network(self.X) self.assertEqual(preds.logits.shape, (20, 1)) self.assertEqual(preds.logprob.shape, (20, 1)) self.assertEqual(preds.prob.shape, (20, 1)) self.assertEqual(preds.entropy.shape, (20, 1)) preds_with_y = network(self.X, False, self.y) self.assertEqual(preds_with_y.logits.shape, (20, 1)) self.assertEqual(preds_with_y.logprob.shape, (20, 1)) self.assertEqual(preds_with_y.prob.shape, (20, 1)) self.assertEqual(preds_with_y.entropy.shape, (20, 1))