Optimal Inference for Distributed Detection