import torch


def pcorrect(out, tilt):
  """Compute proportion of stimuli classified correctly from network output

  Args:
    out (torch.Tensor): output of network for each stimulus, i.e. the
      predicted probability of each stimulus being tilted right
    tilt (torch.Tensor): true tilt of each stimulus (1. for tilt right,
      0. for tilt left)
  
  Returns:
    float: proportion of stimuli classified correctly
  
  """
  out_tilt = (out > 0.5).type(torch.float)  # predicted tilt label: 1. for tilt right, 0. for tilt left (make sure to convert to float!)
  return (tilt == out_tilt).type(torch.float).mean().item()