-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add observer pattern to implement callbacks #109
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #109 +/- ##
==========================================
+ Coverage 82.87% 82.97% +0.09%
==========================================
Files 4 5 +1
Lines 292 323 +31
Branches 35 38 +3
==========================================
+ Hits 242 268 +26
- Misses 45 49 +4
- Partials 5 6 +1
Continue to review full report at Codecov.
|
|
Looks promising! Any reason not to merge this? @fmfn |
|
@Erotemic can you maybe have a quick glance at this? (I was just looking at the contributor list, hope it's ok that I wrote to you specifically!) |
|
I'm by no means an authority on this repo, but I can offer a code review. After a quick glance, it does look fine to me. Functionality it looks like it works, and the code organization isn't bad. However I might make a few style suggestions. Feel free to consider them or ignore them.
class Events(object):
INIT_DONE = 'initialized'
FIT_STEP_DONE = 'fit_step_done'
FIT_DONE = 'fit_done'This makes it so the events are clearly grouped. They can then be used like I think the above changes would make the code slightly more readable, but the code also looks merge-able in its current state. |
|
Thanks for the review @Erotemic. Both your suggestions are valid, I thought about that, but didn't want to clutter the slim folder structure. Still you are right, this would help code quality. I will update my contribution. |
|
This is awesome, I really like it, just have a couple questions.
Thanks for the PR! |
|
On 1: Yes, I started a review where I requested that those were removed. On 3: From what I understand the Observer is supposed to be a parent object. You can see that On 2: I would actually suggest against this. Because those events belong to the |
|
Thanks for the review!
|
|
Ok, I was talking about As for the location of The only thing left before this is merged is to clean the commits a bit. @aprams could you rebase and squash these down 1-2 commits with a good description? |
|
@fmfn I added references in init.py to have Events and Observer publicly accessible. |
Adds a simple observer pattern, allowing callbacks.
Currently implemented callbacks:
Sample code (taken from exploitation vs exploration (UCB kappa=1.0 cell) sample for readability):
Output:
The observer instance is notified via update(self, event, instance), giving it all the flexibility it needs, not limiting any user specific use cases, as you save the results so far already in self.res.
I saw the PR #100, this is basically an advanced version as you requested. I am open for changes to this.