DHB-DR Encoding
dhb_dr
DHB-DR encoder: double-reflection (RMF) frame transport with Euler XYZ relative rotations. Quaternion convention: wxyz (scalar-first).
Robustness features (enabled via robust_mode=True): - 180-degree reversal detection and RMF fallback - Zero-motion segment handling with frame preservation - Frame validation to detect degenerate states - Configurable thresholds for edge case detection
Classes
EncodingDiagnostics
dataclass
Diagnostics from robust encoding.
Source code in src/dhb_xr/encoder/dhb_dr.py
Functions
encode_dhb_dr
encode_dhb_dr(
positions,
quaternions,
init_pose=None,
method="pos",
use_default_initial_frames=True,
dhb_method=DHBMethod.DOUBLE_REFLECTION,
robust_mode=False,
reversal_threshold=-0.9,
zero_motion_threshold=1e-06,
validate_frames=False,
return_diagnostics=False,
)
Compute DHB invariants (original or double-reflection).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
(N, 3) position trajectory |
required |
quaternions
|
ndarray
|
(N, 4) wxyz quaternion trajectory |
required |
init_pose
|
Optional[Dict[str, ndarray]]
|
optional {'position': (3,), 'quaternion': (4,) wxyz} |
None
|
method
|
str
|
EncodingMethod for position or velocity-based encoding |
'pos'
|
use_default_initial_frames
|
bool
|
if True, pad and use identity-like frames |
True
|
dhb_method
|
DHBMethod
|
DHBMethod.ORIGINAL (3 inv) or DHBMethod.DOUBLE_REFLECTION (4 inv) |
DOUBLE_REFLECTION
|
robust_mode
|
bool
|
Enable robustness features (reversal detection, zero-motion handling) |
False
|
reversal_threshold
|
float
|
Dot product threshold for 180° detection (default -0.9) |
-0.9
|
zero_motion_threshold
|
float
|
Threshold for zero-motion detection |
1e-06
|
validate_frames
|
bool
|
Check frame orthogonality at each step |
False
|
return_diagnostics
|
bool
|
Include encoding diagnostics in output |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
dict with linear_motion_invariants, angular_motion_invariants, |
Dict[str, Any]
|
linear_frame_initial, angular_frame_initial, initial_pose, |
Dict[str, Any]
|
and optionally 'diagnostics' if return_diagnostics=True. |
Source code in src/dhb_xr/encoder/dhb_dr.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
Main Functions
encode_dhb_dr
def encode_dhb_dr(
positions: np.ndarray,
quaternions: np.ndarray,
init_pose: Optional[Dict[str, np.ndarray]] = None,
method: EncodingMethod = EncodingMethod.POSITION,
use_default_initial_frames: bool = True,
dhb_method: DHBMethod = DHBMethod.DOUBLE_REFLECTION,
robust_mode: bool = False,
reversal_threshold: float = -0.9,
zero_motion_threshold: float = 1e-6,
validate_frames: bool = False,
return_diagnostics: bool = False,
) -> Dict[str, Any]:
Encode trajectory to DHB-DR (Double-Reflection) invariants.
Parameters:
positions: Trajectory positions (N, 3) arrayquaternions: Trajectory quaternions (N, 4) array in wxyz formatinit_pose: Optional initial pose overridemethod: Initial frame computation methoduse_default_initial_frames: Use default frame initializationdhb_method: DHB variant (DOUBLE_REFLECTION or ORIGINAL)robust_mode: Enable robustness featuresreversal_threshold: Threshold for reversal detectionzero_motion_threshold: Threshold for zero-motion detectionvalidate_frames: Validate frame orthonormalityreturn_diagnostics: Return diagnostic information
Returns:
Dictionary containing:
- linear_motion_invariants: Linear motion invariants (M, 4) or (M, 3)
- angular_motion_invariants: Angular motion invariants (M, 4) or (M, 3)
- initial_pose: Initial pose used for encoding
- Optional diagnostics if return_diagnostics=True
Usage Example
import numpy as np
from dhb_xr.encoder.dhb_dr import encode_dhb_dr
from dhb_xr.core.types import DHBMethod, EncodingMethod
# Create trajectory data
positions = np.random.randn(100, 3) * 0.01
positions = np.cumsum(positions, axis=0)
quaternions = np.tile([1, 0, 0, 0], (100, 1))
# Encode to invariants
result = encode_dhb_dr(
positions,
quaternions,
method=EncodingMethod.POSITION,
dhb_method=DHBMethod.DOUBLE_REFLECTION,
robust_mode=True
)
print(f"Linear invariants shape: {result['linear_motion_invariants'].shape}")
print(f"Angular invariants shape: {result['angular_motion_invariants'].shape}")