A computational framework for studying confidence in humans and animals