Browse code

add a doc-string to 'from_combos'

Bas Nijholt authored on 13/06/2018 04:35:09
Showing 1 changed files
... ...
@@ -147,6 +147,44 @@ class BalancingLearner(BaseLearner):
147 147
 
148 148
     @classmethod
149 149
     def from_combos(cls, f, learner_type, learner_kwargs, combos):
150
+        """Create a `BalancingLearner` with learners of all combinations of
151
+        named variables’ values.
152
+
153
+        Parameters
154
+        ----------
155
+        f : callable
156
+            Function to learn, must take arguments provided in in `combos`.
157
+        learner_type : BaseLearner
158
+            The learner that should wrap the function. For example `Learner1D`.
159
+        learner_kwargs : dict
160
+            Keyword argument for the `learner_type`. For example `dict(bounds=[0, 1])`.
161
+        combos : dict (mapping individual fn arguments -> sequence of values)
162
+            For all combinations of each argument a learner will be instantiated.
163
+
164
+        Returns
165
+        -------
166
+        learner : `BalancingLearner`
167
+            A `BalancingLearner` with learners of all combinations of `combos`
168
+
169
+        Example
170
+        -------
171
+        >>> def f(x, n, alpha, beta):
172
+        ...     return scipy.special.eval_jacobi(n, alpha, beta, x)
173
+
174
+        >>> combos = {
175
+        ...     'n': [1, 2, 4, 8, 16],
176
+        ...     'alpha': np.linspace(0, 2, 3),
177
+        ...     'beta': np.linspace(0, 1, 5),
178
+        ... }
179
+
180
+        >>> learner = BalancingLearner.from_combos(
181
+        ...     f, Learner1D, dict(bounds=(0, 1)), combos)
182
+
183
+        Notes
184
+        -----
185
+        The order of the child learners inside `learner.learners` is the same
186
+        as `adaptive.utils.named_product(**combos)`.
187
+        """
150 188
         learners = []
151 189
         for combo in named_product(**combos):
152 190
             learner = learner_type(partial(f, **combo), **learner_kwargs)