-
Notifications
You must be signed in to change notification settings - Fork 110
[ENH] - Add support for generalized parameter conversions & different peak heights #383
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
Merged
Conversation
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.
This generalizes the procedure for doing post-fitting parameter conversions.
Parameter Conversions
To do so, it introduces "ParameterConverters". For any parameter with a requested / provided converter, this conversion gets called on the fit parameter value after the model fitting process.
In doing so, this update removes parameter conversion from the Algorithm, and makes it a separate process. Note that in terms of default behavior, this PR does not change anything (the same set of post-fitting parameter conversions are defined are previous versions of specparam 2.0 & fooof 1.X, and they are accessed / returned in the same way).
Peak Heights
A key motivation for this relates to being able to update the procedure for how we calculate peak heights. Briefly, in the original version, we fit in log-power values, and return log-power peak heights, computed as the difference between the full model and aperiodic component (in log space). However, this assumes a particular way that the components relate to each other, which is not necessarily always desired (working with addition / subtraction in log space, this is equivalent to multiplication / division in linear space). Though there is not necessarily a definitive answer to how one should model the combination of components (that I know of), one may not always want to use the log-subtracted peak heights that we built in as a default.
Relatedly, in the original code, we also didn't return the literal height of the gaussian (which is fit as log-subtraction), but already built in a post-processing step that recomputed the peak height (as log-subtraction). Originally, this was to make individual peak heights independently interpretable regardless of any overlaps. In generalizing this parameter conversion stage, this means that we can re-compute peak heights based on different model component relationships, and give the user choice on this.
Note: in terms of the Pros / Cons of this approach, this DOES address being able to easily define and compute different peak height measures, including linear additive models, etc. It does so within changing anything about fitting, which is good for consistency. However, this also means this update DOES NOT address any potential implications / limitations of doing log-subtraction in the model fitting process. For example, low power peaks may be harder to detect in log space than they would be linear space, and this may also vary by frequency (because of the 1/f contribution). Further work could investigate whether there are benefits to exploring different approaches during fitting, instead of or in addition to the post-fitting parameter conversion done here. Note that this should now be quite do-able using the flexible approach for defining / testing new or update algorithms.
Further Notes