This is an implementation of Latin Hypercube Sampling with Multi-Dimensional Uniformity (LHS-MDU) from Deutsch and Deutsch, "Latin hypercube sampling with multidimensional uniformity.
Project description
LHS-MDU
--------
Basics
======
This is a package for generating latin hypercube samples with multi-dimensional uniformity.
To use, simply do::
>>> import lhsmdu
>>> k = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
This will generate a nested list with 2 variables, with 20 samples each.
To plot and see the difference between Monte Carlo and LHS-MDU sampling for a 2 dimensional system::
>>> l = lhsmdu.createRandomStandardUniformMatrix(2, 20) # Monte Carlo sampling
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.gca()
>>> ax.set_xticks(numpy.arange(0,1,0.1))
>>> ax.set_yticks(numpy.arange(0,1,0.1))
>>> plt.scatter(k[0], k[1], col="g", label="LHS-MDU")
>>> plt.scatter(l[0], l[1], col="r", label="MC")
>>> plt.grid()
>>> plt.show()
You can use the strata generated by the algorithm to sample again, if you so desire. For this, you can do::
>>> m = lhsmdu.resample()
>>> n = lhsmdu.resample()
>>> o = lhsmdu.resample()
This will again generate the same number of samples as before, a nested list with 2 variables, with 20 samples each.
You can plot these together and see the sampling from the strata::
>>> fig = plt.figure()
>>> ax = fig.gca()
>>> ax.set_xticks(numpy.arange(0,1,0.1))
>>> ax.set_yticks(numpy.arange(0,1,0.1))
>>> plt.title("LHS-MDU")
>>> plt.scatter(k[0], k[1], c="g", label="sample 1")
>>> plt.scatter(m[0], m[1], c="r", label="resample 2")
>>> plt.scatter(n[0], n[1], c="b", label="resample 3")
>>> plt.scatter(o[0], o[1], c="y", label="resample 4")
>>> plt.grid()
>>> plt.show()
Alternatively, you can choose to get new strata each time, and see the sampling hence::
>>> p = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
>>> q = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
>>> r = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
>>> fig = plt.figure()
>>> ax = fig.gca()
>>> ax.set_xticks(numpy.arange(0,1,0.1))
>>> ax.set_yticks(numpy.arange(0,1,0.1))
>>> plt.title("LHS-MDU")
>>> plt.scatter(k[0], k[1], c="g", label="sample 1")
>>> plt.scatter(p[0], p[1], c="r", label="sample 2")
>>> plt.scatter(q[0], q[1], c="b", label="sample 3")
>>> plt.scatter(r[0], r[1], c="y", label="sample 4")
>>> plt.grid()
>>> plt.show()
===========================================================================================
Sampling from arbitrary CDFs
=======================
After uniformly distributed samples have been generated from LHSMDU, you can convert these to samples from arbitrary distributions using inverse tranform sampling. In this, the CDF [0,1] of the distribution of interest is inverted, and then data points corresponding to the uniformly sampled points are picked up. To do this, you must have a `rv_contiuous` or `rv_discrete` distribution instance taken from scipy.stats. You can also use frozen distributions (after setting loc and scale parameters). Following is an example for normal distribution.::
>>> import scipy.stats.distributions as ssd
>>> p = ssd.norm
>>> new_samples = lhsmdu.inverseTransformSample(p, k[0])
>>> plt.hist(lhsmdu.inverseTransformSample(p, k[0]))
>>> plt.show()
--------
Basics
======
This is a package for generating latin hypercube samples with multi-dimensional uniformity.
To use, simply do::
>>> import lhsmdu
>>> k = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
This will generate a nested list with 2 variables, with 20 samples each.
To plot and see the difference between Monte Carlo and LHS-MDU sampling for a 2 dimensional system::
>>> l = lhsmdu.createRandomStandardUniformMatrix(2, 20) # Monte Carlo sampling
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.gca()
>>> ax.set_xticks(numpy.arange(0,1,0.1))
>>> ax.set_yticks(numpy.arange(0,1,0.1))
>>> plt.scatter(k[0], k[1], col="g", label="LHS-MDU")
>>> plt.scatter(l[0], l[1], col="r", label="MC")
>>> plt.grid()
>>> plt.show()
You can use the strata generated by the algorithm to sample again, if you so desire. For this, you can do::
>>> m = lhsmdu.resample()
>>> n = lhsmdu.resample()
>>> o = lhsmdu.resample()
This will again generate the same number of samples as before, a nested list with 2 variables, with 20 samples each.
You can plot these together and see the sampling from the strata::
>>> fig = plt.figure()
>>> ax = fig.gca()
>>> ax.set_xticks(numpy.arange(0,1,0.1))
>>> ax.set_yticks(numpy.arange(0,1,0.1))
>>> plt.title("LHS-MDU")
>>> plt.scatter(k[0], k[1], c="g", label="sample 1")
>>> plt.scatter(m[0], m[1], c="r", label="resample 2")
>>> plt.scatter(n[0], n[1], c="b", label="resample 3")
>>> plt.scatter(o[0], o[1], c="y", label="resample 4")
>>> plt.grid()
>>> plt.show()
Alternatively, you can choose to get new strata each time, and see the sampling hence::
>>> p = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
>>> q = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
>>> r = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
>>> fig = plt.figure()
>>> ax = fig.gca()
>>> ax.set_xticks(numpy.arange(0,1,0.1))
>>> ax.set_yticks(numpy.arange(0,1,0.1))
>>> plt.title("LHS-MDU")
>>> plt.scatter(k[0], k[1], c="g", label="sample 1")
>>> plt.scatter(p[0], p[1], c="r", label="sample 2")
>>> plt.scatter(q[0], q[1], c="b", label="sample 3")
>>> plt.scatter(r[0], r[1], c="y", label="sample 4")
>>> plt.grid()
>>> plt.show()
===========================================================================================
Sampling from arbitrary CDFs
=======================
After uniformly distributed samples have been generated from LHSMDU, you can convert these to samples from arbitrary distributions using inverse tranform sampling. In this, the CDF [0,1] of the distribution of interest is inverted, and then data points corresponding to the uniformly sampled points are picked up. To do this, you must have a `rv_contiuous` or `rv_discrete` distribution instance taken from scipy.stats. You can also use frozen distributions (after setting loc and scale parameters). Following is an example for normal distribution.::
>>> import scipy.stats.distributions as ssd
>>> p = ssd.norm
>>> new_samples = lhsmdu.inverseTransformSample(p, k[0])
>>> plt.hist(lhsmdu.inverseTransformSample(p, k[0]))
>>> plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lhsmdu-0.1.tar.gz
(4.2 kB
view details)
Built Distributions
lhsmdu-0.1-py3-none-any.whl
(5.0 kB
view details)
lhsmdu-0.1-py2.7.egg
(6.8 kB
view details)
File details
Details for the file lhsmdu-0.1.tar.gz
.
File metadata
- Download URL: lhsmdu-0.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ef462054b354cd20b10c6d80876c8fdb552a8d2e23eaf74179dc91956d68d32a
|
|
MD5 |
c62d42af4cb5ce10b4a6562df9a59232
|
|
BLAKE2b-256 |
4bdd52342d9f3cf7bfffa6a30c8a4c8a2b38fcdb7a25634a8a40a29a3b25cbf4
|
File details
Details for the file lhsmdu-0.1-py3-none-any.whl
.
File metadata
- Download URL: lhsmdu-0.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
833818903027c655f04fd28b763891a1ef59c3120003fb51a3fdca909aa8fe4c
|
|
MD5 |
8cc401cfafe09912f33180ec945af421
|
|
BLAKE2b-256 |
7bf0e714a4dae734bcd7228a09d74fff7dc5857dc3311cd72a3e07b09c85d088
|
File details
Details for the file lhsmdu-0.1-py2.7.egg
.
File metadata
- Download URL: lhsmdu-0.1-py2.7.egg
- Upload date:
- Size: 6.8 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
e94b173b2485ed2728beaed0812b39ed36636903ba8d44cf12c28acada3b779c
|
|
MD5 |
0c47562d66997658203368a4c4b73846
|
|
BLAKE2b-256 |
217a9d91818a73ac0ceb8dc83c72480c8302aa68ccaffa1fe63fef2333db1e39
|