Do you have any zeros or near-zero values in your dataset (bg) or as a result of f1[bg] or f2[bg]? If so, you could try dropping those, or adding 1 before doing your other operations. Hard to determine without knowing the range of values in your data.