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

[Feature] Decay functions #594

Merged
merged 8 commits into from
Dec 12, 2023
Merged

Conversation

FBruzzesi
Copy link
Collaborator

@FBruzzesi FBruzzesi commented Nov 6, 2023

Description

Introduces built-in decay functions as discussed in #581

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected): Fixes [FEATURE] Decay functions #581

Checklist:

  • My code follows the style guidelines (flake8)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (also to the readme.md)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added tests to check whether the new feature adheres to the sklearn convention
  • New and existing unit tests pass locally with my changes

Comment on lines 143 to 144
self.n_steps = n_steps
self.step_size = step_size
Copy link
Collaborator Author

@FBruzzesi FBruzzesi Nov 6, 2023

Choose a reason for hiding this comment

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

Not a huge fan of this implementation and how it has to be handled in the .__call__(). Looking for advice 😊

Copy link
Owner

@koaning koaning Nov 6, 2023

Choose a reason for hiding this comment

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

I'm not sure what you're referring to here. You mean the ValueErrors? Is there a reason why they can't be handled here in __init__?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are correct. Every check could be performed in the __init__; my mind just switches to sklearn framework when working on the project, and no checking is done in classes initialization.

What I am not a huge fan is having no default values at all and two mutually exclusive parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved validation to __init__

sklego/meta/_decay_utils.py Outdated Show resolved Hide resolved
trf = DecayEstimator(LinearRegression(), check_input=True)
@pytest.mark.parametrize("decay_func", ["exponential", "linear", "sigmoid"])
def test_estimator_checks_regression(test_fn, decay_func):
trf = DecayEstimator(LinearRegression(), decay_func=decay_func, check_input=True)
test_fn(DecayEstimator.__name__, trf)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't manage to change default values in ln22 and ln 29 as well.

@@ -0,0 +1,272 @@
import numpy as np
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we add check for min_value to be strictly positive? Estimators will handle that anyway, I would say it is redundant

Copy link
Owner

Choose a reason for hiding this comment

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

In general: if there's an opportunity to make a better error message than the library under the hood it may be worth the investment. In this case, it might help to explain to the user why, given the context of what a decay function is supposed to do.

Then again, it's also ok not to add an error message for every little thing that might go wrong as well. It's a balance. Feel free to omit if you prefer :)

@FBruzzesi FBruzzesi marked this pull request as ready for review November 7, 2023 08:32
def test_exponential_decay(kwargs, context):
X, y = np.random.randn(100, 10), np.random.randn(100)

with context:
Copy link
Owner

Choose a reason for hiding this comment

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

TIL about does_not_raise(). Nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I love such trick to save on number of test function 😉

Copy link
Owner

@koaning koaning left a comment

Choose a reason for hiding this comment

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

I guess the main thing that's missing here is perhaps a docs page with plots of all of these decay functions?

I'll leave it up to @FBruzzesi to determine if it's best to add that later given the big push on the docs. But I'd imagine without those docs people may omit this new feature, which would be a shame.

@FBruzzesi
Copy link
Collaborator Author

I guess the main thing that's missing here is perhaps a docs page with plots of all of these decay functions?

I'll leave it up to @FBruzzesi to determine if it's best to add that later given the big push on the docs. But I'd imagine without those docs people may omit this new feature, which would be a shame.

In order we could:

  • Merge doc PRs (whenever ready)
  • Add proper user guide/documentation for this feature in this PR
  • Finally merge this PR as well

@koaning
Copy link
Owner

koaning commented Nov 29, 2023

@FBruzzesi just merged the docs. Feel free to continue on this thread again. I'll try to figure out a nice docs deployment setup from my machine in the meantime.

@FBruzzesi
Copy link
Collaborator Author

Ready for review!

  • Switched from classes to functions to have a unified "api" when passing and calling a custom function
  • Added section called Decay Functions in the Meta Models user guide
  • Added API section for the functions as their signature may be useful to anyone who wants to tinker with values

@koaning koaning merged commit 3a01968 into koaning:main Dec 12, 2023
7 checks passed
@FBruzzesi FBruzzesi deleted the feature/decay-functions branch December 12, 2023 14:45
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.

[FEATURE] Decay functions
2 participants