Skip to content

Conversation

@TomDonoghue
Copy link
Member

@TomDonoghue TomDonoghue commented Nov 26, 2025

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

  • This might not be the final approach / organization for managing parameter conversions, and some elements might move around a bit.
  • There needs to be a related / similar update to the simulations to allow for simulating power spectra based on different combinations of components (this update to come)
  • It's still an open question to me if / how to change defaults. Possible options include:
    • Keep current default (log-subtraction), but now the user could change this
    • Change the default, most likely to linear-subtraction
    • Remove the default, so that the user would have to decide on the approach they want

@TomDonoghue TomDonoghue changed the title [ENH] - Add general support for parameter conversions [ENH/WIP] - Add general support for parameter conversions Nov 26, 2025
@fooof-tools fooof-tools deleted a comment from codecov bot Nov 26, 2025
@fooof-tools fooof-tools deleted a comment from codecov bot Dec 2, 2025
@fooof-tools fooof-tools deleted a comment from codecov bot Dec 3, 2025
@TomDonoghue TomDonoghue merged commit c2a4687 into main Dec 3, 2025
10 checks passed
@TomDonoghue TomDonoghue deleted the peakh branch December 3, 2025 14:04
@fooof-tools fooof-tools deleted a comment from codecov bot Dec 3, 2025
@TomDonoghue TomDonoghue changed the title [ENH/WIP] - Add general support for parameter conversions [ENH] - Add support for generalized parameter conversions & different peak heights Dec 3, 2025
@TomDonoghue TomDonoghue mentioned this pull request Dec 3, 2025
13 tasks
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