Utilities#
Utility functions for BAM Engine.
This module provides common utility functions used throughout BAM Engine, including statistical operations (trimmed means), random sampling utilities, efficient array operations, and batch market matching primitives.
Constants#
- EPSfloat
Machine epsilon for numerical comparisons (1.0e-9). Used to avoid division by zero and detect near-zero values.
Functions#
- trim_mean
Calculate two-sided trimmed mean (SciPy-style).
- trimmed_weighted_mean
Calculate weighted trimmed mean with optional weight filtering.
- sample_beta_with_mean
Draw samples from Beta distribution with specified mean.
- select_top_k_indices_sorted
Efficiently select and sort top-k elements using argpartition.
- grouped_cumsum
Per-group prefix sums via the subtract-offset trick.
- resolve_conflicts
Batch conflict resolution for oversubscribed targets.
See also
bamengine.typingType aliases used in this module
scipy.stats.trim_meanSciPy implementation of trimmed mean
Notes
Trimmed means are robust statistics that exclude extreme values
Beta sampling is used for initialization with controlled variance
Top-k selection uses argpartition for O(n) performance vs O(n log n) for sort
grouped_cumsum and resolve_conflicts underpin vectorized market matching
Helper functions and utilities for BAM Engine.
Random Number Generation#
Create a new random number generator. |
Constants#
- bamengine.utils.EPS#
Machine epsilon for numerical comparisons (1.0e-9).
Statistical Functions#
Calculate two-sided trimmed mean (robust statistic). |
|
Calculate trimmed weighted mean with optional weight filtering. |
Sampling Functions#
Draw n samples from a Beta distribution scaled to [low, high), such that the scaled mean is approximately ``mean``. |
Array Operations#
Returns indices of k smallest/largest elements, sorted along the last axis. |