Large deviations and statistical mechanics