From 36bab27edf48f3abd20c341b349b7ff5f9605f16 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Sun, 12 Apr 2026 13:22:09 +0100 Subject: [PATCH 1/3] add knee constant func --- specparam/modes/funcs.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/specparam/modes/funcs.py b/specparam/modes/funcs.py index 625a3b4a..fa4b6a75 100644 --- a/specparam/modes/funcs.py +++ b/specparam/modes/funcs.py @@ -170,6 +170,31 @@ def double_expo_function(xs, *params): return ys +def knee_constant_function(xs, *params): + """Knee function with a constant, for fitting aperiodic component. + + Parameters + ---------- + xs : 1d array + Input x-axis values. + *params : float + Parameters (offset, exp, knee, constant) that define the function. + + Returns + ------- + ys : 1d array + Output values for the fit function. + """ + + ys = np.zeros_like(xs) + + offset, exp, knee, constant = params + + ys = ys + np.log10(10**offset * (1 / (knee**(exp) + xs**(exp))) + constant) + + return ys + + def linear_function(xs, *params): """Linear fitting function. From d3574e2f693885cb09ad3e072e873b47807422bb Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Sun, 12 Apr 2026 13:23:07 +0100 Subject: [PATCH 2/3] rewrite offset, for consistency --- specparam/modes/funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specparam/modes/funcs.py b/specparam/modes/funcs.py index fa4b6a75..1a6b234d 100644 --- a/specparam/modes/funcs.py +++ b/specparam/modes/funcs.py @@ -190,7 +190,7 @@ def knee_constant_function(xs, *params): offset, exp, knee, constant = params - ys = ys + np.log10(10**offset * (1 / (knee**(exp) + xs**(exp))) + constant) + ys = ys + offset - np.log10(1 / (knee**(exp) + xs**(exp)) + constant) return ys From c88292b9699dd1c8430c84890c60d5d022d15ac2 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Sun, 12 Apr 2026 13:42:39 +0100 Subject: [PATCH 3/3] add knee constant mode --- specparam/modes/definitions.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/specparam/modes/definitions.py b/specparam/modes/definitions.py index 7d5e7036..4af316d2 100644 --- a/specparam/modes/definitions.py +++ b/specparam/modes/definitions.py @@ -75,6 +75,28 @@ powers_space='log10', ) +## AP - Knee with Constant Mode + +params_knee_constant = ParamDefinition(OrderedDict({ + 'offset' : 'Offset of the aperiodic component.', + 'exponent' : 'Exponent of the aperiodic component.', + 'knee' : 'Knee of the aperiodic component.', + 'constant' : 'Constant value which the aperiodic component decays to, after the exponent.', +})) + +ap_knee_constant = Mode( + name='knee_constant', + component='aperiodic', + description='Fit a Lorentzian function that decays to a constant.', + formula=r'XX', + func=knee_constant_function, + jacobian=None, + params=params_knee_constant, + ndim=1, + freq_space='linear', + powers_space='log10', +) + # Collect available aperiodic modes AP_MODES = {