-
Notifications
You must be signed in to change notification settings - Fork 11
Fourier #300
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
base: development
Are you sure you want to change the base?
Fourier #300
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.
Just some minor requested changes about the docstrings and tests.
- Looks like a lot of minor changes in the basis tests -- is that to make sure that the window size is big enough for the Fourier Conv basis?
- Also some line-wrapping -- did the version of black change or something?
- I think we should add tests that check the relationship with FFT.
- 🔵 Conv | ||
|
||
* - **Fourier Basis** | ||
- .. plot:: scripts/basis_figs.py plot_fourier_basis |
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.
this image looks like a mess -- is there a more informative way to plot it?
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 plotting fewer frequencies would help
n_frequencies : | ||
The number of frequencies for the Fourier basis. | ||
include_constant: | ||
Include the constant term, which corresponds to 0 frequency. Default is False. |
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.
Include the constant term, which corresponds to 0 frequency. Default is False. | |
Include the constant term, which corresponds to 0 frequency. |
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.
don't describe defaults in docstring -- it's already in signature
self, | ||
n_frequencies: int, | ||
include_constant: bool = False, | ||
phase_sign: int = 1, |
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.
not described in docstring
|
||
@property | ||
def phase_sign(self): | ||
"""Read-only phase sign property.""" |
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.
"""Read-only phase sign property.""" |
doesn't add anything.
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.
(so either remove, or make it more descriptive and add some for the other properties as well)
By default, ``phase_sign = 1``, which corresponds to the standard orthonormal Fourier basis. | ||
Setting ``phase_sign = -1`` inverts the sign of the phase angle and aligns the basis | ||
with the Discrete Fourier Transform (DFT) convention. With such convention the convolution | ||
with this basis yields the FFT time evolution. |
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.
"FFT time evolution"? is that the right word?
And do we have a test for this?
\text{phase_sign} \cdot \sin(2\pi k x), & \text{otherwise} | ||
\end{cases} | ||
|
||
By default, ``phase_sign = -1``, which aligns the basis with the Discrete Fourier Transform (DFT) |
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.
remove "default" and should probably be identical to the description in FourierEval
\text{phase_sign} \cdot \sin(2\pi k x), & \text{otherwise} | ||
\end{cases} | ||
|
||
By default, ``phase_sign = 1``, which corresponds to the standard orthonormal Fourier basis. |
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.
remove "default"
conv_kwargs: | ||
Additional keyword arguments passed to :func:`nemos.convolve.create_convolutional_predictor`; | ||
These arguments are used to change the default behavior of the convolution. | ||
For example, changing the ``predictor_causality``, which by default is set to ``"causal"``. |
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.
again, remove default
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.
and should probably have an example of how to do this in doctest
@@ -2607,6 +2670,106 @@ def test_samples_range_matches_compute_features_requirements( | |||
basis_obj.compute_features(np.linspace(*sample_range, 100)) | |||
|
|||
|
|||
class TestFourierBasis(BasisFuncsTesting): |
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 test window size is too small for Nyquist
trans_bas_b.n_frequencies = 3 | ||
assert bas_b.n_frequencies == 5 |
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.
what's going on 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.
as in, why does it the transformer basis have more frequencies than the non-transformer one?
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.
Looking great! I have a few comments on missing test cases, and I think the Fourier basis docstring could use a little more information
- 🔵 Conv | ||
|
||
* - **Fourier Basis** | ||
- .. plot:: scripts/basis_figs.py plot_fourier_basis |
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 plotting fewer frequencies would help
src/nemos/basis/_fourier_basis.py
Outdated
n_frequencies: int, | ||
include_constant: bool = False, | ||
phase_sign: int = 1, | ||
label: Optional[str] = "RaisedCosineBasisLinear", |
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.
label: Optional[str] = "RaisedCosineBasisLinear", | |
label: Optional[str] = "Fourier", |
HistoryConv, | ||
IdentityEval, | ||
TransformerBasis, | ||
) | ||
from nemos.basis._basis import ( |
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.
The tests test_expected_output_eval_on_grid
,test_expected_output_compute_features
, test_expected_output_split_by_feature
are missing cases for Fourier
basis.CyclicBSplineConv: "'mylabel': CyclicBSplineConv(n_basis_funcs=5, window_size=11, order=4)", | ||
basis.MSplineConv: "'mylabel': MSplineConv(n_basis_funcs=5, window_size=11, order=4)", | ||
basis.OrthExponentialConv: "'mylabel': OrthExponentialConv(n_basis_funcs=5, window_size=11)", | ||
basis.HistoryConv: "'mylabel': HistoryConv(window_size=11)", |
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.
no expected output here for Fourier
|
||
|
||
class FourierBasis(Basis, AtomicBasisMixin, abc.ABC): | ||
"""Fourier Basis. |
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 this give a little more of a description? The other basis functions have more than this
Yes, the window size in many of the tests was too small for the nyqst check of the basis, so I had to make sure that the check passed.
Yes, black was upgraded. I am calling
I will, good call |
|
Add a Fourier basis.
This PR adds a Fourier basis. The API is as follows: