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

[WIP] - Add explicit {aperiodic, periodic} 'Modes' support #298

Open
wants to merge 233 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
233 commits
Select commit Hold shift + click to select a range
946b01b
first round updates to use fit modes
TomDonoghue Aug 7, 2023
d23fa59
temporarily turn off IO related tests
TomDonoghue Aug 7, 2023
f4edc40
acess param inds from Mode object
TomDonoghue Aug 10, 2023
8a015f8
clean ups
TomDonoghue Aug 10, 2023
5c2ce37
update modes orgs & add n_params
TomDonoghue Aug 10, 2023
f4c35d2
add periodic_mode as a passable input
TomDonoghue Aug 10, 2023
88cdd0a
group_three -> groupby
TomDonoghue Aug 10, 2023
42af5bc
generalize processes for number of params (including temp updates)
TomDonoghue Aug 10, 2023
280b382
add labels to funcs file
TomDonoghue Aug 14, 2023
8c9b5b1
add double exp function
TomDonoghue Aug 14, 2023
7f2bd95
add normalize util func
TomDonoghue Aug 14, 2023
8eb27ad
add skewed gaussian fit function
TomDonoghue Aug 14, 2023
5f0cca3
add new modes
TomDonoghue Aug 14, 2023
d046a3c
add docs to Mode object
TomDonoghue Aug 14, 2023
bf3944d
start process new bounds / guess funcs
TomDonoghue Aug 20, 2023
d06b9de
Merge branch 'basemodel' into modes
TomDonoghue Sep 13, 2023
7663b91
Merge branch 'main' into modes
TomDonoghue Feb 15, 2024
ac1d71b
fix merge
TomDonoghue Apr 9, 2024
9609cf1
Merge branch 'basemodel' into modes
TomDonoghue Apr 10, 2024
90f0bea
Merge branch 'main' into modes
TomDonoghue Aug 3, 2024
a839bd1
Merge branch 'main' into modes
TomDonoghue Nov 28, 2024
83a30cc
Merge branch 'main' into modes
TomDonoghue Mar 7, 2025
63ef803
fix merge
TomDonoghue Mar 9, 2025
d846649
fix merge
TomDonoghue Mar 11, 2025
e58722b
fix merge
TomDonoghue Mar 12, 2025
42a1972
fix ap guess var name
TomDonoghue Mar 12, 2025
400a959
fix obj init for time objects
TomDonoghue Mar 12, 2025
3e6756e
temporarily turn off IO tests
TomDonoghue Mar 12, 2025
80d6b83
reopen IO tests
TomDonoghue Mar 12, 2025
9634ddf
fix merge
TomDonoghue Mar 12, 2025
d703935
fix merge - reports separate
TomDonoghue Mar 12, 2025
43627ca
turn off IO tests
TomDonoghue Mar 12, 2025
b6f9ed9
move core fit stuff -> modes
TomDonoghue Mar 12, 2025
5beaa1e
move & fix links for core -> modes
TomDonoghue Mar 12, 2025
066bf1c
move modes definitions
TomDonoghue Mar 12, 2025
6109383
Merge branch 'main' into modes
TomDonoghue Mar 12, 2025
a3f807e
move normalize to other PR
TomDonoghue Mar 12, 2025
a8087ea
Merge branch 'main' into modes
TomDonoghue Mar 12, 2025
3aec756
fix merge
TomDonoghue Mar 12, 2025
aac58e0
Merge branch 'main' into modes
TomDonoghue Mar 12, 2025
c1125a2
fix merge
TomDonoghue Mar 13, 2025
76aaf1b
Merge branch 'main' into modes
TomDonoghue Mar 13, 2025
4965323
Merge branch 'main' into modes
TomDonoghue Mar 14, 2025
e732947
Merge branch 'main' into modes
TomDonoghue Mar 14, 2025
e42f425
drop core sub-module
TomDonoghue Mar 16, 2025
e2269bc
separate out algorithms sub-module
TomDonoghue Mar 16, 2025
5367276
move modes object to modes
TomDonoghue Mar 16, 2025
3c8d777
add test for Mode obj
TomDonoghue Mar 16, 2025
2b8c280
move model objects to own sub-module
TomDonoghue Mar 16, 2025
be5435e
add jacobian to modes definition
TomDonoghue Mar 16, 2025
76853b0
use jacobian from modes in fit
TomDonoghue Mar 16, 2025
ea9b1ff
add cauchy PE definition
TomDonoghue Mar 16, 2025
cce78bd
move tests for models utils
TomDonoghue Mar 16, 2025
73dea37
add eq dunder to Mode
TomDonoghue Mar 16, 2025
33afe40
fix mode checks
TomDonoghue Mar 16, 2025
7f941eb
turn IO tests back on
TomDonoghue Mar 16, 2025
df022db
split out modes from settings
TomDonoghue Mar 16, 2025
391b7b6
fix saving for modes
TomDonoghue Mar 16, 2025
d8b31d4
update strings for separating settings / modes
TomDonoghue Mar 16, 2025
ef347f9
add print_modes
TomDonoghue Mar 16, 2025
689f2a2
turn model obj load tests back on
TomDonoghue Mar 16, 2025
d9d684b
fix up some doc copying
TomDonoghue Mar 16, 2025
f671855
interim update resetting results
TomDonoghue Mar 16, 2025
8d75eea
move fit from results -> base
TomDonoghue Mar 17, 2025
d6b4a23
move fit methods to base
TomDonoghue Mar 17, 2025
913b403
move out fit methods & par from results
TomDonoghue Mar 17, 2025
65503b4
add utils for objs operations
TomDonoghue Mar 17, 2025
6fd2559
use obj utils in base
TomDonoghue Mar 17, 2025
2d324b2
reorg objs utils file
TomDonoghue Mar 17, 2025
2164701
add skip_if_no_tqdm for tests
TomDonoghue Mar 17, 2025
5eb7387
add objs utils tests
TomDonoghue Mar 17, 2025
614a6c4
update base to manage more of model fit process
TomDonoghue Mar 17, 2025
08d7178
reduce to specific algo elements
TomDonoghue Mar 17, 2025
c089935
reorg measures & error
TomDonoghue Mar 17, 2025
95a3a80
refactor GOF compute
TomDonoghue Mar 17, 2025
9edfe72
interim update object docstrings
TomDonoghue Mar 18, 2025
2a08de3
remove mode from debug
TomDonoghue Mar 18, 2025
5699c70
remove mode from checks
TomDonoghue Mar 18, 2025
e3d4694
remove run modes
TomDonoghue Mar 18, 2025
650abdb
add check_input_options
TomDonoghue Mar 18, 2025
95f025c
add checks for initialize a Mode
TomDonoghue Mar 18, 2025
d01bb20
step back from infer_ap
TomDonoghue Mar 19, 2025
0933200
add ParamDefinition object
TomDonoghue Mar 19, 2025
f971b0b
use ParamDefinition
TomDonoghue Mar 19, 2025
2ad2eaf
update definitions to use ParamDefiniton
TomDonoghue Mar 19, 2025
2be351c
tweak Mode spacing definition
TomDonoghue Mar 19, 2025
ab10aee
drop _reset_results from algo object
TomDonoghue Mar 19, 2025
4cef7ed
add base algorithm & algodef objects
TomDonoghue Mar 19, 2025
1db8470
add SettingsDefinition object
TomDonoghue Mar 19, 2025
9c7d912
use SettingsDef in Algorithm object
TomDonoghue Mar 19, 2025
5342e31
update use of Algo object
TomDonoghue Mar 19, 2025
188bf94
add algo def test
TomDonoghue Mar 19, 2025
4a97711
update docs indices to check for sections
TomDonoghue Mar 19, 2025
0c29531
update algo settings docstring management
TomDonoghue Mar 19, 2025
470cc82
interim update: clean up algo order & dont store temp elements
TomDonoghue Mar 21, 2025
1508a51
update to _fit_prechecks
TomDonoghue Mar 21, 2025
9f5de2e
update ap guess / bounds for modes
TomDonoghue Mar 22, 2025
83f3e18
move settings from Results -> Algorithm
TomDonoghue Mar 22, 2025
26f22da
move algo settings to own file
TomDonoghue Mar 22, 2025
aea71d5
move verbose out from results (to base)
TomDonoghue Mar 22, 2025
6d49cc6
add Modes object
TomDonoghue Mar 22, 2025
f74b1de
lints & fixes
TomDonoghue Mar 22, 2025
bf1093d
make check_mode own func
TomDonoghue Mar 22, 2025
39a95c9
use Modes
TomDonoghue Mar 22, 2025
ef8a0d6
move to using Data object attribute
TomDonoghue Mar 22, 2025
2ade775
drop core test folder
TomDonoghue Mar 22, 2025
acfe049
move Results to attribute
TomDonoghue Mar 23, 2025
84292b7
add get_modes
TomDonoghue Mar 23, 2025
9511692
use get_modes
TomDonoghue Mar 23, 2025
97f08b1
add stricter load tests - check obj dirs
TomDonoghue Mar 23, 2025
c3ace21
rename conflicting get_model -> get_component
TomDonoghue Mar 23, 2025
d71c64c
add metrics
TomDonoghue Mar 23, 2025
eb36957
update metrics
TomDonoghue Mar 23, 2025
3f0d5df
remove metrics from results
TomDonoghue Mar 23, 2025
9e55b9f
add Metrics to base
TomDonoghue Mar 23, 2025
6eea9d4
interim update: alias metrics to results
TomDonoghue Mar 23, 2025
748d891
add indexing to Metrics
TomDonoghue Mar 23, 2025
9498554
misc updates for metrics
TomDonoghue Mar 23, 2025
dc82a14
move Algorithm to it's own attribute
TomDonoghue Mar 24, 2025
1541b77
lints
TomDonoghue Mar 24, 2025
665a983
udpate / consolidate for getting initialized object
TomDonoghue Mar 24, 2025
fc906d3
add initialize_model_from_source util func
TomDonoghue Mar 24, 2025
59df03a
use initialize model from source func
TomDonoghue Mar 24, 2025
229e2ab
update get_modes to use data object
TomDonoghue Mar 24, 2025
32cf001
update initialize from to copy modes
TomDonoghue Mar 24, 2025
66ff9d5
Merge pull request #354 from fooof-tools/objb
TomDonoghue Mar 24, 2025
353e8d6
move sub-object inits to model objs
TomDonoghue Mar 25, 2025
f25020d
consolidate print methods on CommonBase
TomDonoghue Mar 25, 2025
1797c18
deprecate Base1D -> move to model obj
TomDonoghue Mar 25, 2025
6592d8b
deprecate Base2D & move to model obj
TomDonoghue Mar 25, 2025
252609b
drop bsae objects for time / event - revert to inheritance
TomDonoghue Mar 25, 2025
ec4e87c
clear old base stuff
TomDonoghue Mar 25, 2025
5d9f79d
CommonBase -> BaseModel
TomDonoghue Mar 25, 2025
b65643c
clean up models objs
TomDonoghue Mar 25, 2025
be8a452
udpate BaseModel for Modes
TomDonoghue Mar 25, 2025
e98ef0e
update Algorithm definition sub-object
TomDonoghue Mar 25, 2025
b30ec70
update algo def
TomDonoghue Mar 25, 2025
4ea282c
use new algo to not re-initialiez
TomDonoghue Mar 25, 2025
d5e9592
update algo docstrings
TomDonoghue Mar 25, 2025
aba0f16
add algorithm defintions
TomDonoghue Mar 25, 2025
766b63e
lints
TomDonoghue Mar 25, 2025
3b6619d
update algo for managing custom settings
TomDonoghue Mar 25, 2025
7f79048
test settings from algo def not OBJ_DESC
TomDonoghue Mar 25, 2025
0d64ba6
add fields def to results & use instead of OBJ_DESC
TomDonoghue Mar 25, 2025
b3e2abb
add data object fields and use instead of OBJ_DESC
TomDonoghue Mar 25, 2025
e9c0f17
remove use of OBJ_DESC
TomDonoghue Mar 25, 2025
1a90cbb
finish deprecation of OBJ_DESC
TomDonoghue Mar 25, 2025
62b4dbd
remove get_description
TomDonoghue Mar 25, 2025
3c542e3
drop get_info
TomDonoghue Mar 25, 2025
58da1bc
remove modes/info
TomDonoghue Mar 25, 2025
97b7002
update metrics
TomDonoghue Mar 25, 2025
abd32c4
deprecate AlgorithmDefinition
TomDonoghue Mar 26, 2025
e117d3c
udpate settings report to use algo info
TomDonoghue Mar 26, 2025
92792d1
udpate model fit results str
TomDonoghue Mar 26, 2025
ffff339
update group report for modes
TomDonoghue Mar 26, 2025
b365cd5
update time model str
TomDonoghue Mar 26, 2025
99e15aa
update event report
TomDonoghue Mar 26, 2025
2ed5691
add bands attribute to results objects
TomDonoghue Mar 26, 2025
2aca752
deprecate linking bands to attributes
TomDonoghue Mar 26, 2025
bd1e203
use results.bands in model strings
TomDonoghue Mar 26, 2025
6623d7f
reorg report strings
TomDonoghue Apr 1, 2025
2be8fba
update report strings
TomDonoghue Apr 1, 2025
2963620
add data format to algo
TomDonoghue Apr 1, 2025
34b7dab
add format to Data objects
TomDonoghue Apr 1, 2025
6619777
drop verbose from algo object
TomDonoghue Apr 1, 2025
71d0452
rework fit prechecks
TomDonoghue Apr 1, 2025
112ff34
update motivations for changes
TomDonoghue Apr 2, 2025
aa39d72
tweak init
TomDonoghue Apr 2, 2025
0a12fed
consolidate get_params onto Results
TomDonoghue Apr 2, 2025
8d2ad61
interim update of exmaples for updates
TomDonoghue Apr 2, 2025
2c115ac
interim update of tutorials for updates
TomDonoghue Apr 2, 2025
3c9e83a
alias in get_params method
TomDonoghue Apr 2, 2025
5afba0e
interim update API
TomDonoghue Apr 2, 2025
d364f87
add n_params_ to results
TomDonoghue Apr 3, 2025
8ee34c1
add keyword access to metrics
TomDonoghue Apr 3, 2025
6f52f69
interim: move metrics to Results
TomDonoghue Apr 3, 2025
81d833c
add metrics library
TomDonoghue Apr 3, 2025
e3a2553
interim: initialize metrics on Results
TomDonoghue Apr 3, 2025
ba7b8ec
replace default metrics method
TomDonoghue Apr 3, 2025
4f5e1f9
add / propagate metrics selection
TomDonoghue Apr 3, 2025
a2629a5
fix error labels
TomDonoghue Apr 3, 2025
87feb00
update model report metrics printing
TomDonoghue Apr 4, 2025
34ca118
update plt inputs
TomDonoghue Apr 4, 2025
b445e95
add find_first_ind
TomDonoghue Apr 4, 2025
e1ed3fd
add flabels
TomDonoghue Apr 4, 2025
662ae92
fix model plts for metrics
TomDonoghue Apr 4, 2025
dd363b3
generalize plots for modes
TomDonoghue Apr 4, 2025
dbfdc02
extend & tweaks Metric(s)
TomDonoghue Apr 4, 2025
f0a6484
drop get_band_labels
TomDonoghue Apr 4, 2025
98214a1
update reports save for modes
TomDonoghue Apr 4, 2025
b8d5f21
drop get_periodic_labels
TomDonoghue Apr 4, 2025
dda6c64
update / extend model utils for metrics
TomDonoghue Apr 4, 2025
fa6a836
interim results update - _make_fit_results method
TomDonoghue Apr 5, 2025
e8ecec0
work through Metrics & FitResults updates
TomDonoghue Apr 5, 2025
0f1e4c6
add tests for custom metrics
TomDonoghue Apr 5, 2025
7c26365
use modes in data conversions
TomDonoghue Apr 5, 2025
a62b419
remove get_ap_indices
TomDonoghue Apr 5, 2025
8a01fc1
remove get_peak_indices
TomDonoghue Apr 5, 2025
e48fc8d
use modes in get * params funcs
TomDonoghue Apr 5, 2025
20151ec
remove get_indices
TomDonoghue Apr 5, 2025
f522661
remove empty modes/info files
TomDonoghue Apr 5, 2025
1dd50e9
fix imports
TomDonoghue Apr 5, 2025
bdeee01
turn off doctests for now
TomDonoghue Apr 5, 2025
3df5965
use modes in param plots
TomDonoghue Apr 6, 2025
6dc4657
use mode funcs in plt anot peak search
TomDonoghue Apr 6, 2025
96b2ec1
work through sim for modes
TomDonoghue Apr 6, 2025
b354002
remove get *funcs
TomDonoghue Apr 6, 2025
5ec47cf
finish removing sim AP inference
TomDonoghue Apr 6, 2025
1bd4082
remove infer_ap_func
TomDonoghue Apr 6, 2025
20f9496
modified FitResults
TomDonoghue Apr 6, 2025
69f50cd
update FitResults for Metrics
TomDonoghue Apr 6, 2025
206c4e4
turn par back on after FitResults updates
TomDonoghue Apr 6, 2025
826fafe
interim updates for Bands
TomDonoghue Apr 6, 2025
9b121ac
update use of bands in to_df
TomDonoghue Apr 6, 2025
22c6ac7
allow model obj init of bands
TomDonoghue Apr 6, 2025
ab1b248
fix group get_model bug
TomDonoghue Apr 7, 2025
d2eb05d
add eq dunder to bands
TomDonoghue Apr 7, 2025
0f5b386
add bands to test objects
TomDonoghue Apr 7, 2025
4ff8145
enforce tuple type for band def
TomDonoghue Apr 7, 2025
a1bee95
update saving for modes & bands
TomDonoghue Apr 7, 2025
051d2ee
fix up IO for time / event with bands
TomDonoghue Apr 7, 2025
44717a8
update loading of custom objects
TomDonoghue Apr 7, 2025
33822e0
rework adding / loading modes
TomDonoghue Apr 7, 2025
36f6211
add back metrics IO tests and fix
TomDonoghue Apr 7, 2025
f24a607
lints
TomDonoghue Apr 8, 2025
ac49384
update properties for no results / readability
TomDonoghue Apr 8, 2025
5ac3d0d
fix up measures funcs
TomDonoghue Apr 8, 2025
a0e9aa0
update process for additional kwargs to metrics
TomDonoghue Apr 8, 2025
a40d819
test lints
TomDonoghue Apr 8, 2025
2dfc5ba
drop make_data_object func
TomDonoghue Apr 8, 2025
df49143
clean up string help func for avg over time
TomDonoghue Apr 8, 2025
f1f5dc7
drop get_freq_ind
TomDonoghue Apr 8, 2025
7b88a9d
add tests with custom modes / metrics & fix for this
TomDonoghue Apr 8, 2025
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
16 changes: 6 additions & 10 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Object Utilities

Functions to manipulate, examine, and analyze model objects.

.. currentmodule:: specparam.objs
.. currentmodule:: specparam.models

.. autosummary::
:toctree: generated/
Expand All @@ -65,14 +65,9 @@ Functions to manipulate, examine, and analyze model objects.
combine_model_objs
average_group
average_reconstructions

.. currentmodule:: specparam

.. autosummary::
:toctree: generated/

fit_models_3d


Data Objects
------------

Expand Down Expand Up @@ -102,8 +97,9 @@ Objects to store settings, metadata and results for power spectrum models.
:template: data_object.rst

SpectrumMetaData
ModelModes
ModelSettings
ModelRunModes
ModelChecks
FitResults

Simulation Parameters
Expand Down Expand Up @@ -163,7 +159,7 @@ Functions for analyzing the error of model fits.

The following functions take in model objects directly.

.. currentmodule:: specparam.measures.error
.. currentmodule:: specparam.measures.pointwise

.. autosummary::
:toctree: generated/
Expand All @@ -175,7 +171,7 @@ The following functions take in model objects directly.

The following functions operate on arrays of models and data, which may be useful for more custom work-flows.

.. currentmodule:: specparam.measures.error
.. currentmodule:: specparam.measures.pointwise

.. autosummary::
:toctree: generated/
Expand Down
63 changes: 34 additions & 29 deletions examples/analyses/plot_dev_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from specparam.plts.aperiodic import plot_aperiodic_params, plot_aperiodic_fits

# Import functions to examine frequency-by-frequency error of model fits
from specparam.measures.error import compute_pointwise_error, compute_pointwise_error_group
from specparam.measures.pointwise import compute_pointwise_error, compute_pointwise_error_group

# Import helper utility to access data
from specparam.utils.download import fetch_example_data
Expand Down Expand Up @@ -127,12 +127,12 @@
###################################################################################################

# Access the model fit parameters from the model object
print('Aperiodic parameters: \n', fm.aperiodic_params_, '\n')
print('Peak parameters: \n', fm.peak_params_, '\n')
print('Aperiodic parameters: \n', fm.results.aperiodic_params_, '\n')
print('Peak parameters: \n', fm.results.peak_params_, '\n')
print('Goodness of fit:')
print('Error - ', fm.error_)
print('R^2 - ', fm.r_squared_, '\n')
print('Number of fit peaks: \n', fm.n_peaks_)
print('Error - ', fm.results.error_)
print('R^2 - ', fm.results.r_squared_, '\n')
print('Number of fit peaks: \n', fm.results.n_peaks_)

###################################################################################################
#
Expand Down Expand Up @@ -181,15 +181,16 @@
plt_log = False

# Do an initial aperiodic fit - a robust fit, that excludes outliers
init_ap_fit = gen_aperiodic(fm.freqs, fm._robust_ap_fit(fm.freqs, fm.power_spectrum))
init_ap_fit = gen_aperiodic(\
fm.data.freqs, fm.algorithm._robust_ap_fit(fm.data.freqs, fm.data.power_spectrum))

# Recompute the flattened spectrum using the initial aperiodic fit
init_flat_spec = fm.power_spectrum - init_ap_fit
init_flat_spec = fm.data.power_spectrum - init_ap_fit

###################################################################################################

# Plot the flattened the power spectrum
plot_spectra(fm.freqs, init_flat_spec, plt_log, label='Flattened spectrum', color='black')
plot_spectra(fm.data.freqs, init_flat_spec, plt_log, label='Flattened spectrum', color='black')

###################################################################################################
#
Expand Down Expand Up @@ -247,7 +248,7 @@

# Note that the average of this error is the same as the global error stored
print('Average freq-by-freq error:\t {:1.3f}'.format(np.mean(errs_fm)))
print('Total model fit error: \t\t {:1.3f}'.format(fm.error_))
print('Total model fit error: \t\t {:1.3f}'.format(fm.results.error_))

###################################################################################################
# Fitting a Group of Power Spectra
Expand Down Expand Up @@ -329,7 +330,7 @@
###################################################################################################

# Check the average number of fit peaks, per model
print('Average number of fit peaks: ', np.mean(fg.n_peaks_))
print('Average number of fit peaks: ', np.mean(fg.results.n_peaks_))

###################################################################################################

Expand All @@ -341,9 +342,9 @@
###################################################################################################

# Extract band-limited peaks information
thetas = get_band_peak_group(fg, bands.theta)
alphas = get_band_peak_group(fg, bands.alpha)
betas = get_band_peak_group(fg, bands.beta)
thetas = get_band_peak_group(fg, bands['theta'])
alphas = get_band_peak_group(fg, bands['alpha'])
betas = get_band_peak_group(fg, bands['beta'])

###################################################################################################
#
Expand Down Expand Up @@ -377,7 +378,7 @@
# Plot reconstructions of model components
_, axes = plt.subplots(1, 2, figsize=(14, 6))
plot_peak_fits(alphas, ax=axes[0])
plot_aperiodic_fits(aps, fg.freq_range, ax=axes[1])
plot_aperiodic_fits(aps, fg.data.freq_range, ax=axes[1])

###################################################################################################
# Tuning the specparam algorithm
Expand Down Expand Up @@ -424,6 +425,9 @@
m1_peak_height = 0.05
m2_peak_height = 0.10

# Define `` for both models
peak_threshold = 2.0

###################################################################################################
#
# Next, we set frequency ranges for each model.
Expand Down Expand Up @@ -455,7 +459,7 @@
fg1.fit(m1_freq, m1_spectra)

# Create individual reports for model 1 settings (these could be saved and checked)
for ind in range(len(fg1)):
for ind in range(len(fg1.results)):
temp_model = fg1.get_model(ind, regenerate=True)

###################################################################################################
Expand All @@ -471,7 +475,7 @@
fg2.fit(m2_freq, m2_spectra)

# Create individual reports for model 2 settings (these could be saved and checked)
for ind in range(len(fg2)):
for ind in range(len(fg2.results)):
temp_model = fg2.get_model(ind, regenerate=True)

###################################################################################################
Expand All @@ -486,19 +490,20 @@

# Define settings for model 1
settings1 = ModelSettings(peak_width_limits=m1_peak_width, max_n_peaks=m1_n_peaks,
min_peak_height=m1_peak_height, peak_threshold=2.,
aperiodic_mode='fixed')
min_peak_height=m1_peak_height, peak_threshold=peak_threshold)

# Define settings for model 2
settings2 = ModelSettings(peak_width_limits=m2_peak_width, max_n_peaks=m2_n_peaks,
min_peak_height=m2_peak_height, peak_threshold=2.,
aperiodic_mode='fixed')
min_peak_height=m2_peak_height, peak_threshold=peak_threshold)

# Define aperiodic mode to use
aperiodic_mode = 'fixed'

###################################################################################################

# Initialize model objects for spectral parameterization, with some settings
fg1 = SpectralGroupModel(**settings1._asdict())
fg2 = SpectralGroupModel(**settings2._asdict())
fg1 = SpectralGroupModel(**settings1._asdict(), aperiodic_mode=aperiodic_mode)
fg2 = SpectralGroupModel(**settings2._asdict(), aperiodic_mode=aperiodic_mode)

###################################################################################################
#
Expand Down Expand Up @@ -562,7 +567,7 @@
# Extract all fits that are above some error threshold, for further examination.
underfit_error_threshold = 0.100
underfit_check = []
for ind, res in enumerate(fg):
for ind, res in enumerate(fg.results):
if res.error > underfit_error_threshold:
underfit_check.append(fg.get_model(ind, regenerate=True))

Expand All @@ -582,7 +587,7 @@
# Extract all fits that are below some error threshold, for further examination.
overfit_error_threshold = 0.02
overfit_check = []
for ind, res in enumerate(fg):
for ind, res in enumerate(fg.results):
if res.error < overfit_error_threshold:
overfit_check.append(fg.get_model(ind, regenerate=True))

Expand Down Expand Up @@ -641,25 +646,25 @@
errs_fg = compute_pointwise_error_group(fg, plot_errors=False, return_errors=True)

# Check which frequency has the highest error
f_max_err = fg.freqs[np.argmax(np.mean(errs_fg, 0))]
f_max_err = fg.data.freqs[np.argmax(np.mean(errs_fg, 0))]
print('Frequency with highest mean error: \t\t\t', f_max_err)

# Check which frequency has the largest standard deviation of error
f_max_std = fg.freqs[np.argmax(np.std(errs_fg, 0))]
f_max_std = fg.data.freqs[np.argmax(np.std(errs_fg, 0))]
print('Frequency with highest standard deviation of error: \t', f_max_std)

###################################################################################################
#
# In some cases, it may be necessary to drop poor (or failed) model fits from the group object.
# This can be done using the `fg.drop` function, as shown here.
# This can be done using the `fg.results.drop` function, as shown here.
# In this case, we remove a participant who has a MAE greater than 0.10.
# The error threshold will vary depending on sample characteristics and data quality.
#

###################################################################################################

# Drop poor model fits based on MAE
fg.drop(fg.get_params('error') > 0.10)
fg.results.drop(fg.get_params('error') > 0.10)

###################################################################################################
# Conclusions
Expand Down
8 changes: 4 additions & 4 deletions examples/analyses/plot_mne_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def check_nans(data, nan_policy='zero'):
###################################################################################################

# Extract alpha peaks
alphas = get_band_peak_group(fg, bands.alpha)
alphas = get_band_peak_group(fg, bands['alpha'])

# Extract the power values from the detected peaks
alpha_pw = alphas[:, 1]
Expand Down Expand Up @@ -282,10 +282,10 @@ def check_nans(data, nan_policy='zero'):
# Compare the power spectra between low and high exponent channels
fig, ax = plt.subplots(figsize=(8, 6))

spectra = [fg.get_model(np.argmin(exps)).power_spectrum,
fg.get_model(np.argmax(exps)).power_spectrum]
spectra = [fg.get_model(np.argmin(exps)).data.power_spectrum,
fg.get_model(np.argmax(exps)).data.power_spectrum]

plot_spectra(fg.freqs, spectra, ax=ax, labels=['Low Exponent', 'High Exponent'])
plot_spectra(fg.data.freqs, spectra, ax=ax, labels=['Low Exponent', 'High Exponent'])

###################################################################################################
# Conclusion
Expand Down
10 changes: 5 additions & 5 deletions examples/manage/plot_failed_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
###################################################################################################

# Check for failed model fits
print('Number of Null models : \t', fg.n_null_)
print('Indices of Null models : \t', fg.null_inds_)
print('Number of Null models : \t', fg.results.n_null_)
print('Indices of Null models : \t', fg.results.null_inds_)

###################################################################################################
# Inducing Model Fit Failures
Expand Down Expand Up @@ -102,8 +102,8 @@
###################################################################################################

# Check how many model fit failures we have failed model fits
print('Number of Null models : \t', fg.n_null_)
print('Indices of Null models : \t', fg.null_inds_)
print('Number of Null models : \t', fg.results.n_null_)
print('Indices of Null models : \t', fg.results.null_inds_)

###################################################################################################
# Debug Mode
Expand All @@ -130,7 +130,7 @@
###################################################################################################

# Set SpectralGroupModel into debug mode
fg.set_debug_mode(True)
fg.algorithm.set_debug(True)

###################################################################################################

Expand Down
2 changes: 1 addition & 1 deletion examples/manage/plot_fit_models_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from specparam import SpectralGroupModel

# Import utilities for working with model objects
from specparam.objs import fit_models_3d, combine_model_objs
from specparam.models import fit_models_3d, combine_model_objs

# Import simulation & IO utilities to help with the example
from specparam.sim import sim_group_power_spectra
Expand Down
22 changes: 11 additions & 11 deletions examples/manage/plot_manipulating_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from specparam.bands import Bands

# Import utility functions for working with model objects
from specparam.objs.utils import average_group, combine_model_objs, compare_model_objs
from specparam.models.utils import average_group, combine_model_objs, compare_model_objs

# Import simulation functions to create our example data
from specparam.sim import sim_power_spectrum
Expand Down Expand Up @@ -87,7 +87,7 @@

# Check the number of models in the object
# Note that the length of a SpectralGroupModel object is defined as the number of model fits
print('Number of model fits: ', len(fg))
print('Number of model fits: ', len(fg.results))

###################################################################################################
# Note on Manipulating Model Objects
Expand Down Expand Up @@ -141,7 +141,7 @@
nfg = fg.get_group(inds)

# Check how many models our new SpectralGroupModel object contains
print('Number of model fits: ', len(nfg))
print('Number of model fits: ', len(nfg.results))

###################################################################################################
#
Expand All @@ -154,7 +154,7 @@
# -------------------------------------
#
# Another option is to 'drop' model fits from a SpectralGroupModel object. You can do this with
# the :meth:`~specparam.SpectralGroupModel.drop` method from a
# the :meth:`~specparam.SpectralGroupModel.results.drop` method from a
# :class:`~specparam.SpectralGroupModel` object.
#
# This can be used, for example, for a quality control step. If you have checked through
Expand All @@ -168,7 +168,7 @@
###################################################################################################

# Drop all model fits above an error threshold
fg.drop(fg.get_params('error') > 0.01)
fg.results.drop(fg.get_params('error') > 0.01)

###################################################################################################
# Note on Dropped or Failed Fits
Expand All @@ -186,25 +186,25 @@
###################################################################################################

# Check information on null models (dropped models)
print('Number of Null models : \t', fg.n_null_)
print('Indices of Null models : \t', fg.null_inds_)
print('Number of Null models : \t', fg.results.n_null_)
print('Indices of Null models : \t', fg.results.null_inds_)

# Despite the dropped model, the total number of models in the object is the same
# This means that the indices are still the same as before dropping models
print('Number of model fits: ', len(fg))
print('Number of model fits: ', len(fg.results))

###################################################################################################

# Null models are defined as all NaN (not a number)
for ind in fg.null_inds_:
print(fg[ind])
for ind in fg.results.null_inds_:
print(fg.results[ind])

###################################################################################################
# Note on Selecting from SpectralModel Objects
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Both the :meth:`~specparam.SpectralGroupModel.get_group` and
# :meth:`~specparam.SpectralGroupModel.drop` methods take an input of the indices of the
# :meth:`~specparam.SpectralGroupModel.results.drop` methods take an input of the indices of the
# model(s) to select or drop.
#
# In both cases, the input can be defined in multiple ways, including directly indicating
Expand Down
Loading