Is your standard deviation finite? Could you run it and print out sdactivations and sdloss at each iteration? If your standard deviation isn’t finite (perhaps from a too small batch size) you could be dividing by 0.