👀 Reading hidden code
using Plots
👀 Reading hidden code
using PlutoUI
train (generic function with 1 method)
👀 Reading hidden code
function train()
sleep(.1) # fake
end
This is how you would compute 10 epochs in a standalone script:
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
The plot only gets generated when the previous cell has finished, i.e. when all epochs have been computed.
👀 Reading hidden code
More interactive
👀 Reading hidden code
Instead, you could split the code into cells, and use a Button
to drive evaluations.
👀 Reading hidden code
errors2 = Float64[]
👀 Reading hidden code
@bind advance_epoch PlutoUI.Button("Advance epoch 🖐")
👀 Reading hidden code
"🥔"
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
let
epoch_done # reference the variable to make this cell react to it
plot(errors2, xlabel="epoch", ylabel="error")
end
👀 Reading hidden code
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