Cognitive Loop via In-Situ Optimization: Self-Adaptive Reasoning for Science