Skip to content

Commit

Permalink
add a code example to the examples page (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt authored Sep 27, 2021
1 parent 6fded06 commit a81be7a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/source/algorithms_and_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ on the *Play* :fa:`play` button or move the sliders.
`adaptive.Learner1D`
~~~~~~~~~~~~~~~~~~~~

Adaptively learning a 1D function (the plot below) and live-plotting the process in a Jupyter notebook is as easy as

.. code:: python
from adaptive import notebook_extension, Runner, Learner1D
notebook_extension() # enables notebook integration
def peak(x, a=0.01): # function to "learn"
return x + a**2 / (a**2 + x**2)
learner = Learner1D(peak, bounds=(-1, 1))
def goal(learner):
return learner.loss() < 0.01 # continue until loss is small enough
runner = Runner(learner, goal) # start calculation on all CPU cores
runner.live_info() # shows a widget with status information
runner.live_plot()
.. jupyter-execute::
:hide-code:

Expand Down

0 comments on commit a81be7a

Please sign in to comment.