class_docstr: Linear time regression fun and some not so linear fun.
  A modular model that models classic time-series components
      * trend
      * seasonality
      * auto-regression (as AR-Net)
      * covariates (as AR-Net)
      * apriori regressors
      * events and holidays
  by using Neural Network components.
  The Auto-regression and covariate components can be configured as a deeper network (AR-Net).
class_docstr_tok: ["Linear","time","regression","fun","and","some","not","so","linear","fun",".","A","modular","model","that","models","classic","time-series","components","*","trend","*","seasonality","*","auto-regression","(","as","AR-Net",")","*","covariates","(","as","AR-Net",")","*","apriori","regressors","*","events","and","holidays","by","using","Neural","Network","components",".","The","Auto-regression","and","covariate","components","can","be","configured","as","a","deeper","network","(","AR-Net",")","."]
docstr: Add regularization terms to loss, if applicable
  Parameters
  ----------
      loss : torch.Tensor, scalar
          current batch loss
      epoch : int
          current epoch number
      progress : float
          progress within the epoch, between 0 and 1
  Returns
  -------
      loss, reg_loss
docstr_tok: ["Add","regularization","terms","to","loss",",","if","applicable","Parameters","--","--","--","--","--","loss",":","torch.Tensor",",","scalar","current","batch","loss","epoch",":","int","current","epoch","number","progress",":","float","progress","within","the","epoch",",","between","0","and","1","Returns","--","--","--","-","loss",",","reg_loss"]
code: def _add_batch_regularizations(self, loss, epoch, progress):
      """Add regularization terms to loss, if applicable
      Parameters
      ----------
          loss : torch.Tensor, scalar
              current batch loss
          epoch : int
              current epoch number
          progress : float
              progress within the epoch, between 0 and 1
      Returns
      -------
          loss, reg_loss
      """
      delay_weight = self.config_train.get_reg_delay_weight(
          epoch, progress
      )
  
      reg_loss = torch.zeros(
          1, dtype=torch.float, requires_grad=False, device=self.device
      )
      if delay_weight > 0:
          # Add regularization of AR weights - sparsify
          if (
              self.max_lags > 0
              and self.config_ar.reg_lambda is not None
          ):
              reg_ar = self.config_ar.regularize(self.ar_weights)
              reg_ar = torch.sum(reg_ar).squeeze() / self.n_forecasts
              reg_loss += self.config_ar.reg_lambda * reg_ar
  
          # Regularize trend to be smoother/sparse
          l_trend = self.config_trend.trend_reg
          if (
              self.config_trend.n_changepoints > 0
              and l_trend is not None
              and l_trend > 0
          ):
              reg_trend = reg_func_trend(
                  weights=self.trend.get_trend_deltas,
                  threshold=self.config_train.trend_reg_threshold,
              )
              reg_loss += l_trend * reg_trend
  
          # Regularize seasonality: sparsify fourier term coefficients
          if self.config_seasonality:
              l_season = self.config_seasonality.reg_lambda
              if (
                  self.seasonality.season_dims is not None
                  and l_season is not None
                  and l_season > 0
              ):
                  for name in self.seasonality.season_params.keys():
                      reg_season = reg_func_season(
                          self.seasonality.season_params[name]
                      )
                      reg_loss += l_season * reg_season
  
          # Regularize events: sparsify events features coefficients
          if (
              self.config_events is not None
              or self.config_holidays is not None
          ):
              reg_events_loss = reg_func_events(
                  self.config_events, self.config_holidays, self
              )
              reg_loss += reg_events_loss
  
          # Regularize regressors: sparsify regressor features coefficients
          if self.config_regressors is not None:
              reg_regressor_loss = reg_func_regressors(
                  self.config_regressors, self
              )
              reg_loss += reg_regressor_loss
  
      reg_loss = delay_weight * reg_loss
      loss = loss + reg_loss
      return loss, reg_loss
  
imports: import logging
  import math
  from collections import OrderedDict
  from functools import reduce
  from typing import Dict, List, Optional, Union
  import numpy
  import pytorch_lightning
  import torch
  import torch.nn
  import torchmetrics
  from neuralprophet import configure, np_types
  from neuralprophet.components.router import get_future_regressors, get_seasonality, get_trend
  from neuralprophet.utils import check_for_regularization, config_events_to_model_dims, reg_func_events, reg_func_regressors, reg_func_season, reg_func_trend
  from neuralprophet.utils_torch import init_parameter, interprete_model
label_desc: Use image node_id 20 for calling the TimeNet obj's underlying member method code with example usage: obj._add_batch_regularizations(loss, epoch, progress) and returns: loss,  reg_loss