Code to compute importance weights