def test_special_dataset_size(self): gene_dataset = GeneExpressionDataset() x = np.random.randint(1, 100, (17 * 2, 10)) y = np.random.randint(1, 100, (17 * 2, 10)) gene_dataset.populate_from_data(x) protein_data = CellMeasurement( name="protein_expression", data=y, columns_attr_name="protein_names", columns=np.arange(10), ) gene_dataset.initialize_cell_measurement(protein_data) # Test UnsupervisedTrainer vae = VAE( gene_dataset.nb_genes, n_batch=gene_dataset.n_batches, n_labels=gene_dataset.n_labels, ) trainer = UnsupervisedTrainer( vae, gene_dataset, train_size=0.5, use_cuda=False, data_loader_kwargs={"batch_size": 8}, ) trainer.train(n_epochs=1) # Test JVATrainer jvae = JVAE( [gene_dataset.nb_genes, gene_dataset.nb_genes], gene_dataset.nb_genes, [slice(None)] * 2, ["zinb", "zinb"], [True, True], n_batch=1, ) cls = Classifier(gene_dataset.nb_genes, n_labels=2, logits=True) trainer = JVAETrainer( jvae, cls, [gene_dataset, gene_dataset], train_size=0.5, use_cuda=False, data_loader_kwargs={"batch_size": 8}, ) trainer.train(n_epochs=1) totalvae = TOTALVI(gene_dataset.nb_genes, len(gene_dataset.protein_names)) trainer = TotalTrainer( totalvae, gene_dataset, train_size=0.5, use_cuda=False, data_loader_kwargs={"batch_size": 8}, early_stopping_kwargs=None, ) trainer.train(n_epochs=1)
def test_special_dataset_size(self): gene_dataset = GeneExpressionDataset() x = np.random.randint(1, 100, (17 * 2, 10)) gene_dataset.populate_from_data(x) # Test UnsupervisedTrainer vae = VAE( gene_dataset.nb_genes, n_batch=gene_dataset.n_batches, n_labels=gene_dataset.n_labels, ) trainer = UnsupervisedTrainer( vae, gene_dataset, train_size=0.5, use_cuda=False, data_loader_kwargs={"batch_size": 8}, ) trainer.train(n_epochs=1) # Test JVATrainer jvae = JVAE( [gene_dataset.nb_genes, gene_dataset.nb_genes], gene_dataset.nb_genes, [slice(None)] * 2, ["zinb", "zinb"], [True, True], n_batch=1, ) cls = Classifier(gene_dataset.nb_genes, n_labels=2, logits=True) trainer = JVAETrainer( jvae, cls, [gene_dataset, gene_dataset], train_size=0.5, use_cuda=False, data_loader_kwargs={"batch_size": 8}, ) trainer.train(n_epochs=1)
n_latent = 8 kappa = 5 start = tm.time() torch.manual_seed(0) model = JVAE( n_inputs, total_genes, gene_mappings, generative_distributions, model_library_size, n_layers_decoder_individual=0, n_layers_decoder_shared=0, n_layers_encoder_individual=1, n_layers_encoder_shared=1, dim_hidden_encoder=64, dim_hidden_decoder_shared=64, dropout_rate_encoder=0.2, dropout_rate_decoder=0.2, n_batch=n_batches, n_latent=n_latent, ) discriminator = Classifier(n_latent, 32, 2, 3, logits=True) trainer = JVAETrainer(model, discriminator, datasets, 0.95, frequency=1,