Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Allow state and iterations as arguments in callback #573

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ The callback function `callback` is a function which is called after every optim
step. Its signature is:

```julia
callback = (u, loss_val, other_args) -> false
callback = (u, loss_val, other_args...) -> false
```

where `u` and `loss_val` are the current optimization variables and loss/objective value
in the optimization loop and `other_args` can be the extra things returned from
the optimization `f`. This allows for saving values from the optimization and
using them for plotting and display without recalculating. The callback should
return a Boolean value, and the default should be `false`, such that the optimization
gets stopped if it returns `true`.
the optimization `f` or the state of the optimizer and iteration count. This allows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" or the state of the optimizer and iteration count" what do you mean by that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll refine it. It's a placeholder to make sure I update it as soon as the update happens in the wrappers.

The point is that the callback will have a current state of the optimizer if it's available and iteration counts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how that would work. Wouldn't that need to be an argument? If so, how is that argument uniformized? I don't see a struct definition or docs to go along with that.

for saving values from the optimization and using them for plotting and display without
recalculating. The callback should return a Boolean value, and the default should be `false`,
such that the optimization gets stopped if it returns `true`.

### Callback Example

Here we show an example a callback function that plots the prediction at the current value of the optimization variables.
Here we show an example of a callback function that plots the prediction at the current value of the optimization variables.
The loss function here returns the loss and the prediction i.e. the solution of the `ODEProblem` `prob`, so we can use the prediction in the callback.

```julia
Expand All @@ -76,7 +76,7 @@ function loss(u, p)
sum(abs2, batch .- pred), pred
end

callback = function (p, l, pred; doplot = false) #callback function to observe training
callback = function (p, l, pred, args...; doplot = false) #callback function to observe training
display(l)
# plot current prediction against data
if doplot
Expand Down
Loading