Skip to main content

Simple implementation of Latin Hypercube Sampling.

Project description

simplelhs

Simple implementation of Latin Hypercube Sampling.

Example

The example below shows how to sample from a random Latin Hypercube Design with five points for three inputs.

from simplelhs import LatinHypercubeSampling

lhs = LatinHypercubeSampling(3)
hc = lhs.random(5)

print(hc)
[[0.65830165 0.26660356 0.78491755]
 [0.42168063 0.43244666 0.979281  ]
 [0.39058169 0.76099351 0.34764726]
 [0.07122137 0.15507069 0.58082752]
 [0.87530571 0.94575193 0.03949576]]

The example below shows how to sample from a Maximin Latin Hypercube Design with five points for three inputs. Out of 1000 randomly sampled Latin Hypercube samples the sample with the maximal minimal distance between points is selected.

from simplelhs import LatinHypercubeSampling

lhs = LatinHypercubeSampling(3)
hc = lhs.maximin(5, 1000)

print(hc)
[[0.24607101 0.11399068 0.5456922 ]
 [0.88731638 0.40600431 0.32305333]
 [0.47416121 0.99487745 0.03087923]
 [0.06288706 0.7227211  0.78248764]
 [0.77081332 0.36862214 0.99449703]]

To scale the data to unit cube and back to its original range the functions normalise() and unnormalise() are provided. The example below scales the Maximin Latin Hypercube sample back to its original range.

from simplelhs import unnormalise

lower = np.array([0., -5., 10.,])
upper = np.array([1., 5., 40.])
hc_maximin_scaled = unnormalise(hc_maximin, lower, upper)

print(hc_maximin_scaled)
[[ 0.24607101 -3.86009322 26.37076609]
[ 0.88731638 -0.93995687 19.69159997]
[ 0.47416121  4.94877447 10.92637679]
[ 0.06288706  2.22721099 33.47462916]
[ 0.77081332 -1.31377864 39.83491091]]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplelhs-1.2.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplelhs-1.2.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file simplelhs-1.2.1.tar.gz.

File metadata

  • Download URL: simplelhs-1.2.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for simplelhs-1.2.1.tar.gz
Algorithm Hash digest
SHA256 94d6643c258000dbf031e4a80c0799dc7b3a4326b3f2a80b83224acadbb3673a
MD5 5b722670a3bc86f04e7359f22e2409e9
BLAKE2b-256 6610769457ae066ed0820312a282573eae1269e9f603bcba0e3ca85d073e7f8d

See more details on using hashes here.

File details

Details for the file simplelhs-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: simplelhs-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for simplelhs-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e9f5587d24f49d3aeba6c0f630a86da7928e4b8f08ce89fa9e4a0d41f15b855
MD5 04d96c6b4a60d940f70a68be85040c89
BLAKE2b-256 d69ac61a1f563b0ec80e391c85e45a54bffae12071c61323682714c47e8da85f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page