capturegraph.scheduling.void_and_cluster
#
Void & Cluster Scheduling Algorithm#
A generic implementation of the Void & Cluster importance sampling algorithm. This module selects a subset of candidate items that maximize diversity relative to a set of existing items, using a user-provided distance metric.
select_sessions(potential_sessions, previous_sessions, distance_fn, energy_fn=gaussian(sigma=1), energy_mode='sum', selections=10)
#
Select sessions using Void & Cluster importance sampling.
The algorithm iteratively selects points that maximize diversity: 1. Find the "void" (point with lowest energy from existing/selected points). 2. Add it to the selection. 3. Find the "cluster" (point with highest energy, i.e., too similar). 4. Remove the cluster if different from the void. 5. Repeat until desired count is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential_sessions
|
List[Dict[Any]]
|
List of candidate sessions to select from. Each session must have attributes compatible with the distance_fn. |
required |
previous_sessions
|
List[Dict[Any]]
|
List of already-captured sessions. New selections will be spread away from these. |
required |
distance_fn
|
Callable[[Dict[Any], Dict[Any]], float]
|
Function |
required |
energy_fn
|
Callable[[float], float]
|
Function |
gaussian(sigma=1)
|
energy_mode
|
str
|
How to combine energies from multiple sources. - "sum": Total energy is sum of all contributions. - "max": Total energy is maximum contribution. |
'sum'
|
selections
|
int
|
Number of sessions to select. |
10
|
Returns:
| Type | Description |
|---|---|
List[Dict[Any]]
|
List of selected session Dicts from potential_sessions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If energy_mode is not "sum" or "max". |
Source code in capturegraph-lib/capturegraph/scheduling/void_and_cluster.py
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 | |