Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 63
fix problem when learner has no more points for BalancingLearner#214
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
884674a2fedb39091d8178a798f794645b3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -119,27 +119,34 @@ def strategy(self, strategy): | ||
| ' strategy="npoints", or strategy="cycle" is implemented.' | ||
| ) | ||
| def _ask_all_learners(self, total_points): | ||
| to_select = [] | ||
| for index, learner in enumerate(self.learners): | ||
| # Take the points from the cache | ||
| if index not in self._ask_cache: | ||
| self._ask_cache[index] = learner.ask(n=1, tell_pending=False) | ||
| points, loss_improvements = self._ask_cache[index] | ||
| if not points: # cannot ask for more points | ||
| return to_select | ||
| to_select.append( | ||
| ((index, points[0]), (loss_improvements[0], -total_points[index])) | ||
| ) | ||
| return to_select | ||
| def _ask_and_tell_based_on_loss_improvements(self, n): | ||
| selected = [] # tuples ((learner_index, point), loss_improvement) | ||
| total_points = [l.npoints + len(l.pending_points) for l in self.learners] | ||
| for _ in range(n): | ||
| to_select = [] | ||
| for index, learner in enumerate(self.learners): | ||
| # Take the points from the cache | ||
| if index not in self._ask_cache: | ||
| self._ask_cache[index] = learner.ask(n=1, tell_pending=False) | ||
| points, loss_improvements = self._ask_cache[index] | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here one would need a double break, but because that doesn't exist I make it into a function. | ||
| to_select.append( | ||
| ((index, points[0]), (loss_improvements[0], -total_points[index])) | ||
| ) | ||
| to_select = self._ask_all_learners(total_points) | ||
| if not to_select: # cannot ask for more points | ||
| break | ||
| # Choose the optimal improvement. | ||
| (index, point), (loss_improvement, _) = max(to_select, key=itemgetter(1)) | ||
| total_points[index] += 1 | ||
| selected.append(((index, point), loss_improvement)) | ||
| self.tell_pending((index, point)) | ||
| points, loss_improvements = map(list, zip(*selected)) | ||
| points, loss_improvements = map(list, zip(*selected)) if selected else [], [] | ||
| return points, loss_improvements | ||
| def _ask_and_tell_based_on_loss(self, n): | ||
| @@ -156,11 +163,12 @@ def _ask_and_tell_based_on_loss(self, n): | ||
| if index not in self._ask_cache: | ||
| self._ask_cache[index] = self.learners[index].ask(n=1) | ||
| points, loss_improvements = self._ask_cache[index] | ||
| if not points: # cannot ask for more points | ||
| break | ||
| selected.append(((index, points[0]), loss_improvements[0])) | ||
| self.tell_pending((index, points[0])) | ||
| points, loss_improvements = map(list, zip(*selected)) | ||
| points, loss_improvements = map(list, zip(*selected)) if selected else [], [] | ||
| return points, loss_improvements | ||
| def _ask_and_tell_based_on_npoints(self, n): | ||
| @@ -172,11 +180,13 @@ def _ask_and_tell_based_on_npoints(self, n): | ||
| if index not in self._ask_cache: | ||
| self._ask_cache[index] = self.learners[index].ask(n=1) | ||
| points, loss_improvements = self._ask_cache[index] | ||
| if not points: # cannot ask for more points | ||
| break | ||
| total_points[index] += 1 | ||
| selected.append(((index, points[0]), loss_improvements[0])) | ||
| self.tell_pending((index, points[0])) | ||
| points, loss_improvements = map(list, zip(*selected)) | ||
| points, loss_improvements = map(list, zip(*selected)) if selected else [], [] | ||
| return points, loss_improvements | ||
| def _ask_and_tell_based_on_cycle(self, n): | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of things I don't understand here:
returnshould be acontinue; just because learnericould not give any more points does not mean that no other learners can give any!learner.ask(1)is guaranteed to return a point. At the moment there is no way for a learner to indicate that it has "no more points". If a learner returns no points then it is in violation of the API and other stuff is liable to break