4 | import Data.ScientificNotation
5 | import Data.Materialise
9 | runActionUntilMaxSteps : Materialise p =>
10 | ScientificDisplay p => ScientificDisplay l =>
11 | {default 100 printEvery : Nat} ->
12 | (action : p -> IO p) ->
14 | (currentStep : Nat) -> (currentValue : p) ->
15 | (loss : p -> IO l) ->
17 | runActionUntilMaxSteps action maxSteps currStep currVal lossIO
18 | = go (minus maxSteps currStep) currStep currVal
21 | stepWidth = length (show maxSteps)
24 | rule = dim (String.replicate 50 '─')
26 | go : (remaining : Nat) -> (step : Nat) -> p -> IO p
30 | putStrLn " Max steps (\{bold (show maxSteps)}) reached."
31 | putStrLn " \{dim "Final loss: "} \{yellow (showSci loss)}"
32 | putStrLn " \{dim "Final params: "} \{cyan (showSci val)}"
35 | go (S k) step val = do
36 | runIf (step `mod` printEvery == 0 || step < 10) $
do
38 | putStrLn " \{dim "step"} \{bold (padLeft stepWidth ' ' (show step))} \{dim "│ loss"} \{yellow (showSci loss)}"
39 | result <- action val
41 | go k (S step) (materialise result)