smash.SampleResult#

class smash.SampleResult[source]#

Represents the generated sample result.

See also

smash.generate_samples

Generate a multiple set of spatially uniform Model parameters/states.

Notes

This class is essentially a subclass of dict with attribute accessors and four additional methods, which are:

This may have additional attributes not listed here depending on the specific names provided in the argument problem in the smash.generate_samples method.

Examples

>>> problem = {"num_vars": 2, "names": ["cp", "lr"], "bounds": [[1,200], [1,500]]}
>>> sr = smash.generate_samples(problem, n=5, random_state=1)

Convert the result to a numpy.ndarray:

>>> sr.to_numpy(axis=-1)
array([[ 83.98737894,  47.07695879],
       [144.34457419,  93.94384548],
       [  1.02276059, 173.43480279],
       [ 61.16418195, 198.98696964],
       [ 30.20442227, 269.86955027]])

Convert the result to a pandas.DataFrame:

>>> sr.to_dataframe()
           cp          lr
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

Slice the first two sets:

>>> slc = sr.slice(2)
>>> slc.to_numpy(axis=-1)
array([[ 83.98737894,  47.07695879],
       [144.34457419,  93.94384548]])

Slice between the start and end set:

>>> slc = sr.slice(start=3, end=5)
>>> slc.to_numpy(axis=-1)
array([[ 61.16418195, 198.98696964],
       [ 30.20442227, 269.86955027]])

Iterate on each set:

>>> for slc_i in sr.iterslice():
>>>     slc_i.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 slc_i in sr.iterslice(2):
>>>     slc_i.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]])
Attributes:
generatorstr

The generator used to generate the samples.

n_sampleint

The number of generated samples.

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

iterslice([by])

Iterate on the SampleResult object by slices.

keys()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

slice(end[, start])

Slice the SampleResult object.

to_dataframe()

Convert the SampleResult object to a pandas.DataFrame.

to_numpy([axis])

Convert the SampleResult object to a numpy.ndarray.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()