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

Expose standard callback options for datafit #158

Open
ChrisRackauckas opened this issue Apr 12, 2023 · 2 comments
Open

Expose standard callback options for datafit #158

ChrisRackauckas opened this issue Apr 12, 2023 · 2 comments

Comments

@ChrisRackauckas
Copy link
Member

  • Timer-based callback: give a time increment where the callback does its payload based

The callback should calculate:

  • Current loss value
  • Current test value
    • Add a way to pass the test data
  • Current sensitivity values
  • Tolerance to exit
  • Current parameter values
@jClugstor
Copy link
Contributor

Is something like this on the right track? (Very roughly)

struct TimedDatafitCallback
    tolerance
    effect_function
    elapsed
    last_callback::Dates.DateTime
    params
    test_data
end

function TimedDatafitCallback(tolerance, effect_function; elapsed = Dates.Second(5))
    TimeDatafitCallback(tolerance, effect_function, elapsed, ,typemin(Dates.DateTime), Nothing, Nothing)
end

function (cb::TimedDatafitCallback)(p, lossval, args...)
    if lossval ≤ cb.tolerance #maybe just < ?
        return true
   end

    if cb.last_callback + cb.elapsed ≤ Dates.now() 
        return false
    end

    cb.test_data = args[1]
    cb.params = p

    cb.effect_function(p, lossval, args...)

    return false
end

Basically a TimedDatafitCallback struct, with a constructor that takes a tolerance and an effect function, and has a default value for the time elapsed before running the effect function. Then I make the struct callable with the same signature as in https://docs.sciml.ai/Optimization/stable/API/solve/. Then use it as the callback for the Optimizer call inside of datafit. This also depends on having the loss function also return the solution of the ODE though, since that's needed for the signature.

I didn't see any examples of callbacks for Optimizers.jl so this might be completely off.

@ChrisRackauckas
Copy link
Member Author

yup that's on the right track

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants