smash.Samples.iterslice#

Samples.iterslice(by=1)[source]#

Iterate on the Samples object by slices.

Parameters:
byint, default 1

The size of the sample slice. If by is not a multiple of the sample size \(n\) the last slice iteration size will be updated to the maximum range. It results in \(k=\lfloor{\frac{n}{by}}\rfloor\) iterations of size \(by\) and one last iteration of size \(n - k \times by\).

Yields:
sliceSamples

The Samples object sliced according to by arguments.

See also

Samples.slice

Slice the Samples object.

Examples

>>> from smash.factory import generate_samples
>>> problem = {"num_vars": 2, "names": ["cp", "llr"], "bounds": [[1, 200], [1, 500]]}

Generate samples

>>> sample = generate_samples(problem, n=5, random_state=1)
>>> sample.to_dataframe()
           cp         llr
0   83.987379   47.076959
1  144.344574   93.943845
2    1.022761  173.434803
3   61.164182  198.986970
4   30.204422  269.869550

Iterate on each set

>>> for sample_slice in sample.iterslice():
        sample_slice.to_numpy(axis=-1)
array([[83.98737894, 47.07695879]])
array([[144.34457419,  93.94384548]])
array([[  1.02276059, 173.43480279]])
array([[ 61.16418195, 198.98696964]])
array([[ 30.20442227, 269.86955027]])

Iterate on pairs of sets

>>> for sample_slice in sample.iterslice(2):
        sample_slice.to_numpy(axis=-1)
array([[ 83.98737894,  47.07695879],
       [144.34457419,  93.94384548]])
array([[  1.02276059, 173.43480279],
       [ 61.16418195, 198.98696964]])
array([[ 30.20442227, 269.86955027]])