scipy.stats.qmc.scale¶
- scipy.stats.qmc.scale(sample, l_bounds, u_bounds, *, reverse=False)[source]¶
Sample scaling from unit hypercube to different bounds.
To convert a sample from \([0, 1)\) to \([a, b), b>a\), with \(a\) the lower bounds and \(b\) the upper bounds. The following transformation is used:
\[(b - a) \cdot \text{sample} + a\]- Parameters
- samplearray_like (n, d)
Sample to scale.
- l_bounds, u_boundsarray_like (d,)
Lower and upper bounds (resp. \(a\), \(b\)) of transformed data. If reverse is True, range of the original data to transform to the unit hypercube.
- reversebool, optional
Reverse the transformation from different bounds to the unit hypercube. Default is False.
- Returns
- samplearray_like (n, d)
Scaled sample.
Examples
Transform 3 samples in the unit hypercube to bounds:
>>> from scipy.stats import qmc >>> l_bounds = [-2, 0] >>> u_bounds = [6, 5] >>> sample = [[0.5 , 0.75], ... [0.5 , 0.5], ... [0.75, 0.25]] >>> sample_scaled = qmc.scale(sample, l_bounds, u_bounds) >>> sample_scaled array([[2. , 3.75], [2. , 2.5 ], [4. , 1.25]])
And convert back to the unit hypercube:
>>> sample_ = qmc.scale(sample_scaled, l_bounds, u_bounds, reverse=True) >>> sample_ array([[0.5 , 0.75], [0.5 , 0.5 ], [0.75, 0.25]])