A transdimensional Bayesian method to infer the star formation history of resolved stellar populations