Skip to content

Commit a81be7a

Browse files
authored
add a code example to the examples page (#335)
1 parent 6fded06 commit a81be7a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/source/algorithms_and_examples.rst

+20
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ on the *Play* :fa:`play` button or move the sliders.
5050
`adaptive.Learner1D`
5151
~~~~~~~~~~~~~~~~~~~~
5252

53+
Adaptively learning a 1D function (the plot below) and live-plotting the process in a Jupyter notebook is as easy as
54+
55+
.. code:: python
56+
57+
from adaptive import notebook_extension, Runner, Learner1D
58+
notebook_extension() # enables notebook integration
59+
60+
def peak(x, a=0.01): # function to "learn"
61+
return x + a**2 / (a**2 + x**2)
62+
63+
learner = Learner1D(peak, bounds=(-1, 1))
64+
65+
def goal(learner):
66+
return learner.loss() < 0.01 # continue until loss is small enough
67+
68+
runner = Runner(learner, goal) # start calculation on all CPU cores
69+
runner.live_info() # shows a widget with status information
70+
runner.live_plot()
71+
72+
5373
.. jupyter-execute::
5474
:hide-code:
5575

0 commit comments

Comments
 (0)