Centralized and distributed online learning for sparse time-varying optimization