void_and_cluster
void_and_cluster
#
Void & cluster sampling for distribution-aware session selection.
Select a subset of candidate items that maximize diversity relative to a set of existing items, using a user-provided distance metric. Adapted from the Void & Cluster dithering algorithm: each iteration adds the candidate with the lowest energy — the largest "void" — given the existing sessions and the selections made so far, then releases the tightest selected point (the "cluster") unless the set has stabilized, allowing earlier picks that became crowded to be re-placed.
select_sessions(potential_sessions, previous_sessions, distance_fn, energy_fn=_DEFAULT_ENERGY_FN, energy_mode='sum', selections=10)
#
Select diverse sessions with a Void & Cluster sampler.
Each iteration fills the largest "void": it computes every unselected
candidate's energy — its similarity to the previous sessions plus the
selections made so far — and selects the candidate with the lowest
energy. It then finds the tightest "cluster" — the selected point with
the highest energy — and, unless that is the point just added (a stable
set), releases it so a later iteration can place it in a better void.
This relaxation lets late picks evict early picks that became crowded.
The first pick is the candidate least covered by previous_sessions;
with no previous sessions it is uniformly random. Total removals are
bounded by len(potential_sessions) to guarantee termination.
Energy functions are applied to whole numpy distance matrices, so
custom energy_fn callables must be numpy-vectorized. Ties are broken
with the global numpy RNG; seed np.random for reproducibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential_sessions
|
Array
|
Candidate sessions to select from. A candidate the metric cannot compare — every dimension missing — is never offered. |
required |
previous_sessions
|
Array
|
Already-captured sessions. New selections are spread away from these; one the metric cannot compare covers nothing. |
required |
distance_fn
|
Callable[[Any, Any], float]
|
Statistical distance between two sessions. A
|
required |
energy_fn
|
Callable[[ndarray], ndarray]
|
Converts distance to coverage energy. Default is Gaussian with sigma=1. |
_DEFAULT_ENERGY_FN
|
energy_mode
|
str
|
How to combine energies from multiple sources. - "sum": Total energy is the sum of all contributions. - "max": Total energy is the largest contribution. |
'sum'
|
selections
|
int
|
Number of sessions to select. Clamped to the number of comparable candidates. |
10
|
Returns:
| Type | Description |
|---|---|
Array
|
Array of selected sessions, in |
Array
|
(not selection order). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If energy_mode is not "sum" or "max". |
Source code in capturegraph-lib/capturegraph/scheduling/void_and_cluster.py
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 | |