code: def reg_func_trend(weights, threshold=None):
      """Regularization of weights to induce sparcity
  
      Parameters
      ----------
          weights : torch.Tensor
              Model weights to be regularized towards zero
          threshold : float
              Value below which not to regularize weights
  
      Returns
      -------
          torch.Tensor
              regularization loss
      """
      # weights dimensions:
      # local: quantiles, num_time_series, segments + 1
      # global: quantiles, segments + 1
      # we do the average of all the sum of weights per time series and per quantile. equivalently
      abs_weights = torch.abs(weights)
      if threshold is not None and not math.isclose(threshold, 0):
          abs_weights = torch.clamp(abs_weights - threshold, min=0.0)
      reg = torch.mean(torch.sum(abs_weights, dim=-1)).squeeze()
      return reg
  
imports: from __future__ import annotations
  import logging
  import math
  import os
  import sys
  from collections import OrderedDict
  from typing import TYPE_CHECKING, Iterable, Optional, Union
  import numpy
  import pandas
  import pytorch_lightning
  import torch
  from neuralprophet import utils_torch
  from neuralprophet.hdays_utils import get_country_holidays
  from neuralprophet.logger import ProgressBar
label_desc: Use image node_id 4 for calling a global function with example usage: reg_func_trend(weights, threshold) and returns: reg