Ancestral Inference and Learning for Branching Processes in Random Environments