python/methylnet/models.py
def fit(self, train_data):
		"""Fit MLP to training data to make predictions.

		Parameters
		----------
		train_data : type
			DataLoader with Training MethylationDataset.

		Returns
		-------
		self
			MLPFinetuneVAE with updated parameters.
		"""
		loss_list = []
		model = self.model
		print(model)
		best_model=copy.deepcopy(self.model)
		plt_data={'loss':[],'lr_vae':[],'lr_mlp':[], 'val_loss':[]}
		for epoch in range(self.n_epochs):
			print(epoch)
			model, loss = self.train_fn(model, train_data, self.loss_fn, self.optimizer_vae, self.optimizer_mlp, self.cuda,categorical=self.categorical, train_decoder=self.train_decoder)
			self.scheduler_vae.step()
			self.scheduler_mlp.step()
			plt_data['loss'].append(loss)
			print("Epoch {}: Loss {}".format(epoch,loss))
			if self.validation_set:
				model, val_loss = self.val_fn(model, self.validation_set, self.loss_fn, self.cuda,categorical=self.categorical, train_decoder=self.train_decoder)
				plt_data['val_loss'].append(val_loss)
				print("Epoch {}: Val-Loss {}".format(epoch,val_loss))
			plt_data['lr_vae'].append(self.scheduler_vae.get_lr())
			plt_data['lr_mlp'].append(self.scheduler_mlp.get_lr())
			loss = loss if not self.validation_set else val_loss
			loss_list.append(loss)
			if loss <= min(loss_list): # next get models for lowest reconstruction and kl, 3 models
				best_model=copy.deepcopy(model)
				best_epoch=epoch
		self.training_plot_data=plt_data
		if 0:
			plts=Plotter([Plot(k,'epoch','lr' if 'loss' not in k else k,
						  pd.DataFrame(np.vstack((range(len(plt_data[k])),plt_data[k])).T,
									   columns=['x','y'])) for k in plt_data if plt_data[k]],animation=False)
			plts.write_plots(self.loss_plt_fname)
		self.min_loss = min(plt_data['loss'])
		if self.validation_set:
			self.min_val_loss = min(plt_data['val_loss'])
		else:
			self.min_val_loss = -1
		self.best_epoch = best_epoch
		self.model = best_model
		return self
Fit MLP to training data to make predictions.

		Parameters
		----------
		train_data : type
			DataLoader with Training MethylationDataset.

		Returns
		-------
		self
			MLPFinetuneVAE with updated parameters.
		
Fit MLP to training data to make predictions.
Parameters



Returns

self
MLPFinetuneVAE with updated parameters.
Fit MLP to training data to make predictions . Parameters Returns self MLPFinetuneVAE with updated parameters .
def fit(self, train_data):
		loss_list = []
		model = self.model
		print(model)
		best_model=copy.deepcopy(self.model)
		plt_data={'loss':[],'lr_vae':[],'lr_mlp':[], 'val_loss':[]}
		for epoch in range(self.n_epochs):
			print(epoch)
			model, loss = self.train_fn(model, train_data, self.loss_fn, self.optimizer_vae, self.optimizer_mlp, self.cuda,categorical=self.categorical, train_decoder=self.train_decoder)
			self.scheduler_vae.step()
			self.scheduler_mlp.step()
			plt_data['loss'].append(loss)
			print("Epoch {}: Loss {}".format(epoch,loss))
			if self.validation_set:
				model, val_loss = self.val_fn(model, self.validation_set, self.loss_fn, self.cuda,categorical=self.categorical, train_decoder=self.train_decoder)
				plt_data['val_loss'].append(val_loss)
				print("Epoch {}: Val-Loss {}".format(epoch,val_loss))
			plt_data['lr_vae'].append(self.scheduler_vae.get_lr())
			plt_data['lr_mlp'].append(self.scheduler_mlp.get_lr())
			loss = loss if not self.validation_set else val_loss
			loss_list.append(loss)
			if loss <= min(loss_list): 
				best_model=copy.deepcopy(model)
				best_epoch=epoch
		self.training_plot_data=plt_data
		if 0:
			plts=Plotter([Plot(k,'epoch','lr' if 'loss' not in k else k,
						  pd.DataFrame(np.vstack((range(len(plt_data[k])),plt_data[k])).T,
									   columns=['x','y'])) for k in plt_data if plt_data[k]],animation=False)
			plts.write_plots(self.loss_plt_fname)
		self.min_loss = min(plt_data['loss'])
		if self.validation_set:
			self.min_val_loss = min(plt_data['val_loss'])
		else:
			self.min_val_loss = -1
		self.best_epoch = best_epoch
		self.model = best_model
		return self
def fit ( self , train_data ) : loss_list = [ ] model = self . model print ( model ) best_model = copy . deepcopy ( self . model ) plt_data = { 'loss' : [ ] , 'lr_vae' : [ ] , 'lr_mlp' : [ ] , 'val_loss' : [ ] } for epoch in range ( self . n_epochs ) : print ( epoch ) model , loss = self . train_fn ( model , train_data , self . loss_fn , self . optimizer_vae , self . optimizer_mlp , self . cuda , categorical = self . categorical , train_decoder = self . train_decoder ) self . scheduler_vae . step ( ) self . scheduler_mlp . step ( ) plt_data [ 'loss' ] . append ( loss ) print ( "Epoch {}: Loss {}" . format ( epoch , loss ) ) if self . validation_set : model , val_loss = self . val_fn ( model , self . validation_set , self . loss_fn , self . cuda , categorical = self . categorical , train_decoder = self . train_decoder ) plt_data [ 'val_loss' ] . append ( val_loss ) print ( "Epoch {}: Val-Loss {}" . format ( epoch , val_loss ) ) plt_data [ 'lr_vae' ] . append ( self . scheduler_vae . get_lr ( ) ) plt_data [ 'lr_mlp' ] . append ( self . scheduler_mlp . get_lr ( ) ) loss = loss if not self . validation_set else val_loss loss_list . append ( loss ) if loss <= min ( loss_list ) : best_model = copy . deepcopy ( model ) best_epoch = epoch self . training_plot_data = plt_data if 0 : plts = Plotter ( [ Plot ( k , 'epoch' , 'lr' if 'loss' not in k else k , pd . DataFrame ( np . vstack ( ( range ( len ( plt_data [ k ] ) ) , plt_data [ k ] ) ) . T , columns = [ 'x' , 'y' ] ) ) for k in plt_data if plt_data [ k ] ] , animation = False ) plts . write_plots ( self . loss_plt_fname ) self . min_loss = min ( plt_data [ 'loss' ] ) if self . validation_set : self . min_val_loss = min ( plt_data [ 'val_loss' ] ) else : self . min_val_loss = - 1 self . best_epoch = best_epoch self . model = best_model return self
Fit MLP to training data to make predictions.
Fit MLP to training data to make predictions .
"""Fit MLP to training data to make predictions.

		Parameters
		----------
		train_data : type
			DataLoader with Training MethylationDataset.

		Returns
		-------
		self
			MLPFinetuneVAE with updated parameters.
		""" # next get models for lowest reconstruction and kl, 3 models
self
train_data