code: def preds_to_weight_with_clamp(
      preds, clip_weight=None, clip_method="tanh"
  ):
      """
      Clip the weights.
  
      Parameters
      ----------
      clip_weight: float
          The clip threshold.
      clip_method: str
          The clip method. Current available: "clamp", "tanh", and "sigmoid".
      """
      if clip_weight is not None:
          if clip_method == "clamp":
              weights = torch.exp(preds)
              weights = weights.clamp(1.0 / clip_weight, clip_weight)
          elif clip_method == "tanh":
              weights = torch.exp(
                  torch.tanh(preds) * np.log(clip_weight)
              )
          elif clip_method == "sigmoid":
              # intuitively assume its sum is 1
              if clip_weight == 0.0:
                  weights = torch.ones_like(preds)
              else:
                  sm = nn.Sigmoid()
                  weights = (
                      sm(preds) * clip_weight
                  )  # TODO: The clip_weight is useless here.
                  weights = (
                      weights / torch.sum(weights) * weights.numel()
                  )
          else:
              raise ValueError("Unknown clip_method")
      else:
          weights = torch.exp(preds)
      return weights
  
file_path: qlib/qlib/contrib/meta/data_selection/utils.py
imports: import numpy
  import torch
  from torch import nn
  from qlib.constant import EPS
  from qlib.log import get_module_logger
label_desc: Use image node_id 1 for calling a global function with example usage: preds_to_weight_with_clamp(preds, clip_weight, clip_method) and returns: weights