python/methylnet/models.py
def train_decoder_(model, x, z):
	"""Run if retraining decoder to adjust for adjusted latent embeddings during finetuning of embedding layers for VAE_MLP.

	Parameters
	----------
	model : type
		VAE_MLP model.
	x : type
		Input methylation data.
	z : type
		Latent Embeddings

	Returns
	-------
	nn.Module
		VAE_MLP module with updated decoder parameters.
	float
		Reconstruction loss over all batches.

	"""
	model.vae.train(True)
	for param in model.parameters():
		param.requires_grad = False
	for param in model.vae.decoder.parameters():
		param.requires_grad = True
	loss_fn = nn.BCELoss(reduction='sum')
	x_hat = model.decode(z)
	if type(x_hat) != type([]):
		x_hat = [x_hat]
	loss = sum([loss_func(x_h, x) for x_h in x_hat])
	loss.backward()
	for param in model.parameters():
		param.requires_grad = True
	model.vae.eval()
	return model, loss.item()
Run if retraining decoder to adjust for adjusted latent embeddings during finetuning of embedding layers for VAE_MLP.

	Parameters
	----------
	model : type
		VAE_MLP model.
	x : type
		Input methylation data.
	z : type
		Latent Embeddings

	Returns
	-------
	nn.Module
		VAE_MLP module with updated decoder parameters.
	float
		Reconstruction loss over all batches.

	
Run if retraining decoder to adjust for adjusted latent embeddings during finetuning of embedding layers for VAE_MLP.
Parameters

model : type
VAE_MLP model.
x : type
Input methylation data.
z : type
Latent Embeddings

Returns

nn.Module
VAE_MLP module with updated decoder parameters.
float
Reconstruction loss over all batches.
Run if retraining decoder to adjust for adjusted latent embeddings during finetuning of embedding layers for VAE_MLP . Parameters model : type VAE_MLP model . x : type Input methylation data . z : type Latent Embeddings Returns nn . Module VAE_MLP module with updated decoder parameters . float Reconstruction loss over all batches .
def train_decoder_(model, x, z):
	model.vae.train(True)
	for param in model.parameters():
		param.requires_grad = False
	for param in model.vae.decoder.parameters():
		param.requires_grad = True
	loss_fn = nn.BCELoss(reduction='sum')
	x_hat = model.decode(z)
	if type(x_hat) != type([]):
		x_hat = [x_hat]
	loss = sum([loss_func(x_h, x) for x_h in x_hat])
	loss.backward()
	for param in model.parameters():
		param.requires_grad = True
	model.vae.eval()
	return model, loss.item()
def train_decoder_ ( model , x , z ) : model . vae . train ( True ) for param in model . parameters ( ) : param . requires_grad = False for param in model . vae . decoder . parameters ( ) : param . requires_grad = True loss_fn = nn . BCELoss ( reduction = 'sum' ) x_hat = model . decode ( z ) if type ( x_hat ) != type ( [ ] ) : x_hat = [ x_hat ] loss = sum ( [ loss_func ( x_h , x ) for x_h in x_hat ] ) loss . backward ( ) for param in model . parameters ( ) : param . requires_grad = True model . vae . eval ( ) return model , loss . item ( )
Run if retraining decoder to adjust for adjusted latent embeddings during finetuning of embedding layers for VAE_MLP.
Run if retraining decoder to adjust for adjusted latent embeddings during finetuning of embedding layers for VAE_MLP .
"""Run if retraining decoder to adjust for adjusted latent embeddings during finetuning of embedding layers for VAE_MLP.

	Parameters
	----------
	model : type
		VAE_MLP model.
	x : type
		Input methylation data.
	z : type
		Latent Embeddings

	Returns
	-------
	nn.Module
		VAE_MLP module with updated decoder parameters.
	float
		Reconstruction loss over all batches.

	"""
model
x
z