Statistical mechanics of samples, efficient representations and criticality