Skip to content

Convergence check for infer functionality #227

Answered by bvdmitri
ThijsvdLaar asked this question in Q&A
Discussion options

You must be logged in to vote

Here is what I cam up with @ThijsvdLaar

struct StopEarlyIterationStrategy
    tolerance::Float64
    fe_values::Vector{Float64}
end

function (strategy::StopEarlyIterationStrategy)(model, niteration)
    current_fe_value = 0.0
    # Subscribe on the `BetheFreeEnergy` stream but only `take(1)` value from it
    subscribe!(score(model, Float64, BetheFreeEnergy()) |> take(1), (v) -> current_fe_value = v)
    # Take the previous value from the saved history, use the large value if the first iteration
    previous_fe_value = isempty(strategy.fe_values) ? 10e5 : last(strategy.fe_values)
    # Save the current value in the history
    push!(strategy.fe_values, current_fe_value)
    # Stop early …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@albertpod
Comment options

@ThijsvdLaar
Comment options

ThijsvdLaar Feb 7, 2024
Collaborator Author

@bvdmitri
Comment options

Answer selected by ThijsvdLaar
@ThijsvdLaar
Comment options

ThijsvdLaar Feb 8, 2024
Collaborator Author

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants