mixture
mixture
¶
Negative log-likelihood losses for mixture distributions.
GaussianMixtureNLLoss
¶
GaussianMixtureNLLoss(action_keys, weight=1.0, per_key_weights=None, learned_variance=True, sigmas=None, min_variance=0.0001)
Bases: ScalarWeightedLoss
Negative Log-Likelihood loss for Gaussian Mixture Model.
Supports both learned variance (from logvar predictions) and fixed variance (sigma parameter).
Two regimes are supported, dispatched on the shape of routing_weights:
Per-trajectory routing (B, K) — one mixture component is selected for the entire chunk (e.g., MoDEACT). The joint trajectory likelihood is: log p(a_{1:T}|s) = logsumexp_k [log π_k + Σ_t log N(a_t | μ_k(t), σ_k(t)²)] Components are forced to model coherent trajectories; without this formulation the gating collapses to one component that averages distinct trajectory modes.
Per-timestep routing (B, T, K) — a component is selected per timestep (e.g., PhaseACT). The per-step mixture likelihood applies: log p(a_t|s, t) = logsumexp_k [log π_kt + log N(a_t | μ_kt, σ_kt²)]
Initialize Gaussian mixture NLL loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_keys
|
list[str]
|
List of continuous action keys. |
required |
weight
|
float
|
Overall loss weight. |
1.0
|
per_key_weights
|
dict[str, float] | None
|
Optional per-key weights. |
None
|
learned_variance
|
bool
|
If True, expects {action_key}_mean and {action_key}_logvar. If False, expects {action_key} (stacked means) and uses sigmas. |
True
|
sigmas
|
dict[str, float] | None
|
Fixed stddev per action key (only used when learned_variance=False). |
None
|
min_variance
|
float
|
Minimum variance for numerical stability (learned_variance=True). |
0.0001
|
Source code in src/versatil/metrics/losses/mixture.py
get_required_keys
¶
forward
¶
Compute Gaussian mixture NLL loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
dict[str, Tensor]
|
Dictionary containing: - routing_weights: (B, K) for per-trajectory or (B, T, K) for per-timestep. - If learned_variance: {action_key}_mean (B, T, K, D), {action_key}_logvar (B, T, K, D) - If fixed variance: {action_key} (B, T, K, D) stacked expert means |
required |
targets
|
dict[str, Tensor]
|
Dictionary with action_key targets (B, T, D). |
required |
is_pad
|
Tensor | None
|
Optional padding mask (B, T). |
None
|
Returns:
| Type | Description |
|---|---|
LossOutput
|
LossOutput with Gaussian mixture NLL. |
Source code in src/versatil/metrics/losses/mixture.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
GripperMixtureNLLoss
¶
GripperMixtureNLLoss(key, actions_metadata, weight=1.0, learned_variance=False, sigma=0.5, min_variance=0.0001)
Bases: ScalarWeightedLoss
Negative Log-Likelihood loss for gripper with mixture distribution.
Binary gripper: p(a|z) = Σ_k π_k(z) · Bernoulli(a | p_k(z)) Continuous gripper: p(a|z) = Σ_k π_k(z) · N(a | μ_k(z), σ_k²)
Supports both fixed and learned variance for continuous gripper.
Initialize gripper mixture NLL loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Key for gripper actions. |
required |
actions_metadata
|
dict[str, ActionMetadata]
|
Dict of metadata of the action space. |
required |
weight
|
float
|
Loss weight. |
1.0
|
learned_variance
|
bool
|
If True, expects {key}_mean and {key}_logvar for continuous. If False, expects {key} (stacked means) and uses sigma. |
False
|
sigma
|
float
|
Fixed std for continuous gripper (only used when learned_variance=False). |
0.5
|
min_variance
|
float
|
Minimum variance for numerical stability (learned_variance=True). |
0.0001
|
Source code in src/versatil/metrics/losses/mixture.py
get_required_keys
¶
forward
¶
Compute gripper mixture NLL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
dict[str, Tensor]
|
Dictionary containing: - routing_weights: (B, K) or (B, T, K) mixing probabilities - For binary: {key} stacked logits (B, T, K) or (B, T, K, 1) - For continuous with learned_variance: {key}_mean (B, T, K, D), {key}_logvar (B, T, K, D) - For continuous with fixed variance: {key} stacked means (B, T, K, D) |
required |
targets
|
dict[str, Tensor]
|
Dictionary with gripper targets. |
required |
is_pad
|
Tensor | None
|
Optional padding mask (B, T). |
None
|
Returns:
| Type | Description |
|---|---|
LossOutput
|
LossOutput with gripper NLL. |