AthenaEPI / dmipy

The open source toolbox for reproducible diffusion MRI-based microstructure estimation
MIT License
96 stars 30 forks source link

divide by zero in volume fraction normalization of tortuosity #102

Open matteofrigo opened 4 years ago

matteofrigo commented 4 years ago

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 ?

rutgerfick commented 4 years ago

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)?

matteofrigo commented 4 years ago

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.

rutgerfick commented 4 years ago

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