This package is a python wrapper for FrankWolfe.jl.
First, download the package frankwolfe-py.
Move to the root of the package and execute on a terminal the following command:
pip install .
Now you can use the FrankWolfe.jl functions with
from frankwolfepy import frankwolfe
and the wrapper of the objective function with
from frankwolfepy import wrapper
Each objective function must be wrapped if the algorithm is used with verbose=true
.
In each file, import wrapper and wrap the objective function using:
f = wrapper.wrap_objective_function(f).
A simple example :
from frankwolfepy import frankwolfe
from frankwolfepy import wrapper
import numpy as np
def f(x): #objective function
return np.linalg.norm(x)**2
f = wrapper.wrap_objective_function(f) #wrap the objective function
def grad(storage,x): #gradient computation
for i in range(len(x)):
storage[i] = x[i]
# Create the Linear Minimization Oracle
lmo_prob = frankwolfe.ProbabilitySimplexOracle(1)
# Compute first point
x0 = frankwolfe.compute_extreme_point(lmo_prob,np.zeros(5))
#Solve the optimisation problem using vanilla Frank-Wolfe algorithm
frankwolfe.frank_wolfe(
f,
grad,
lmo_prob,
x0,
max_iteration=1000,
line_search=frankwolfe.Agnostic(),
verbose=True,
)
For documentation on FrankWolfe.jl: https://zib-iol.github.io/FrankWolfe.jl/dev/
The most flexible way to wrap Julia expressions is through seval
which returns the result of evaluating a string as Julia code.
This lets you for instance use type parameters like Vector{Int}
or FrankWolfe.LpNormLMO{1}
:
import juliacall
lmo = juliacall.Main.seval("FrankWolfe.LpNormLMO{1}(0.95)")