Open
Conversation
For certain dipole locations (and moments) FSM calculates NaN potential at certain electrodes. It is probably due to numerical error in calculating `cos(phi)` value which violates `-1 <= cos(phi) <= 1`, thus leading to `arccos(cos(phi))` being NaN.
`cos(phi)` fixed if violating `-1 <= cos(phi) <= 1`. If `abs(cos(phi)) > 1 + 1e-10`, `RuntimeWarning` is triggered. See also: f78145b
Collaborator
|
We discovered the same problem in the LFPy-version of the code. This problem occurs when phi is not defined. I.e., when theta= 0 or theta = pi or when the dipole has no tangential component. Here: LFPy/eegmegcalc.py, from line 646, you can see how we solved this by creating a mask to avoid trying to compute phi when not defined. The way the dipole is decomposed in a radial and tangential component, is prone to round-off errors. We have created a unit vector containing the direction of the dipole location vector (self._z, line 400), and using self._z to decompose the dipole (line 545) will reduce the risk of round-off errors. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For particular combination of dipoles and electrodes calculated potentials were NaNs.
I have traced the error to violation of the
-1 <= cos(phi) <= 1constraint, probably due to a numerical error.