Skip to content

Commit de6eb19

Browse files
committed
add docs for the SequenceLearner
1 parent 53e723a commit de6eb19

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

adaptive/learner/sequence_learner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SequenceLearner(BaseLearner):
5252
Notes
5353
-----
5454
From primitive tests, the `~adaptive.SequenceLearner` appears to have a
55-
similar performance to `ipyparallel`\s `load_balanced_view().map`. With
55+
similar performance to `ipyparallel`\s ``load_balanced_view().map``. With
5656
the added benefit of having results in the local kernel already.
5757
"""
5858

@@ -120,7 +120,7 @@ def done(self):
120120
return not self._to_do_indices and not self.pending_points
121121

122122
def result(self):
123-
"""Get back the data in the same order as ``sequence``."""
123+
"""Get the function values in the same order as ``sequence``."""
124124
if not self.done():
125125
raise Exception("Learner is not yet complete.")
126126
return list(self.data.values())
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
adaptive.SequenceLearner
2+
========================
3+
4+
.. autoclass:: adaptive.SequenceLearner
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/source/reference/adaptive.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Learners
1414
adaptive.learner.learner1D
1515
adaptive.learner.learner2D
1616
adaptive.learner.learnerND
17+
adaptive.learner.sequence_learner
1718
adaptive.learner.skopt_learner
1819

1920
Runners
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Tutorial `~adaptive.SequenceLearner`
2+
---------------------------------
3+
4+
.. note::
5+
Because this documentation consists of static html, the ``live_plot``
6+
and ``live_info`` widget is not live. Download the notebook
7+
in order to see the real behaviour.
8+
9+
.. seealso::
10+
The complete source code of this tutorial can be found in
11+
:jupyter-download:notebook:`tutorial.SequenceLearner`
12+
13+
.. jupyter-execute::
14+
:hide-code:
15+
16+
import adaptive
17+
adaptive.notebook_extension(_inline_js=False)
18+
19+
import holoviews as hv
20+
import numpy as np
21+
22+
This learner will learn a sequence. It simply returns
23+
the points in the provided sequence when asked.
24+
25+
This is useful when your problem cannot be formulated in terms of
26+
another adaptive learner, but you still want to use Adaptive's
27+
routines to run, (periodically) save, and plot.
28+
29+
.. jupyter-execute::
30+
31+
from adaptive import SequenceLearner
32+
33+
def f(x):
34+
return int(x) ** 2
35+
36+
seq = np.linspace(-15, 15, 1000)
37+
learner = SequenceLearner(f, seq)
38+
39+
runner = adaptive.Runner(learner, SequenceLearner.done)
40+
# that goal is same as `lambda learner: learner.done()`
41+
42+
.. jupyter-execute::
43+
:hide-code:
44+
45+
await runner.task # This is not needed in a notebook environment!
46+
47+
.. jupyter-execute::
48+
49+
runner.live_info()
50+
51+
.. jupyter-execute::
52+
53+
def plotter(learner):
54+
data = learner.data if learner.data else []
55+
return hv.Scatter(data)
56+
57+
runner.live_plot(plotter=plotter)
58+
59+
``learner.data`` contains a dictionary that maps the index of the point of ``learner.sequence`` to the value at that point.
60+
61+
To get the values in the same order as the input sequence (``learner.sequence``) use
62+
63+
.. jupyter-execute::
64+
65+
result = learner.result()
66+
print(result[:10]) # print the 10 first values

docs/source/tutorial/tutorial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ We recommend to start with the :ref:`Tutorial `~adaptive.Learner1D``.
4040
tutorial.DataSaver
4141
tutorial.IntegratorLearner
4242
tutorial.LearnerND
43+
tutorial.SequenceLearner
4344
tutorial.SKOptLearner
4445
tutorial.parallelism
4546
tutorial.advanced-topics

0 commit comments

Comments
 (0)