in bayesmark/experiment.py [0:0]
def build_suggest_ds(suggest_log):
"""Convert :class:`numpy:numpy.ndarray` with function evaluation inputs to :class:`xarray:xarray.Dataset`.
This function is a data cleanup routine after running an experiment, before serializing the data to end the study.
Parameters
----------
suggest_log : list(list(dict(str, object)))
Log of the suggestions. It has shape `(n_call, n_suggest)`.
Returns
-------
suggest_ds : :class:`xarray:xarray.Dataset`
:class:`xarray:xarray.Dataset` containing one variable for each input with the objective function evaluations.
It has dimensions ``(ITER, SUGGEST)``.
"""
n_call, n_suggest = np.shape(suggest_log)
assert n_call * n_suggest > 0
# Setup the dims
ds_vars = sorted(suggest_log[0][0].keys())
coords = OrderedDict([(ITER, range(n_call)), (SUGGEST, range(n_suggest))])
# There is prob a way to vectorize this more but good enough for now. Using np.full to infer dtype from 1st element
data = OrderedDict([(kk, ((ITER, SUGGEST), np.full((n_call, n_suggest), suggest_log[0][0][kk]))) for kk in ds_vars])
for ii in range(n_call):
for jj in range(n_suggest):
for kk in ds_vars:
data[kk][1][ii, jj] = suggest_log[ii][jj][kk]
suggest_ds = xr.Dataset(data, coords=coords)
return suggest_ds