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

340 interface additional cf returns #343

Merged
merged 10 commits into from
Sep 1, 2022

Conversation

tensionhead
Copy link
Contributor

@tensionhead tensionhead commented Aug 29, 2022

Make use of additional cF returns

  • Granger now returns 4 additional metadata entries stored in .info documenting the factorization
  • equality of frequency axis for mtmfft and csd get checked via hashes
  • Further refactored process_metadata to reduce copied code and have one place where the properties get attached from input to output (propagate_properties)

closes #148
closes #340

Author Guidelines

  • Is the change set < 600 lines?
  • Was the code checked for memory leaks/performance bottlenecks?
  • Is the code running locally and on the ESI cluster?
  • Is the code running on all supported platforms?

Reviewer Checklist

  • Are testing routines present?
  • Do parallel loops have a set length and correct termination conditions?
  • Do objects in the global package namespace perform proper parsing of their input?
  • Do code-blocks provide novel functionality, i.e., no re-factoring using builtin/external packages possible?
  • Code layout
    • Is the code PEP8 compliant?
    • Does the code adhere to agreed-upon naming conventions?
    • Are keywords clearly named and easy to understand?
    • No commented-out code?
  • Are all docstrings complete and accurate?
  • Is the CHANGELOG.md up to date?

- we have to parse and serialize 0-dim arrays it seems

Changes to be committed:
	modified:   syncopy/nwanalysis/AV_compRoutines.py
	modified:   syncopy/nwanalysis/connectivity_analysis.py
	modified:   syncopy/nwanalysis/granger.py
	modified:   syncopy/nwanalysis/wilson_sf.py
	modified:   syncopy/shared/metadata.py
	modified:   syncopy/tests/backend/test_conn.py
Changes to be committed:
	modified:   syncopy/shared/metadata.py
Changes to be committed:
	modified:   syncopy/nwanalysis/AV_compRoutines.py
	modified:   syncopy/shared/metadata.py
	modified:   syncopy/tests/test_connectivity.py
- no complicated trialdefinition needed a keeptrials=False is enforced
in frontend

Changes to be committed:
	modified:   syncopy/nwanalysis/ST_compRoutines.py
	modified:   syncopy/nwanalysis/connectivity_analysis.py
Changes to be committed:
	modified:   syncopy/specest/compRoutines.py
- further beefed up `propagate_properties` to improve DRY
- single-trial cross-spectra frequency hashes now also get checked

Changes to be committed:
	modified:   syncopy/nwanalysis/AV_compRoutines.py
	modified:   syncopy/nwanalysis/ST_compRoutines.py
	modified:   syncopy/nwanalysis/csd.py
	modified:   syncopy/preproc/compRoutines.py
	modified:   syncopy/shared/computational_routine.py
	modified:   syncopy/shared/metadata.py
	modified:   syncopy/specest/compRoutines.py
	modified:   syncopy/tests/test_connectivity.py
	modified:   syncopy/tests/test_specest.py
- renaming is hard..

Changes to be committed:
	modified:   syncopy/preproc/compRoutines.py
@dfsp-spirit dfsp-spirit self-assigned this Aug 29, 2022
Changes to be committed:
	modified:   syncopy/nwanalysis/ST_compRoutines.py
	modified:   syncopy/tests/backend/test_conn.py
	modified:   syncopy/tests/backend/test_fooofspy.py
- I should play the lottery..

Changes to be committed:
	modified:   syncopy/tests/backend/test_fooofspy.py
@codecov
Copy link

codecov bot commented Aug 29, 2022

Codecov Report

Merging #343 (9582dd0) into dev (55934ac) will decrease coverage by 0.42%.
The diff coverage is 82.97%.

@@            Coverage Diff             @@
##              dev     #343      +/-   ##
==========================================
- Coverage   69.09%   68.66%   -0.43%     
==========================================
  Files          77       77              
  Lines        8850     8870      +20     
  Branches     1816     1823       +7     
==========================================
- Hits         6115     6091      -24     
- Misses       2319     2351      +32     
- Partials      416      428      +12     
Impacted Files Coverage Δ
syncopy/shared/metadata.py 79.67% <51.72%> (-8.87%) ⬇️
syncopy/shared/computational_routine.py 81.10% <78.57%> (-0.43%) ⬇️
syncopy/nwanalysis/wilson_sf.py 94.20% <85.71%> (+1.44%) ⬆️
syncopy/nwanalysis/AV_compRoutines.py 73.58% <100.00%> (+7.17%) ⬆️
syncopy/nwanalysis/ST_compRoutines.py 89.58% <100.00%> (+1.12%) ⬆️
syncopy/nwanalysis/connectivity_analysis.py 73.45% <100.00%> (ø)
syncopy/nwanalysis/csd.py 86.95% <100.00%> (-1.05%) ⬇️
syncopy/nwanalysis/granger.py 100.00% <100.00%> (ø)
syncopy/preproc/compRoutines.py 86.77% <100.00%> (ø)
syncopy/specest/compRoutines.py 88.33% <100.00%> (-2.85%) ⬇️
... and 8 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

out.trialdefinition = trl
else:
out.trialdefinition = np.array([[0, 1, 0]])
check_freq_hashes(metadata, out)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea to put this into a function

@@ -1019,15 +1019,14 @@ def process_metadata(self, data, out):

# --- metadata helper functions ---

def propagate_metadata(in_data, out_data):
def propagate_properties(in_data, out_data, keeptrials=True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice, this reduces quite a bit code duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, it's still not perfect imho.. I could also think of putting those property mappings into the respective module compRoutines.py, however there is already quite some crossover between freqanalysis and connectivityanalysis for example.

CSDreg, fac, iniCN = regularize_csd(CSD, cond_max=cmax, nSteps=25)
# get initial CSD condition number, which is way too large!
print(iniCN)
assert iniCN > cmax
Copy link
Collaborator

@dfsp-spirit dfsp-spirit Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: could be nice to use 2nd arg of assert statement to print better error here, like

assert iniCN > cmax, f"some message about var {var} here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I've seen this only in your code now.. did not know this is possible, but good idea 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puh, there was definitely something off in any case.. I corrected it, still not sure how often ill conditioned CSDs appear in the wild 😅
But at least now we know at least aposteriori what the factorization/regularization did thanks to the additional cF returns :)

@dfsp-spirit
Copy link
Collaborator

Looks good,

only 2 things:

  • the changelog should be updated
  • do you want to document the new Granger return values in the docstrings of the frontend, so that the users know about them?

@tensionhead
Copy link
Contributor Author

tensionhead commented Aug 30, 2022

About your 2nd point regarding the docstring of the frontend, I now think we should programmatically fix/define the key's which are propagated from the CR/cF to .info. Then also Sphinx can pick them up easily via :data: syncopy.nwanalysis..., but for now I 'hardcoded' the .info keys into the frontend doc.
EDIT: made an issue #345

- corrected regularization test
- increased maximal Granger regularization parameter to 0.1
- updated Changelog
- added .info Granger returns to frontend doc

Changes to be committed:
	modified:   CHANGELOG.md
	modified:   syncopy/nwanalysis/AV_compRoutines.py
	modified:   syncopy/nwanalysis/connectivity_analysis.py
	modified:   syncopy/tests/backend/test_conn.py
@tensionhead
Copy link
Contributor Author

I also added the changelog entries for the additional fooof returns, which are also new right :) ?! Feel free to edit/change!

@dfsp-spirit dfsp-spirit merged commit cc880e6 into dev Sep 1, 2022
@tensionhead tensionhead deleted the 340-interface-additional-cf-returns branch September 1, 2022 08:58
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