REPLICAS IN COMPLEX SYSTEMS: APPLICATIONS TO LARGE DEVIATIONS AND NEURAL NETWORKS