Optimizing FPGA and Wafer Test Coverage with Spatial Sampling and Machine Learning