https://github.com/zib-iol/frankwolfe-py
https://github.com/zib-iol/frankwolfe-py
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/zib-iol/frankwolfe-py
- Owner: ZIB-IOL
- License: apache-2.0
- Created: 2024-01-31T12:28:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T14:48:57.000Z (about 2 years ago)
- Last Synced: 2025-02-07T01:32:07.996Z (over 1 year ago)
- Language: Python
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# frankwolfe-py
This package is a python wrapper for [FrankWolfe.jl](https://github.com/ZIB-IOL/FrankWolfe.jl).
## Installation
First, download the package [frankwolfe-py](https://github.com/ZIB-IOL/frankwolfe-py).
Move to the root of the package and execute on a terminal the following command:
```bash
pip install .
```
Now you can use the FrankWolfe.jl functions with
```python
from frankwolfepy import frankwolfe
```
and the wrapper of the objective function with
```python
from frankwolfepy import wrapper
```
## Usage
Because of compatibility issues between Python and Julia number types, 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:
```python
f = wrapper.wrap_objective_function(f).
```
A simple example :
```python
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/