def _shrink(X, npoints):
"""
When designs are generated that are larger than the requested number of points (N* > N), resize them.
If the size was correct all along, the LHD is returned unchanged.
:param X: Generated LHD, size N* x D, with N* >= N
:param npoints: What size to resize to (N)
:return: LHD data matrix, size N x D
"""
npStar, nv = X.shape
# Pick N samples nearest to centre of X
centre = npStar * np.ones((1, nv)) / 2.
distances = cdist(X, centre).ravel()
idx = np.argsort(distances)
X = X[idx[:npoints], :]
# Translate to origin
X -= np.min(X, axis=0) - 1
# Collapse gaps in the design to assure all cell projections onto axes have 1 sample
Xs = np.argsort(X, axis=0)
X[Xs, np.arange(nv)] = np.tile(np.arange(1, npoints + 1), (nv, 1)).T
assert (X.shape[0] == npoints)
return X
评论列表
文章目录