Learning Optimal Commitment to Overcome Insecurity