import torch


def inverseSoftplus(y, beta=1, threshold=20):
  """
  inverse of y=torch.nn.functional.softplus(x, beta, threshold)
  :param y: the output of the softplus
  :param beta: the smoothness of the step
  :param threshold: the threshold after which a linear function is used
  :return: the input
  """
  return torch.where(y*beta>threshold, y, torch.log(torch.exp(beta*y)-1)/beta)