ray.rllib.policy.sample_batch.SampleBatch
ray.rllib.policy.sample_batch.SampleBatch#
- class ray.rllib.policy.sample_batch.SampleBatch(*args, **kwargs)[source]#
Bases:
dictWrapper around a dictionary with string keys and array-like values.
For example, {“obs”: [1, 2, 3], “reward”: [0, -1, 1]} is a batch of three samples, each with an “obs” and “reward” attribute.
Methods
__init__(*args, **kwargs)Constructs a sample batch (same params as dict constructor).
Returns the same as len(self) (number of steps in this batch).
Returns the respective MultiAgentBatch using DEFAULT_POLICY_ID.
clear()columns(keys)Returns a list of the batch-data in the specified columns.
compress([bulk, columns])Compresses the data buffers (by column) in place.
concat(other)Concatenates
otherto this one and returns a new SampleBatch.copy([shallow])Creates a deep or shallow copy of this SampleBatch and returns it.
decompress_if_needed([columns])Decompresses data buffers (per column if not compressed) in place.
Returns the same as len(self) (number of steps in this batch).
fromkeys([value])Create a new dictionary with keys from iterable and values set to value.
get(key[, default])Returns one column (by key) from the data or a default value.
get_single_step_input_dict(view_requirements)Creates single ts SampleBatch at given index from
self.Returns True if this SampleBatch only contains one trajectory.
Returns True if
selfis either terminated or truncated at idx -1.items()keys()pop(k[,d])If key is not found, default is returned if given, otherwise KeyError is raised
popitem()Remove and return a (key, value) pair as a 2-tuple.
right_zero_pad(max_seq_len[, exclude_states])Right (adding zeros at end) zero-pads this SampleBatch in-place.
rows()Returns an iterator over data rows, i.e. dicts with column values.
Sets a function to be called on every getitem.
set_training([training])Sets the
is_trainingflag for this SampleBatch.setdefault(key[, default])Insert key with a value of default if key is not in the dictionary.
shuffle()Shuffles the rows of this batch in-place.
Returns sum over number of bytes of all data buffers.
slice(start, end[, state_start, state_end])Returns a slice of the row data of this batch (w/o copying).
split_by_episode([key])Splits by
eps_idcolumn and returns list of new batches.timeslices([size, num_slices, k])Returns SampleBatches, each one representing a k-slice of this one.
to_device(device[, framework])TODO: transfer batch to given device as framework tensor.
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()Attributes