jonathf / chaospy

Chaospy - Toolbox for performing uncertainty quantification.
https://chaospy.readthedocs.io/
MIT License
439 stars 87 forks source link

.sample() method is much slower for GaussianKDE #415

Open iffanh opened 10 months ago

iffanh commented 10 months ago

Describe your problem I am solving a UQ problem where I use both Beta distributions and DD approach using Gaussian KDE for comparison. However, the sampling method using GaussianKDE distribution is much slower, rendering my solution impractical. It would be nice to have performance that are comparable.

Initial implementation

import chaospy

data = [116.2745628 , 115.13416142, 114.80945382, 116.33084439,
       114.54430672, 115.24590145, 112.82373268, 114.54212321,
       115.52909247, 114.18009555, 112.07062018, 116.121504  ,
       115.66960091, 113.76577903, 115.09706703, 115.02576397,
       116.09792064, 113.58395028, 116.43990758, 110.87611642,
       113.75703483, 113.73841484, 113.94810725, 113.55789659,
       114.23254175, 112.02328131, 115.93962318, 114.82174351,
       112.98921929, 114.46347643, 114.3485737 , 116.31094777,
       113.95286305, 116.35006936, 112.13944517, 113.4164324 ,
       113.49817194, 112.13492641, 115.86916609, 110.03929423,
       112.63799775, 114.68182756, 115.42690616, 114.38960296,
       113.24773739, 113.56371198, 113.98226525, 115.92298171,
       115.06980836, 113.78593864, 120.79032402, 121.04689476,
       121.38657614, 121.99086261, 120.11176311, 120.55870961,
       121.7959077 , 119.97631963, 121.28797822, 121.50383483,
       120.70152975, 120.78281641, 121.41026365, 121.12063399,
       121.60536863, 120.49792794, 121.62735184, 121.28069985,
       118.00865215, 120.00771131, 121.81723751, 121.66991639,
       121.81448758, 121.12223572, 121.75089556, 121.93087192,
       121.51646797, 121.1670653 , 120.36084271, 121.53289615,
       121.77973136, 121.31569106, 121.9604421 , 121.92048975,
       120.38454544, 120.52848225, 120.6338943 , 121.59134533,
       120.63304273, 121.75531306, 121.40742477, 121.17508324,
       120.98898567, 121.82692894, 120.89837076, 121.78889696,
       121.50167626, 121.88522189, 119.97447533, 120.1121333 ]

dist1 = chaospy.GaussianKDE(data)
dist2 = chaospy.Beta(2, 2, 0, 1)

start = time.time()
dist1.sample(100000)
end = time.time()
print(f"Sampling time from GaussianKDE : {end - start} seconds")

start = time.time()
dist2.sample(100000)
end = time.time()
print(f"Sampling time from Beta: {end - start} seconds")

In my computer the results are

Sampling time from GaussianKDE : 24.94120717048645 seconds
Sampling time from Beta: 0.032398223876953125 seconds

Is there a good alternative to this problem?

iffanh commented 10 months ago

related to #414