This package provides an algorithm for solving Kullback-Leibler (KL) regularized least squares problems of the form
where
- the probability simplex:
$\Delta := { x∈ℝ^n_+ \mid ∑_j x_j=1}$ ) or, - the nonnegative orthant
$ℝ^n_+$ .
The algorithm is based on a trust-region Newton CG method on the dual problem.
The latest release (v0.1.3) includes:
- Official Julia registry support
- Python package available on PyPI
You can install this package directly from Julia's package manager:
import Pkg; Pkg.add("DualPerspective")
For Python users, install from PyPI:
pip install DualPerspective
To solve a simple optimal transport problem:
using DualPerspective, LinearAlgebra, Distances
μsupport = νsupport = range(-2, 2; length=100)
C = pairwise(SqEuclidean(), μsupport', νsupport'; dims=2) # Cost matrix
μ = normalize!(exp.(-μsupport .^ 2 ./ 0.5^2), 1) # Start distribution
ν = normalize!(νsupport .^ 2 .* exp.(-νsupport .^ 2 ./ 0.5^2), 1) # Target distribution
ϵ = 0.01*median(C) # Entropy regularization constant
ot = DualPerspective.OTModel(μ, ν, C, ϵ) # Model initialization
solution = solve!(ot, trace=true) # Solution to the OT problem
DualPerspective.jl provides the following optional extensions:
Provides plotting capabilities using the UnicodePlots package. To use:
using DualPerspective, UnicodePlots
# Now you can plot DualPerspective.ExecutionStats objects
histogram(solution)
To get started with developing the package, first pull the Github repo
git clone https://github.com/MPF-Optimization-Laboratory/DualPerspective.jl.git
Or better, create fork to develop!
To be able to use the library in the julia REPL, navigate to the library root folder, and run
julia --project=. -i -e 'using Pkg; Pkg.activate(".")'
This will start the julia REPL, and add the repo to the julia LOAD_PATH
. To start using, run
using DualPerspective
To use this package in a notebook while developing, add it manually to your julia LOAD_PATH
by
push!(LOAD_PATH, "/path/to/the/library")
Each pull requested will be tested against the current tests, and new tests are highly encouraged for any new piece of code. To run the tests, run
julia --project=. -i -e 'using Pkg; Pkg.test()'