Learning Beamforming Codebooks for Active Sensing with Reconfigurable Intelligent Surface