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

[MNT] - Optimizations for curve fit #299

Merged
merged 13 commits into from
Sep 13, 2023
54 changes: 50 additions & 4 deletions fooof/core/jacobians.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
""""Functions for computing Jacobian matrices to be used during fitting."""
""""Functions for computing Jacobian matrices to be used during fitting.

Notes
-----
These functions line up with those in `funcs`.
The parameters in these functions are labelled {a, b, c, ...}, but follow the order in `funcs`.
These functions are designed to be passed into `curve_fit` to provide a computed Jacobian.
"""

import numpy as np

Expand All @@ -8,7 +15,20 @@
## Periodic fit functions

def jacobian_gauss(xs, *params):
"""Create the Jacobian matrix for the Guassian function."""
"""Create the Jacobian matrix for the Guassian function.
TomDonoghue marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
xs : 1d array
Input x-axis values.
*params : float
Parameters for the function.

Returns
-------
jacobian : 2d array
Jacobian matrix, with shape [len(xs), n_params].
"""

jacobians = []
for a, b, c in zip(*[iter(params)] * 3):
Expand All @@ -28,7 +48,20 @@ def jacobian_gauss(xs, *params):
## Aperiodic fit functions

def jacobian_expo(xs, *params):
"""Create the Jacobian matrix for the exponential function."""
"""Create the Jacobian matrix for the exponential function.

Parameters
----------
xs : 1d array
Input x-axis values.
*params : float
Parameters for the function.

Returns
-------
jacobian : 2d array
Jacobian matrix, with shape [len(xs), n_params].
"""

a, b, c = params
jacobian = np.hstack([
Expand All @@ -41,7 +74,20 @@ def jacobian_expo(xs, *params):


def jacobian_expo_nk(xs, *params):
"""Create the Jacobian matrix for the exponential no-knee function."""
"""Create the Jacobian matrix for the exponential no-knee function.

Parameters
----------
xs : 1d array
Input x-axis values.
*params : float
Parameters for the function.

Returns
-------
jacobian : 2d array
Jacobian matrix, with shape [len(xs), n_params].
"""

jacobian = np.hstack([
np.ones([len(xs), 1]),
Expand Down
1 change: 0 additions & 1 deletion fooof/tests/core/test_jacobians.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tests for fooof.core.jacobians."""


from fooof.core.jacobians import *

###################################################################################################
Expand Down