summaryrefslogtreecommitdiff
path: root/test/test_emd_multi.py
blob: 2eef2424c960d017026bc653f207dbc01b760c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 10 09:56:06 2017

@author: rflamary
"""

import numpy as np

import ot
from ot.datasets import get_1D_gauss as gauss
# reload(ot.lp)

#%% parameters

n = 5000  # nb bins

# bin positions
x = np.arange(n, dtype=np.float64)

# Gaussian distributions
a = gauss(n, m=20, s=5)  # m= mean, s= std

ls = np.arange(20, 1000, 10)
nb = len(ls)
b = np.zeros((n, nb))
for i in range(nb):
    b[:, i] = gauss(n, m=ls[i], s=10)

# loss matrix
M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
# M/=M.max()

#%%

print('Computing {} EMD '.format(nb))

# emd loss 1 proc
ot.tic()
emd_loss4 = ot.emd2(a, b, M, 1)
ot.toc('1 proc : {} s')

# emd loss multipro proc
ot.tic()
emd_loss4 = ot.emd2(a, b, M)
ot.toc('multi proc : {} s')