Debian Codegraph @

benchmarks/sinkhorn_knopp.py

raw symbols SCIP
1 # /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 import numpy as np
5 import ot
6 from .benchmark import setup_backends, exec_bench, convert_to_html_table
7
8
9 def setup(n_samples):
10 rng = np.random.RandomState(123456789)
11 a = rng.rand(n_samples // 4, 100)
12 b = rng.rand(n_samples, 100)
13
14 wa = ot.unif(n_samples // 4)
15 wb = ot.unif(n_samples)
16
17 M = ot.dist(a.copy(), b.copy())
18 return wa, wb, M
19
20
21 if __name__ == "__main__":
22 n_runs = 100
23 warmup_runs = 10
24 param_list = [50, 100, 500, 1000, 2000, 5000]
25
26 setup_backends()
27 results = exec_bench(
28 setup=setup,
29 tested_function=lambda *args: ot.bregman.sinkhorn(*args, reg=1, stopThr=1e-7),
30 param_list=param_list,
31 n_runs=n_runs,
32 warmup_runs=warmup_runs,
33 )
34 print(
35 convert_to_html_table(
36 results,
37 param_name="Sample size",
38 main_title=f"Sinkhorn Knopp - Averaged on {n_runs} runs",
39 )
40 )