@@ -22,7 +22,7 @@ class BalancingLearner(BaseLearner):
2222
2323 Parameters
2424 ----------
25- learners : sequence of `BaseLearner`
25+ learners : sequence of `~adaptive. BaseLearner`\s
2626 The learners from which to choose. These must all have the same type.
2727 cdims : sequence of dicts, or (keys, iterable of values), optional
2828 Constant dimensions; the parameters that label the learners. Used
@@ -42,6 +42,13 @@ class BalancingLearner(BaseLearner):
4242 >>> cdims = (['A', 'B'], [(True, 0), (True, 1),
4343 ... (False, 0), (False, 1)])
4444
45+ Attributes
46+ ----------
47+ learners : list
48+ The sequence of `~adaptive.BaseLearner`\s.
49+ function : callable
50+ A function that calls the functions of the underlying learners.
51+ Its signature is ``function(learner_index, point)``.
4552 strategy : 'loss_improvements' (default), 'loss', or 'npoints'
4653 The points that the `BalancingLearner` choses can be either based on:
4754 the best 'loss_improvements', the smallest total 'loss' of the
@@ -51,13 +58,13 @@ class BalancingLearner(BaseLearner):
5158
5259 Notes
5360 -----
54- This learner compares the ' loss' calculated from the "child" learners.
61+ This learner compares the ` loss` calculated from the "child" learners.
5562 This requires that the 'loss' from different learners *can be meaningfully
5663 compared*. For the moment we enforce this restriction by requiring that
5764 all learners are the same type but (depending on the internals of the
5865 learner) it may be that the loss cannot be compared *even between learners
59- of the same type*. In this case the `BalancingLearner` will behave in an
60- undefined way.
66+ of the same type*. In this case the `~adaptive. BalancingLearner` will
67+ behave in an undefined way. Change the `strategy` in that case .
6168 """
6269
6370 def __init__ (self , learners , * , cdims = None , strategy = 'loss_improvements' ):
@@ -81,6 +88,12 @@ def __init__(self, learners, *, cdims=None, strategy='loss_improvements'):
8188
8289 @property
8390 def strategy (self ):
91+ """Can be either 'loss_improvements' (default), 'loss', or 'npoints'
92+ The points that the `BalancingLearner` choses can be either based on:
93+ the best 'loss_improvements', the smallest total 'loss' of the
94+ child learners, or the number of points per learner, using 'npoints'.
95+ One can dynamically change the strategy while the simulation is
96+ running by changing the ``learner.strategy`` attribute."""
8497 return self ._strategy
8598
8699 @strategy .setter
@@ -122,7 +135,7 @@ def _ask_and_tell_based_on_loss(self, n):
122135 points = []
123136 loss_improvements = []
124137 for _ in range (n ):
125- losses = self .losses (real = False )
138+ losses = self ._losses (real = False )
126139 max_ind = np .argmax (losses )
127140 xs , ls = self .learners [max_ind ].ask (1 )
128141 points .append ((max_ind , xs [0 ]))
@@ -165,7 +178,7 @@ def tell_pending(self, x):
165178 self ._loss .pop (index , None )
166179 self .learners [index ].tell_pending (x )
167180
168- def losses (self , real = True ):
181+ def _losses (self , real = True ):
169182 losses = []
170183 loss_dict = self ._loss if real else self ._pending_loss
171184
@@ -178,7 +191,7 @@ def losses(self, real=True):
178191
179192 @cache_latest
180193 def loss (self , real = True ):
181- losses = self .losses (real )
194+ losses = self ._losses (real )
182195 return max (losses )
183196
184197 def plot (self , cdims = None , plotter = None , dynamic = True ):
@@ -215,8 +228,8 @@ def plot(self, cdims=None, plotter=None, dynamic=True):
215228 Returns
216229 -------
217230 dm : `holoviews.core.DynamicMap` (default) or `holoviews.core.HoloMap`
218- A `DynamicMap` (dynamic=True) or `HoloMap` (dynamic=False) with
219- sliders that are defined by `cdims`.
231+ A `DynamicMap` `` (dynamic=True)`` or `HoloMap`
232+ ``(dynamic=False)`` with sliders that are defined by `cdims`.
220233 """
221234 hv = ensure_holoviews ()
222235 cdims = cdims or self ._cdims_default
@@ -295,7 +308,7 @@ def from_product(cls, f, learner_type, learner_kwargs, combos):
295308 Notes
296309 -----
297310 The order of the child learners inside `learner.learners` is the same
298- as `adaptive.utils.named_product(**combos)`.
311+ as `` adaptive.utils.named_product(**combos)` `.
299312 """
300313 learners = []
301314 arguments = named_product (** combos )
@@ -313,7 +326,7 @@ def save(self, folder, compress=True):
313326 folder : str
314327 Directory in which the learners's data will be saved.
315328 compress : bool, default True
316- Compress the data upon saving using ' gzip' . When saving
329+ Compress the data upon saving using ` gzip` . When saving
317330 using compression, one must load it with compression too.
318331
319332 Notes
@@ -364,7 +377,7 @@ def load(self, folder, compress=True):
364377
365378 Example
366379 -------
367- See the example in the ' BalancingLearner.save' doc-string.
380+ See the example in the ` BalancingLearner.save` doc-string.
368381 """
369382 for l in self .learners :
370383 l .load (os .path .join (folder , l .fname ), compress = compress )
0 commit comments