-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add fourier #49
base: main
Are you sure you want to change the base?
Add fourier #49
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should change the parametrization of this new basis, as discussed in my comments, and probably work a bit on how it's explained. I don't have any comments on how it's implemented, looks great.
# ### The Fourier Basis | ||
# Another type of basis available is the Fourier Basis. Fourier basis are ideal to capture periodic and | ||
# quasi-periodic patterns. Such oscillatory, rhythmic behavior is a common signature of many neural signals. | ||
# Additionally, the Fourier basis has the advantage of being orthogonal, which simplifies the estimation and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably explain orthogonal here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still think this. at least a foot note or link
src/nemos/basis.py
Outdated
""" | ||
if self.n_basis_funcs < 1: | ||
raise ValueError( | ||
f"Object class {self.__class__.__name__} requires >= 1 basis elements. " | ||
f"Object class {self.__class__.__name__} requires >= 0 basis elements. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the error message now matches the check, but shouldn't this actually at least 1 basis element? With max_freq=0
(just the DC term), you get a n_basis_funcs=1
. And it doesn't make sense to have max_freq<0
# ### The Fourier Basis | ||
# Another type of basis available is the Fourier Basis. Fourier basis are ideal to capture periodic and | ||
# quasi-periodic patterns. Such oscillatory, rhythmic behavior is a common signature of many neural signals. | ||
# Additionally, the Fourier basis has the advantage of being orthogonal, which simplifies the estimation and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still think this. at least a foot note or link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this parametrization much more. Still have some comments about explanation from the last round that need addressing, and then some small wording suggestions here.
# Note that we are inverting the time axis of the basis because we are aiming | ||
# for a cross-correlation, while np.convolve compute a convolution which would flip the time axis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still think this
# compute the phase and amplitude from the convolution | ||
xcorr_phase = np.arctan2(np.hstack([[0], xcorr[n_freqs:]]), xcorr[:n_freqs]) | ||
xcorr_aplitude = np.sqrt(xcorr[:n_freqs] ** 2 + np.hstack([[0], xcorr[n_freqs:]]) ** 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still think this
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #49 +/- ##
==========================================
+ Coverage 95.02% 95.34% +0.32%
==========================================
Files 10 10
Lines 864 881 +17
==========================================
+ Hits 821 840 +19
+ Misses 43 41 -2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments :)
>>> import nemos as nmo | ||
>>> import numpy as np | ||
>>> n_samples, max_freq = 1000, 10 | ||
>>> basis = nmo.basis.FourierBasis(max_freq) | ||
>>> eval_basis = basis.evaluate(np.linspace(0, 1, n_samples)) | ||
>>> sinusoid = np.cos(3 * np.arange(0, 1000) * np.pi * 2 / 1000.) | ||
>>> conv = [np.convolve(eval_basis[::-1, k], sinusoid, mode='valid')[0] for k in range(2*max_freq+1)] | ||
>>> fft = np.fft.fft(sinusoid) | ||
>>> print('FFT power: ', np.round(np.real(fft[:max_freq]), 4)) | ||
>>> print('Convolution: ', np.round(conv[:max_freq], 4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way in mkdocs to set this as a python codeblock? Can you remove the >>>
? Because right now in the docs the >>>
shows up and when you copy it copies with the >>>
so a user can't just copy and paste and run from the docs 😄
for example at the bottom here the arrows render and get copied: https://nemos.readthedocs.io/en/latest/reference/nemos/utils/#nemos.utils.pytree_map_and_reduce
(sample_pts,) = self._check_evaluate_input(sample_pts) | ||
# assumes equi-spaced samples. | ||
if sample_pts.shape[0] / np.max(self._frequencies) < 2: | ||
raise ValueError("Not enough samples, aliasing likely to occur!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe report sample_pts.shape[0]
and max(self._frequencies)
to the user?
Co-authored-by: William F. Broderick <[email protected]>
Co-authored-by: William F. Broderick <[email protected]>
FourierBasis
to the basis module