A Theory of Epidemics