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

solve_trig sometimes returns an incorrect root #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

azagajewski
Copy link
Contributor

solve_trig by default returns the first root (k=0) of the trigonometric solution, which is sometimes not the correct root. This leads to errors in calculation of x_c which propagates to the radial distribution calculation and cell reconstrution, particularily when the cells become vertical.

Fixed by returning all 3 roots (k=0,1,2) from solve_trig, and by adding a static method to evaluate the r^2 polynomial expression at all 3 roots and pick the root that minimizes r^2. A purely analytic solution is also possible based on the sign of the second deriviative, but in practice this was fewer lines of code, and that would have the issue of inflexion points.

To reproduce a test case, initialise the parameters and bitmap provided in #119 and reconstruct over the binary. Current code produces the incorrect reconstruction (bottom), fix produces the correct reconstruction (top). Same holds for fluorescent data, not shown here for brevity. (Sorry for small image size of bitmap, they're the same pixel size as the mask which generated them)

good_reconstruction
bad_reconstruction

fixes #122

…es to _solve_trig to return all 3 real roots instead of the 1st one from the trigonometric solution, added static _pick_root which picks the correct root to use, changes to calc_xc which now uses _pick_root to pick the correct root.
@Jhsmit
Copy link
Owner

Jhsmit commented Jul 4, 2021

Thanks, I'll try to have a look a this later today or this week.

Just for any potential future contributions; it's easier for me if you create a feature branch on your work (instead of using master) and then if you make a PR tick the box 'Allow edits from maintainers'.
This will allow me to push changes to your branch (and the PR) such that I can add tests or make other changes before merging

@azagajewski
Copy link
Contributor Author

Sounds good, I'll create a separate branch in my fork and go from there!

@azagajewski
Copy link
Contributor Author

By the way, as far as I see now, there appear to be no further issues. If I come across anything, I will try to fix and send to you.

@Jhsmit
Copy link
Owner

Jhsmit commented Jul 6, 2021

Ok, thanks.
I havent looked in detail yet but it seems like the tests are not passing.
It might be that there are some differences introduced in the optimization algorithm. Do the tests pass on your local branch?

@azagajewski
Copy link
Contributor Author

Hi, sorry for the delay, we were moving our lab to a new site this month and things have been super busy ... but getting back into things now.

Looking at the test, we have one failure in test_fitting_brightfield_DE, the DE optimiser returns a slightly different value (8197140.50771191 != 8191888.515532021) when optimising the cell. Since DE is quite stochastic iirc, this doesn't sound like a major problem. Let me know what you think!

Copy link
Owner

@Jhsmit Jhsmit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about all the nitpicking :)
In my tests I find a bit bigger difference in the differential evolution optimization (about 5000).
Probably not such a big a deal and as expected but I'll try to look into it more later.

colicoords/cell.py Show resolved Hide resolved
colicoords/cell.py Show resolved Hide resolved
@azagajewski
Copy link
Contributor Author

No worries, your work, your rules! High code quality is definitively something to fight hard for! :)

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.

Radial distribution errors over occasional cells
2 participants