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

Move stateful initialization to a pre_fit function #159

Merged
merged 2 commits into from
Sep 16, 2020

Conversation

timokau
Copy link
Collaborator

@timokau timokau commented Sep 16, 2020

Description

Creates a _pre_fit function to bridge the gap between __init__ and fit: Everything which initializes some state, but does not actually depend on the data, belongs there. This separates concerns a bit and makes it possible to inherit those initializations.

I thought about making this an implicit wrapper (a wrapper defined in learner that inherits signature & docs and automatically prepends a call to pre_fit to every fit call). This might be possible with wrapt and a meta-class, but it would be a little complex. Since it would also be less explicit, it might be a bit confusing for people who are not very familiar with the code. So I just went with an explicit call to _pre_fit for now.

I could imagine to automate the calls to initialize_optimizer and initiialize_regularizer in the future, but again I'm not entirely certain its desirable because it would feel a little "magic".

Motivation and Context

#157 (comment)

How Has This Been Tested?

Pre-commit & test suite.

Does this close/impact existing issues?

Impacts #94, #116, #146.

Types of changes

  • 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 change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

Now that some pre_fit initialization is inherited, we can move the
initialization there. This will satisfy the scikit-learn estimator
requirements (__init__ should only store the parameters).
@timokau timokau changed the title Create pre fit Move stateful initialization to a pre_fit function Sep 16, 2020
Copy link
Owner

@kiudee kiudee left a comment

Choose a reason for hiding this comment

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

Looks like a very clean solution. I like it.

@kiudee kiudee merged commit a8e121f into kiudee:master Sep 16, 2020
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.

2 participants