dmipy icon indicating copy to clipboard operation
dmipy copied to clipboard

divide by zero in volume fraction normalization of tortuosity

Open matteofrigo opened this issue 3 years ago • 3 comments

When we pass the volume fraction of both the intra and the extra cellular compartments to the function that computes the perpendicular diffusivity through the tortuosity constraint, there could be a division by zero that breaks everything.

https://github.com/AthenaEPI/dmipy/blob/9bd7038ea93edbf9cced56a7ef6a0f19f25388c3/dmipy/utils/utils.py#L231

We might want to catch it and avoid the division in that case. Any more sophisticated thoughts @rutgerfick ?

matteofrigo avatar Jul 24 '20 07:07 matteofrigo

No you're completely right, this is something that should be caught if it happens. How about adding a small epsilon in the denominator to avoid this? something like vf_intra = vf_intra / (vf_intra + vf_extra + eps)?

rutgerfick avatar Jul 24 '20 12:07 rutgerfick

I've never liked that trick in general. In this context it may work since the parameter range for volume fractions is [0.01, 0.99] and I guess that in the optimization the variable is projected in that interval (correct me if I'm wrong), but I feel like it's not as clean as

denominator = vf_intra + vf_extra
if denominator == 0:
    vf_intra = 0
else:
    vf_intra = vf_intra / denominator

which comes almost for free.

matteofrigo avatar Aug 17 '20 08:08 matteofrigo

fair enough, please go ahead and add it and I'll merge.

rutgerfick avatar Aug 17 '20 11:08 rutgerfick