import torch


def calculate_threshold(weights):
  """Calculates LTU threshold according to weights"""
  m = weights.shape[1]
  beta = 0.6
  S = torch.sum(weights<0, dim=1)
  threshold = torch.ones(weights.shape[0])*m*beta - S.float()
  return threshold