util_sampling
Utility functions for sampling.
scale_samples(samples_norm, limits, limits_norm=(0, 1), do_log=False)
Scale samples to new limits, either logarithmically or linearly.
This function transforms normalized samples to specified limits, allowing for both linear and logarithmic scaling based on the provided parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples_norm
|
ndarray
|
The normalized samples to scale, with dimensions (nsamples, ndims). |
required |
limits
|
List[Tuple[int, int]]
|
A list of (min, max) tuples for the various dimensions. The length of the list must match the number of dimensions (ndims). |
required |
limits_norm
|
Tuple[int, int]
|
The (min, max) values from which |
(0, 1)
|
do_log
|
Union[bool, List[bool]]
|
Indicates whether to apply log10 scaling to each dimension.
This can be a single boolean or a list of length ndims. Defaults
to a list of |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The scaled samples, with the same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
- The function follows the sklearn convention, requiring samples to be provided as an (nsamples, ndims) array.
- To transform 1-D arrays, reshape them accordingly:
Example
>>> # Turn 0:1 samples into -1:1
>>> import numpy as np
>>> norm_values = np.linspace(0,1,5).reshape((-1,1))
>>> real_values = scale_samples(norm_values, [(-1,1)])
>>> print(real_values)
[[-1. ]
[-0.5]
[ 0. ]
[ 0.5]
[ 1. ]]
>>> # Logarithmically scale to 1:10000
>>> real_values = scale_samples(norm_values, [(1,1e4)] do_log=True)
>>> print(real_values)
[[ 1.00000000e+00]
[ 1.00000000e+01]
[ 1.00000000e+02]
[ 1.00000000e+03]
[ 1.00000000e+04]]