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

Add new samplers #2913

Merged
merged 7 commits into from
Jun 12, 2023
Merged

Add new samplers #2913

merged 7 commits into from
Jun 12, 2023

Conversation

abdulfatir
Copy link
Contributor

Issue #, if available:

Description of changes:
This PR adds two new samplers: NInstanceSampler and ExpectedNumInstanceWithMinSampler.
NInstanceSampler: sample exactly N time points per time series.
ExpectedNumInstanceWithMinSampler: same as ExpectedNumInstanceSampler but ensures at a minimum number of time points are sampled per time series.

Thanks to @lostella for code and suggestions.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Please tag this pr with at least one of these labels to make our release process faster: BREAKING, new feature, bug fix, other change, dev setup

@abdulfatir abdulfatir requested a review from lostella June 9, 2023 16:12
src/gluonts/transform/sampler.py Outdated Show resolved Hide resolved
@@ -142,6 +162,37 @@ def __call__(self, ts: np.ndarray) -> np.ndarray:
return indices + a


class ExpectedNumInstanceWithMinSampler(ExpectedNumInstanceSampler):
Copy link
Contributor

Choose a reason for hiding this comment

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

I see two ways to escape the naming dilemma here:

  1. Make min_instances: int = 0 (note the default 0) an attribute of ExpectedNumInstanceSampler and add the logic directly there. Then there's no name to be invented. However, strictly speaking when one sets min_instances > 0 then this is not really sampling num_instances on average.
  2. Make this logic a wrapper around some other sampler: sampler = AtLeast(1, ExpectedNumInstanceSampler). The logic is factored a bit better maybe that way, just not as straightforward to instantiate.

Again, no strong opinions, it's just that this names is now a mouthful. @jaheba to the rescue.

Copy link
Contributor

Choose a reason for hiding this comment

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

@abdulfatir let's go for option 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@lostella lostella added the new feature (one of pr required labels) label Jun 9, 2023
Abdul Fatir Ansari added 2 commits June 10, 2023 16:22
src/gluonts/transform/sampler.py Outdated Show resolved Hide resolved
src/gluonts/transform/sampler.py Outdated Show resolved Hide resolved
src/gluonts/transform/sampler.py Outdated Show resolved Hide resolved
@jaheba
Copy link
Contributor

jaheba commented Jun 12, 2023

I think we can just extend the current class with min_instances=0

@abdulfatir
Copy link
Contributor Author

@lostella @jaheba Removed the new class and added min_instances option to the original class.

@lostella lostella added the enhancement New feature or request label Jun 12, 2023
@abdulfatir abdulfatir merged commit 1cc17c1 into awslabs:dev Jun 12, 2023

Parameters
----------
N
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this uppercase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new feature (one of pr required labels)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants