Skip to content

Commit

Permalink
implement 'strategy' setter such that it can be changed dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Oct 15, 2018
1 parent 722f61a commit 197b56f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions adaptive/learner/balancing_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class BalancingLearner(BaseLearner):
The points that the 'BalancingLearner' choses can be either based on:
the best 'loss_improvements', the smallest total 'loss' of the
child learners, or the number of points per learner, using 'npoints'.
One can dynamically change the strategy while the simulation is
running by changing the 'learner.strategy' attribute.
Notes
-----
Expand Down Expand Up @@ -69,6 +71,15 @@ def __init__(self, learners, *, cdims=None, strategy='loss_improvements'):
raise TypeError('A BalacingLearner can handle only one type'
' of learners.')

self.strategy = strategy

@property
def strategy(self):
return self._strategy

@strategy.setter
def strategy(self, strategy):
self._strategy = strategy
if strategy == 'loss_improvements':
self._ask_and_tell = self._ask_and_tell_based_on_loss_improvements
elif strategy == 'loss':
Expand Down

0 comments on commit 197b56f

Please sign in to comment.