(self, n_epochs=1)
return self.history
Launch the training and logging loop.

        Parameters
        ----------
        n_epochs : int
            Number of epochs.
Launch the training and logging loop.
Launch the training and logging loop .
def launch(self, n_epochs=1):
        """Launch the training and logging loop.

        Parameters
        ----------
        n_epochs : int
            Number of epochs.
        """
        try:
            self.network.to(device=self.device, dtype=self.dtype)
            # Train begin
            if self.current_epoch == -1:
                self.on_train_begin(metadata={'n_epochs': n_epochs})

            for _ in range(n_epochs):
                self.current_epoch += 1
                # Epoch begin
                self.on_epoch_begin(metadata={'epoch': self.current_epoch})

                for batch_ix, (X_batch, y_batch, timestamps, asset_names) in enumerate(self.train_dataloader):
                    # Batch begin
                    self.on_batch_begin(metadata={'asset_names': asset_names,
                                                  'batch': batch_ix,
                                                  'epoch': self.current_epoch,
                                                  'timestamps': timestamps,
                                                  'X_batch': X_batch,
                                                  'y_batch': y_batch})

                    # Get batch
                    X_batch, y_batch = X_batch.to(self.device).to(self.dtype), y_batch.to(self.device).to(self.dtype)

                    # Make sure network on the right device and train mode
                    self.network.train()

                    # Forward & Backward
                    weights = self.network(X_batch)
                    loss_per_sample = self.loss(weights, y_batch)
                    loss = loss_per_sample.mean()
                    self.optimizer.zero_grad()
                    loss.backward()
                    self.optimizer.step()

                    # Switch back to eval mode
                    self.network.eval()

                    # Batch end
                    self.on_batch_end(metadata={'asset_names': asset_names,
                                                'batch': batch_ix,
                                                'batch_loss': loss.item(),
                                                'epoch': self.current_epoch,
                                                'timestamps': timestamps,
                                                'weights': weights,
                                                'X_batch': X_batch,
                                                'y_batch': y_batch})

                # Epoch end
                self.on_epoch_end(metadata={'epoch': self.current_epoch,
                                            'n_epochs': n_epochs})

            # Train end
            self.on_train_end()

        except (EarlyStoppingException, KeyboardInterrupt, SolverError) as ex:
            print('Training interrupted')
            time.sleep(1)

            self.on_train_interrupt(metadata={'exception': ex,
                                              'locals': locals()})

        return self.history
def launch ( self , n_epochs = 1 ) : try : self . network . to ( device = self . device , dtype = self . dtype ) # Train begin if self . current_epoch == - 1 : self . on_train_begin ( metadata = { 'n_epochs' : n_epochs } ) for _ in range ( n_epochs ) : self . current_epoch += 1 # Epoch begin self . on_epoch_begin ( metadata = { 'epoch' : self . current_epoch } ) for batch_ix , ( X_batch , y_batch , timestamps , asset_names ) in enumerate ( self . train_dataloader ) : # Batch begin self . on_batch_begin ( metadata = { 'asset_names' : asset_names , 'batch' : batch_ix , 'epoch' : self . current_epoch , 'timestamps' : timestamps , 'X_batch' : X_batch , 'y_batch' : y_batch } ) # Get batch X_batch , y_batch = X_batch . to ( self . device ) . to ( self . dtype ) , y_batch . to ( self . device ) . to ( self . dtype ) # Make sure network on the right device and train mode self . network . train ( ) # Forward & Backward weights = self . network ( X_batch ) loss_per_sample = self . loss ( weights , y_batch ) loss = loss_per_sample . mean ( ) self . optimizer . zero_grad ( ) loss . backward ( ) self . optimizer . step ( ) # Switch back to eval mode self . network . eval ( ) # Batch end self . on_batch_end ( metadata = { 'asset_names' : asset_names , 'batch' : batch_ix , 'batch_loss' : loss . item ( ) , 'epoch' : self . current_epoch , 'timestamps' : timestamps , 'weights' : weights , 'X_batch' : X_batch , 'y_batch' : y_batch } ) # Epoch end self . on_epoch_end ( metadata = { 'epoch' : self . current_epoch , 'n_epochs' : n_epochs } ) # Train end self . on_train_end ( ) except ( EarlyStoppingException , KeyboardInterrupt , SolverError ) as ex : print ( 'Training interrupted' ) time . sleep ( 1 ) self . on_train_interrupt ( metadata = { 'exception' : ex , 'locals' : locals ( ) } ) return self . history