sahilm89 / lhsmdu

This is an implementation of Deutsch and Deutsch, "Latin hypercube sampling with multidimensional uniformity", Journal of Statistical Planning and Inference 142 (2012) , 763-772
MIT License
79 stars 16 forks source link

Sample code needs to be updated. #3

Closed MooersLab closed 4 years ago

MooersLab commented 4 years ago

The example in the Readme.md is not working with Python3.6. The k and l are 2-D numpy matrices that need to be converted to np.arrays before sending to matplotlib. In addition, the 'col' parameter name needs to be replaced with 'c' or 'color'.

import lhsmdu
import matplotlib.pyplot as plt
import numpy as np

k = lhsmdu.sample(2, 20) # Latin Hypercube Sampling with multi-dimensional uniformity
print(k)
l = lhsmdu.createRandomStandardUniformMatrix(2, 20) # Monte Carlo sampling

k = np.array(k)
l = np.array(l)

fig = plt.figure()
ax = fig.gca()
ax.set_xticks(np.arange(0,1,0.1))
ax.set_yticks(np.arange(0,1,0.1))
plt.scatter(k[0], k[1], color="g", label="LHS-MDU")
plt.scatter(l[0], l[1], color="r", label="MC")
plt.grid()
plt.show()

m = lhsmdu.resample()
n = lhsmdu.resample()
o = lhsmdu.resample()
m = np.array(m)
n = np.array(n)
o = np.array(o)

fig = plt.figure()
ax = fig.gca()
ax.set_xticks(np.arange(0,1,0.1))
ax.set_yticks(np.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()
sahilm89 commented 4 years ago

Thanks, I've updated the README with these suggestions.

sahilm89 commented 4 years ago

Closing issue.