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

Spectrum analysis of datasets. #193

Merged
merged 8 commits into from
Aug 11, 2023

Conversation

Robertboy18
Copy link
Member

I have pushed a script for analyzing the spectrum of a given dataset. This script performs a comprehensive analysis of the frequency components present in the data, providing valuable insights into understanding the difficulty of the dataset by analyzing its frequency spectrum.

For example, the script below calculates the spectrum of the Darcy flow dataset. Comments have been added for a more general setup as well.

Thank you!

Copy link
Member

@JeanKossaifi JeanKossaifi left a comment

Choose a reason for hiding this comment

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

Thank you @Robertboy18, great to have! Added a few comments.

dataset_name = "Darcy Flow"

# %%
HOME_PATH = '/home/user/'
Copy link
Member

Choose a reason for hiding this comment

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

@Robertboy18 this will not work for users - better to just use the builtin dataset for this, as in https://github.com/neuraloperator/neuraloperator/blob/main/examples/plot_FNO_darcy.py

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense, will load the dataset directly then!

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, the issue is that we need to load the dataset in its raw format (so .pt, .mat, .zarr etc) to get the full spectrum; we cannot use the data loaders! I can leave a comment asking the user to change the HOME_PATH as 'neuraloperator/neuralop/datasets/data/darcy_test_16.pt' this path is the direct link to the raw format dataset.

Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it!

"""
T = u.shape[0]
u = u.reshape(T, s, s)
# u = torch.rfft(u, 2, normalized=False, onesided=False) - depending on your choice of normalization and such
Copy link
Member

Choose a reason for hiding this comment

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

Can we make these options in the function rather than a comment here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!


# 2d wavenumbers following Pytorch fft convention
k_max = s // 2
wavenumers = torch.cat((torch.arange(start=0, end=k_max, step=1), \
Copy link
Member

Choose a reason for hiding this comment

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

Can we do everything in pytorch instead of going back and forth pytorch <-> numpy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that is a good suggestion.

@JeanKossaifi JeanKossaifi merged commit 8c56ed9 into neuraloperator:main Aug 11, 2023
1 check passed
@JeanKossaifi
Copy link
Member

Thank you @Robertboy18, looks great, merging!

ziqi-ma pushed a commit to ziqi-ma/neuraloperator that referenced this pull request Aug 29, 2023
Adds Spectrum analysis function and example.
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.

None yet

2 participants