Skip to content

Commit 3bbc0d5

Browse files
committed
Merge branch 'dw/bluestyle'
2 parents 5065f5f + c99b0da commit 3bbc0d5

File tree

8 files changed

+286
-168
lines changed

8 files changed

+286
-168
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style="blue"

.github/workflows/Format.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Format
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
format:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: julia-actions/setup-julia@latest
12+
with:
13+
version: 1
14+
- name: Format code
15+
run: |
16+
using Pkg
17+
Pkg.add(; name="JuliaFormatter", uuid="98e50ef6-434e-11e9-1051-2b60c6c9e899")
18+
using JuliaFormatter
19+
format("."; verbose=true)
20+
shell: julia --color=yes {0}
21+
- uses: reviewdog/action-suggester@v1
22+
with:
23+
tool_name: JuliaFormatter
24+
fail_on_error: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![CI](https://github.com/zsteve/OptimalTransport.jl/workflows/CI/badge.svg?branch=master)](https://github.com/zsteve/OptimalTransport.jl/actions?query=workflow%3ACI+branch%3Amaster)
99
[![Codecov](https://codecov.io/gh/zsteve/OptimalTransport.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/zsteve/OptimalTransport.jl)
1010
[![Coveralls](https://coveralls.io/repos/github/zsteve/OptimalTransport.jl/badge.svg?branch=master)](https://coveralls.io/github/zsteve/OptimalTransport.jl?branch=master)
11+
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
1112

1213
This package provides some [Julia](https://julialang.org/) implementations of algorithms for computational [optimal transport](https://optimaltransport.github.io/), including the Earth-Mover's (Wasserstein) distance, Sinkhorn scaling algorithm for entropy-regularised transport as well as some variants or extensions.
1314

docs/make.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using OptimalTransport
2-
import Literate
3-
import Pkg
2+
using Literate: Literate
3+
using Pkg: Pkg
44

55
if haskey(ENV, "GITHUB_ACTIONS")
66
# Print `@debug` statements (https://github.com/JuliaDocs/Documenter.jl/issues/955)
@@ -75,6 +75,4 @@ makedocs(;
7575
checkdocs=:exports,
7676
)
7777

78-
deploydocs(;
79-
repo="github.com/zsteve/OptimalTransport.jl", push_preview=true,
80-
)
78+
deploydocs(; repo="github.com/zsteve/OptimalTransport.jl", push_preview=true)

examples/basic/script.jl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Random.seed!(1234);
2121
# and $\nu$ (target measure) in 1D:
2222

2323
M = 200
24-
μ = fill(1/M, M)
24+
μ = fill(1 / M, M)
2525
μsupport = rand(M)
2626

2727
N = 250
28-
ν = fill(1/N, N)
28+
ν = fill(1 / N, N)
2929
νsupport = rand(N);
3030

3131
# Now we compute the quadratic cost matrix $C_{ij} = \| x_i - x_j \|_2^2$:
@@ -133,11 +133,11 @@ norm(γ - γpot, Inf)
133133
# We construct two random measures, now with different total masses:
134134

135135
M = 100
136-
μ = fill(1/M, M)
136+
μ = fill(1 / M, M)
137137
μsupport = rand(M)
138138

139139
N = 200
140-
ν = fill(1/M, N)
140+
ν = fill(1 / M, N)
141141
νsupport = rand(N);
142142

143143
# We compute the quadratic cost matrix:
@@ -164,9 +164,9 @@ norm(γ - γpot, Inf)
164164

165165
μsupport = νsupport = range(-2, 2; length=100)
166166
C = pairwise(SqEuclidean(), μsupport', νsupport')
167-
μ = exp.(- μsupport.^2 ./ 0.5^2)
167+
μ = exp.(-μsupport .^ 2 ./ 0.5^2)
168168
μ ./= sum(μ)
169-
ν = νsupport.^2 .* exp.(- νsupport.^2 ./ 0.5^2)
169+
ν = νsupport .^ 2 .* exp.(-νsupport .^ 2 ./ 0.5^2)
170170
ν ./= sum(ν)
171171

172172
plot(μsupport, μ; label=raw"$\mu$", size=(600, 400))
@@ -176,8 +176,11 @@ plot!(νsupport, ν; label=raw"$\nu$")
176176

177177
γ = sinkhorn(μ, ν, C, 0.01)
178178
heatmap(
179-
μsupport, νsupport, γ;
180-
title="Entropically regularised optimal transport", size=(600, 600)
179+
μsupport,
180+
νsupport,
181+
γ;
182+
title="Entropically regularised optimal transport",
183+
size=(600, 600),
181184
)
182185

183186
# ### Quadratically regularised transport
@@ -187,8 +190,11 @@ heatmap(
187190

188191
γquad = Matrix(quadreg(μ, ν, C, 5; maxiter=500))
189192
heatmap(
190-
μsupport, νsupport, γquad;
191-
title="Quadratically regularised optimal transport", size=(600, 600)
193+
μsupport,
194+
νsupport,
195+
γquad;
196+
title="Quadratically regularised optimal transport",
197+
size=(600, 600),
192198
)
193199

194200
# ### Sinkhorn barycenters
@@ -208,9 +214,9 @@ heatmap(
208214
# $\lambda_1 \in \{0.25, 0.5, 0.75\}$.
209215

210216
support = range(-1, 1; length=250)
211-
mu1 = exp.(- (support .+ 0.5).^2 ./ 0.1^2)
217+
mu1 = exp.(-(support .+ 0.5) .^ 2 ./ 0.1^2)
212218
mu1 ./= sum(mu1)
213-
mu2 = exp.(- (support .- 0.5).^2 ./ 0.1^2)
219+
mu2 = exp.(-(support .- 0.5) .^ 2 ./ 0.1^2)
214220
mu2 ./= sum(mu2)
215221

216222
plt = plot(; size=(800, 400), legend=:outertopright)

0 commit comments

Comments
 (0)