Optimal Information Gathering Processes: Algorithmic Learning and Rational Herds