Rayleigh-Ritz variational principle for ensembles of fractionally occupied states.