Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement clip of sig_ml to avoid divide by zero bug #20

Merged
merged 2 commits into from
Sep 1, 2020

Conversation

jpkrooney
Copy link
Contributor

Proposed solution for issue #19
I have added the line:
sig_ml = sig_ml.clip(0.5) # To prevent divide by zero in marginal_p function
the estimate_parameters function in order to later divide by zero issue in the marginal_p function. As discussed in issue #19 , 0.5 is a somewhat arbitrary figure, however it seems to work well in practice. However you may wish to explore this further before implementing this fix.

Prevents a divide by zero/divide by almost-zero scenario in the function marginal_p. Min value of 0.5 for sig_ml seems to work well although this may need further testing.
@gregversteeg gregversteeg mentioned this pull request Jun 22, 2020
@jpkrooney
Copy link
Contributor Author

After some further thought and experimentation I'd suggest a clip value of 0.25 instead of 0.5. i.e.
sig_ml = sig_ml.clip( 0.25 ) # To prevent divide by zero in marginal_p function

The logic being as follows: the denominator for the calculation in marginal_p is:
(2. * sig) - 0.5 * np.log(2 * np.pi * sig)).transpose((1, 0, 2))
This output of this function reaches a minima at 0.25 as sig varies as shown in this graph:
Screenshot 2020-08-31 at 10 11 33
Below sig = 0.25 the function quickly becomes asymptotic.
In test runs with different values for the clip, 0.25 produce higher TCS than a clip of 0.25.

@gregversteeg gregversteeg merged commit ad2f587 into gregversteeg:master Sep 1, 2020
jpkrooney added a commit to jpkrooney/bio_corex that referenced this pull request Sep 2, 2020
Merge pull request gregversteeg#20 from jpkrooney/master
@jpkrooney
Copy link
Contributor Author

Hi Greg. I took another look at this issue. I'm afraid I made a mistake in generating the above graph by misplacing a bracket. Thus the choice of 0.25 as a clip on sig_ml is not justified by the above argument. Will post more thoughts on the divide by zero issue here: #19 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants