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

kwargs for compute_extreme_point(lmo, direction)? #399

Open
gdalle opened this issue Jun 28, 2023 · 2 comments
Open

kwargs for compute_extreme_point(lmo, direction)? #399

gdalle opened this issue Jun 28, 2023 · 2 comments

Comments

@gdalle
Copy link
Contributor

gdalle commented Jun 28, 2023

For our use case in InferOpt.jl, we sometimes need to pass keyword arguments to the LMO. This is not allowed by FrankWolfe.jl, so I wrote a wrapper that predefines the kwargs with the LMO itself:

struct LMOWithKwargs{F,K} <: FrankWolfe.LinearMinimizationOracle
    minimizer::F
    minimizer_kwargs::K
end

LMOWithKwargs(minimizer) = LMOWithKwargs(minimizer, NamedTuple())

function FrankWolfe.compute_extreme_point(
    lmo::LMOWithKwargs, direction; kwargs...
)
    (; minimizer, minimizer_kwargs) = lmo
    v = minimizer(direction; minimizer_kwargs...)
    return v
end

Is there a more clever way to do this?

@matbesancon
Copy link
Member

if you always pass the same kwargs to the LMO, why not set them as parameters of the LMO struct itself?

@gdalle
Copy link
Contributor Author

gdalle commented Jun 28, 2023

That's exactly what I'm doing here (I edited the code above). But typically in InferOpt one might want to solve maximization problems on many different instances, passed as keyword arguments. So currently I re-create an LMO every time.
Basically I was wondering if something like this would make sense to you:

function frank_wolfe(..., lmo, ...; ..., lmo_kwargs, ...)
    for iteration in 1:n
        ...
        vertex = compute_extreme_point(lmo, direction, lmo_kwargs...)
        ...
    end
end

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