Mixins
RebinMixin
hypergrid.mixin.rebin_mixin.RebinMixin
Project the histogram onto a new grid by mapping each bin's centroid.
Source code in hypergrid\mixin\rebin_mixin.py
rebin_to(target_edges, *, as_storage=None)
Reproject mass onto target_edges by mapping each source bin's centre to the nearest target bin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_edges
|
list of ndarray
|
|
required |
as_storage
|
storage backend
|
If provided, also accumulate results into this backend. Useful when rebinning into an existing grid in-place. |
None
|
Returns:
| Type | Description |
|---|---|
dict {tuple_index: float}
|
Mass in target-grid coordinates. |
Source code in hypergrid\mixin\rebin_mixin.py
ComparisonMixin
hypergrid.mixin.comparison_mixin.ComparisonMixin
Statistical divergence metrics between two hypergrids.
Source code in hypergrid\mixin\comparison_mixin.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
compare(other, method='js', align='union', normalize=True)
Compute a scalar distance between self and other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
hypergrid
|
|
required |
method
|
(l1, kl, js, wasserstein)
|
l1 — total variation distance kl — Kullback-Leibler divergence (asymmetric) js — Jensen-Shannon divergence (symmetric, bounded in [0,1]) wasserstein — Earth Mover's Distance via linear programming |
"l1"
|
align
|
(union, self)
|
union — merge both edge sets before comparing (recommended) self — project other onto self's edges |
"union"
|
normalize
|
bool
|
Compare probability densities (True) or raw counts (False). |
True
|
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in hypergrid\mixin\comparison_mixin.py
EmbeddingMixin
hypergrid.mixin.embedding_mixin.EmbeddingMixin
Convert hypergrid mass to a flat, index-ordered probability vector.
Source code in hypergrid\mixin\embedding_mixin.py
to_vector()
Flatten the histogram into a 1D probability vector ordered by ravel_multi_index, so two grids with the same edges produce directly comparable vectors.
Returns:
| Type | Description |
|---|---|
ndarray, shape (prod(shape),) — sums to ~1.
|
|
Source code in hypergrid\mixin\embedding_mixin.py
VisualizationMixin
hypergrid.mixin.visualization_mixin.VisualizationMixin
Plotting methods for single-grid inspection and pairwise comparison.
Source code in hypergrid\mixin\visualization_mixin.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
sample(n_samples=2000, rng=None)
Draw samples from the histogram by treating each bin as a uniform distribution over its volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
|
2000
|
rng
|
Generator
|
|
None
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(n_samples, dim))
|
|
Source code in hypergrid\mixin\visualization_mixin.py
plot_umap(n_samples=2000, ax=None, **umap_kwargs)
UMAP projection of a single hypergrid.
Source code in hypergrid\mixin\visualization_mixin.py
compare_umap(other, n_samples=2000, **umap_kwargs)
UMAP projection with both grids overlaid in different colours.
Source code in hypergrid\mixin\visualization_mixin.py
compare_marginal(other, dim, ax=None, rebin=True)
Overlay marginal distributions for dimension dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
hypergrid
|
|
required |
dim
|
int
|
|
required |
ax
|
matplotlib Axes
|
|
None
|
rebin
|
bool
|
If True (default), project |
True
|
Source code in hypergrid\mixin\visualization_mixin.py
StatsMixin
hypergrid.mixin.stats_mixin.StatsMixin
Summary statistics computed from the histogram's marginal distributions.
Source code in hypergrid\mixin\stats_mixin.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
describe(percentiles=None)
Summary statistics of each dimension computed from the binned histogram.
Statistics are derived from the marginal distribution along each dimension (all other dimensions summed out). They reflect the binned representation, not the original raw data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percentiles
|
list of float
|
Quantile positions to include, each in [0, 1]. Default is [0.25, 0.50, 0.75]. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Rows: count, mean, std, skewness, kurtosis, min, |
Notes
Requires pandas (pip install pandas).
- count — total mass (sum of all bin counts, equal across dimensions).
- mean / std — probability-weighted mean and population std of bin centres.
- skewness — third standardised central moment (0 for symmetric distributions).
- kurtosis — fourth standardised central moment minus 3 (excess kurtosis; 0 for a normal distribution).
- min / max — lower / upper edge of the outermost non-empty bin.
- percentiles — linearly interpolated within bins from the marginal CDF.
Source code in hypergrid\mixin\stats_mixin.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |