Fast-ion losses induced by ELMs and externally applied magnetic perturbations in the ASDEX Upgrade tokamak