Hi everyone,
I was playing with Centered discrepancy and wrote my function before I saw the
class SpaceFillingC2.
There is no issue except that I get 2x speedup with my python version. There
might be room for improvement as I can even get a 10x on my version using numba.
Here it is:
import numpy as np
import timeit
import openturns as ot
def discrepancy(sample):
disc1 = 0
disc2 = 0
n_sample = len(sample)
dim = sample.shape[1]
abs_ = abs(sample - 0.5)
disc1 = np.sum(np.prod(1 + 0.5 * abs_ - 0.5 * abs_ ** 2, axis=1))
prod_arr = 1
for i in range(dim):
s0 = sample[:, i]
prod_arr *= (1 +
0.5 * abs(s0[:, None] - 0.5) + 0.5 * abs(s0 - 0.5) -
0.5 * abs(s0[:, None] - s0))
disc2 = prod_arr.sum()
c2 = (13 / 12) ** dim - 2 / n_sample * disc1 + 1 / (n_sample ** 2) * disc2
return np.sqrt(c2)
sample = np.random.random_sample((100, 2))
print(discrepancy(sample))
print(ot.SpaceFillingC2().evaluate(sample))
print('Function time: ', timeit.repeat('discrepancy(sample)', number=500,
repeat=3, setup="from __main__ import discrepancy, sample"))
print('OT time: ', timeit.repeat('ot.SpaceFillingC2().evaluate(sample)',
number=500, repeat=3, setup="from __main__ import sample, ot"))
Pamphile ROY
Chercheur doctorant en Quantification d’Incertitudes
CERFACS - Toulouse (31) - France
+33 (0) 5 61 19 31 57
+33 (0) 7 86 43 24 22
_______________________________________________
OpenTURNS users mailing list
[email protected]
http://openturns.org/mailman/listinfo/users