A Relational Macrostate Theory Guides Artificial Intelligence to Learn Macro and Design Micro