The foundations of inference and its application to fundamental physics