binned_value_discretizer
binned_value_discretizer
¶
Binned discretizer for continuous values.
This module provides the shared binning used by observation and action tokenization. Uniform binning places equal-width bins over a fixed range and decodes through bin centers. Quantile binning adapts bin edges to the data distribution and decodes through per-bin data means, which stays exact for heavily repeated values (binary grippers, zero deltas) where quantile edges collapse into duplicates.
BinnedValueDiscretizer
¶
BinnedValueDiscretizer(num_bins=256, device=None, binning_strategy=value, min_value=-1.0, max_value=1.0)
Discretizer mapping continuous values to per-dimension bin IDs.
Attributes:
| Name | Type | Description |
|---|---|---|
num_bins |
Number of discrete bins per dimension. |
|
binning_strategy |
Bin-edge placement strategy from |
|
device |
Target device for tensors. |
|
bin_edges |
Tensor | None
|
Bin boundaries for each dimension, shape (D, num_bins-1). |
bin_values |
Tensor | None
|
Decode value for each bin, shape (D, num_bins). |
Initialize discretizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_bins
|
int
|
Number of discrete bins per dimension. |
256
|
device
|
device | None
|
Target device for tensors. If None, uses CPU. |
None
|
binning_strategy
|
str
|
|
value
|
min_value
|
float
|
Lower bound of the uniform bin range. |
-1.0
|
max_value
|
float
|
Upper bound of the uniform bin range. |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/versatil/data/tokenization/binned_value_discretizer.py
fit
¶
Fit bin edges and per-bin decode values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized_data
|
ndarray
|
Normalized data of shape (N, D) where: N = number of samples D = feature dimension Values should be normalized (typically [-1, 1]). |
required |
Source code in src/versatil/data/tokenization/binned_value_discretizer.py
encode
¶
Encode normalized data to discrete IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized_data
|
ndarray | Tensor
|
Normalized data of shape (..., D). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
ID tensor of shape (..., D) with integer values in [0, num_bins-1]. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If discretizer has not been fitted. |
Source code in src/versatil/data/tokenization/binned_value_discretizer.py
decode
¶
Decode discrete IDs back to normalized data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
Tensor | ndarray
|
ID tensor of shape (..., D) with values in [0, num_bins-1]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Reconstructed normalized data of shape (..., D). |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If discretizer has not been fitted. |
Source code in src/versatil/data/tokenization/binned_value_discretizer.py
to
¶
Move discretizer to specified device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device
|
Target device. |
required |
Returns:
| Type | Description |
|---|---|
BinnedValueDiscretizer
|
Self for chaining. |
Source code in src/versatil/data/tokenization/binned_value_discretizer.py
state_dict
¶
Get state dictionary for serialization.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing discretizer state. |
Source code in src/versatil/data/tokenization/binned_value_discretizer.py
load_state_dict
¶
Load state dictionary.
States saved before the strategy split default to quantile binning with geometric-center decoding, preserving their trained behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
dict[str, Any]
|
State dictionary from state_dict(). |
required |