To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

This notebook takes about 30 seconds to run.

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
👀 Reading hidden code
using Plots
3.8 s
👀 Reading hidden code
using PlutoUI
92.4 ms
train (generic function with 1 method)
👀 Reading hidden code
function train()
sleep(.1) # fake
end
374 μs

This is how you would compute 10 epochs in a standalone script:

👀 Reading hidden code
200 μs
👀 Reading hidden code
begin
errors1 = Float64[]
for epoch in 1:10
ϵ = 1.0 / epoch # fake
push!(errors1, ϵ)
end
end
1.0 s
👀 Reading hidden code
plot(errors1, xlabel="epoch", ylabel="error")
3.5 s

The plot only gets generated when the previous cell has finished, i.e. when all epochs have been computed.

👀 Reading hidden code
264 μs

More interactive

👀 Reading hidden code
189 μs

Instead, you could split the code into cells, and use a Button to drive evaluations.

👀 Reading hidden code
226 μs
errors2 = Float64[]
👀 Reading hidden code
16.5 μs
@bind advance_epoch PlutoUI.Button("Advance epoch 🖐")
👀 Reading hidden code
222 ms
"🥔"
begin
advance_epoch # reference the variable to make this cell react to it
let
epoch = length(errors2) + 1

train()
ϵ = 1.0 / epoch # fake
push!(errors2, ϵ)
end
epoch_done = "🥔"
end
👀 Reading hidden code
101 ms
let
epoch_done # reference the variable to make this cell react to it
plot(errors2, xlabel="epoch", ylabel="error")
end
👀 Reading hidden code
674 μs

The array errors2 is only assigned to once, initialising it to the empty array. We later use push! to add elements non-reactively - Pluto doesn't track value changes (such as x[2] = 456), it only tracks variable assingments (such as x = [123, 456]).

To make sure that the plot gets updated, we assign to a dummy variable, epoch_done. Because this is a regular global assignment, it will be reactive.

👀 Reading hidden code
423 μs