Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions specparam/modes/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from specparam.modes.mode import Mode
from specparam.modes.params import ParamDefinition
from specparam.modes.funcs import (expo_function, expo_nk_function, double_expo_function,
gaussian_function, skewnorm_function, cauchy_function)
gaussian_function, skewed_gaussian_function, cauchy_function)
from specparam.modes.jacobians import jacobian_gauss

###################################################################################################
## APERIODIC MODES

# Fixed
## AP - Fixed Mode

params_fixed = ParamDefinition(OrderedDict({
'offset' : 'Offset of the aperiodic component.',
'exponent' : 'Exponent of the aperiodic component.',
Expand All @@ -30,7 +31,8 @@
)


# Knee
## AP - Knee Mode

params_knee = ParamDefinition(OrderedDict({
'offset' : 'Offset of the aperiodic component.',
'knee' : 'Knee of the aperiodic component.',
Expand All @@ -50,8 +52,9 @@
)


# Double exponent
params_double_exp = ParamDefinition(OrderedDict({
## AP - Double Exponent Mode

params_doublexp = ParamDefinition(OrderedDict({
'offset' : 'Offset of the aperiodic component.',
'exponent0' : 'Exponent of the aperiodic component, before the knee.',
'knee' : 'Knee of the aperiodic component.',
Expand All @@ -64,7 +67,7 @@
description='Fit an function with 2 exponents and a knee.',
func=double_expo_function,
jacobian=None,
params=params_double_exp,
params=params_doublexp,
ndim=1,
freq_space='linear',
powers_space='log10',
Expand All @@ -81,7 +84,8 @@
###################################################################################################
## PERIODIC MODES

# Gaussian
## PE - Gaussian Mode

params_gauss = ParamDefinition(OrderedDict({
'cf' : 'Center frequency of the peak.',
'pw' : 'Power of the peak, over and above the aperiodic component.',
Expand All @@ -101,28 +105,30 @@
)


# Skewed Gaussian
params_skew = ParamDefinition(OrderedDict({
## PE - Skewed Gaussian Mode

params_skewed_gaussian = ParamDefinition(OrderedDict({
'cf' : 'Center frequency of the peak.',
'pw' : 'Power of the peak, over and above the aperiodic component.',
'bw' : 'Bandwidth of the peak.',
'skew' : 'Skewness of the peak.',
}))

pe_skewnorm = Mode(
name='skewnorm',
pe_skewed_gaussian = Mode(
name='skewed_gaussian',
component='periodic',
description='Skewed Gaussian peak fit function.',
func=skewnorm_function,
func=skewed_gaussian_function,
jacobian=None,
params=params_skew,
params=params_skewed_gaussian,
ndim=2,
freq_space='linear',
powers_space='log10',
)


# Cauchy
## PE - Cauchy Mode

params_cauchy = ParamDefinition(OrderedDict({
'cf' : 'Center frequency of the peak.',
'pw' : 'Power of the peak, over and above the aperiodic component.',
Expand All @@ -145,7 +151,7 @@
# Collect available periodic modes
PE_MODES = {
'gaussian' : pe_gaussian,
'skewed_gaussian' : pe_skewnorm,
'skewed_gaussian' : pe_skewed_gaussian,
'cauchy' : pe_cauchy,
}

Expand Down
4 changes: 2 additions & 2 deletions specparam/modes/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def gaussian_function(xs, *params):
return ys


def skewnorm_function(xs, *params):
"""Skewed normal distribution fitting function.
def skewed_gaussian_function(xs, *params):
"""Skewed gaussian fitting function.

Parameters
----------
Expand Down
8 changes: 4 additions & 4 deletions specparam/tests/modes/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ def test_gaussian_function():
assert max(ys) == hgt
assert np.allclose([ii/sum(ys) for ii in ys], norm.pdf(xs, ctr, wid))

def test_skewnorm_function():
def test_skewed_gaussian_function():

# Check that with no skew, approximate gaussian
ctr, hgt, wid, skew = 50, 5, 10, 1
xs = np.arange(1, 100)
ys_gaus = gaussian_function(xs, ctr, hgt, wid)
ys_skew = skewnorm_function(xs, ctr, hgt, wid, skew)
ys_skew = skewed_gaussian_function(xs, ctr, hgt, wid, skew)
np.allclose(ys_gaus, ys_skew, atol=0.001)

# Check with some skew - right skew (more density after center)
skew1 = 2
ys_skew1 = skewnorm_function(xs, ctr, hgt, wid, skew1)
ys_skew1 = skewed_gaussian_function(xs, ctr, hgt, wid, skew1)
assert sum(ys_skew1[xs<ctr]) < sum(ys_skew1[xs>ctr])

# Check with some skew - left skew (more density before center)
skew2 = -2
ys_skew2 = skewnorm_function(xs, ctr, hgt, wid, skew2)
ys_skew2 = skewed_gaussian_function(xs, ctr, hgt, wid, skew2)
assert sum(ys_skew2[xs<ctr]) > sum(ys_skew2[xs>ctr])

def test_cauchy_function():
Expand Down