data.buffer.deque_buffer¶
deque_buffer¶
DequeBuffer¶
- class ding.data.buffer.deque_buffer.DequeBuffer(size: int, sliced: bool = False)[source]¶
- Overview:
A buffer implementation based on the deque structure.
- clear() None [source]¶
- Overview:
The method that clear all data, indices, and the meta information in the buffer.
- delete(indices: str | Iterable[str]) None [source]¶
- Overview:
The method that delete the data and related meta information by specific indices.
- Arguments:
indices (Union[str, Iterable[str]]): Where the data to be cleared in the buffer.
- get(idx: int) BufferedData [source]¶
- Overview:
The method that returns the BufferedData object given a specific index.
- push(data: Any, meta: dict | None = None) BufferedData [source]¶
- Overview:
The method that input the objects and the related meta information into the buffer.
- Arguments:
data (
Any
): The input object which can be in any format.meta (
Optional[dict]
): A dict that helps describe data, such as category, label, priority, etc. Default toNone
.
- sample(size: int | None = None, indices: List[str] | None = None, replace: bool = False, sample_range: slice | None = None, ignore_insufficient: bool = False, groupby: str | None = None, unroll_len: int | None = None) List[BufferedData] | List[List[BufferedData]] [source]¶
- Overview:
The method that randomly sample data from the buffer or retrieve certain data by indices.
- Arguments:
- size (
Optional[int]
): The number of objects to be obtained from the buffer. If
indices
is not specified, thesize
is required to randomly sample the corresponding number of objects from the buffer.
- size (
- indices (
Optional[List[str]]
): Only used when you want to retrieve data by indices. Default to
None
.
- indices (
replace (
bool
): As the sampling process is carried out one by one, this parameter determines whether the previous samples will be put back into the buffer for subsequent sampling. Default toFalse
, it means that duplicate samples will not appear in onesample
call.sample_range (
Optional[slice]
): The indices range to sample data. Default toNone
, it means no restrictions on the range of indices for the sampling process.ignore_insufficient (
bool
): whether throw `` ValueError`` if the sampled size is smaller than the required size. Default toFalse
.groupby (
Optional[str]
): If this parameter is activated, the method will return a target size of object groups.unroll_len (
Optional[int]
): The unroll length of a trajectory, used only when thegroupby
is activated.
- Returns:
sampled_data (Union[List[BufferedData], List[List[BufferedData]]]): The sampling result.
- update(index: str, data: Any | None = None, meta: dict | None = None) bool [source]¶
- Overview:
the method that update data and the related meta information with a certain index.
- Arguments:
data (
Any
): The data which is supposed to replace the old one. If you set it toNone
, nothing will happen to the old record.meta (
Optional[dict]
): The new dict which is supposed to merge with the old one.