kups.core.parameter_scheduler
¶
Adaptive parameter scheduling based on acceptance rates.
This module implements automatic parameter adjustment for Monte Carlo simulations, dynamically tuning parameters (e.g., step sizes, temperatures) to maintain target acceptance rates.
Key components:
- ParameterSchedulerState: State containing the scheduled parameter value, configuration, and history.
- acceptance_target_schedule: Schedule function that adjusts values based on acceptance rates.
Example
AcceptanceHistory
¶
Circular buffer for tracking acceptance rates over time.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
Array
|
Array of shape |
index |
Array
|
Current write position in the circular buffer for each system |
Source code in src/kups/core/parameter_scheduler.py
Correlation
¶
Bases: Enum
Defines how parameters correlate with acceptance rates.
Attributes:
| Name | Type | Description |
|---|---|---|
POSITIVE |
Parameter increases lead to higher acceptance (e.g., temperature) |
|
NEGATIVE |
Parameter increases lead to lower acceptance (e.g., step size) |
Source code in src/kups/core/parameter_scheduler.py
ParameterSchedulerState
¶
State for parameter scheduling algorithm.
Contains both the parameter value being scheduled and the configuration for the scheduling algorithm.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
Array
|
The parameter value being scheduled (e.g., step size, temperature) |
multiplicity |
Array
|
Factor by which to multiply/divide parameter on adjustment |
target |
Array
|
Target acceptance rate to achieve (typically 0.2-0.5 for MC) |
tolerance |
Array
|
Acceptance within ±tolerance of target won't trigger adjustment |
correlation |
Correlation
|
How parameter correlates with acceptance rate |
bounds |
tuple[Array | None, Array | None]
|
Optional (min, max) bounds to clip parameter values |
history |
AcceptanceHistory
|
Circular buffer tracking recent acceptance rates |
Example
state = ParameterSchedulerState(
value=jnp.array([0.1, 0.2]), # Step sizes for 2 systems
multiplicity=jnp.array([1.5, 1.5]),
target=jnp.array([0.4, 0.4]),
tolerance=jnp.array([0.05, 0.05]),
correlation=Correlation.NEGATIVE,
bounds=(jnp.array([0.01, 0.01]), jnp.array([1.0, 1.0])),
history=AcceptanceHistory(
values=jnp.zeros((2, 10)),
index=jnp.array([0, 0]),
),
)
Source code in src/kups/core/parameter_scheduler.py
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 | |
create(n_systems=1, initial_value=0.1, multiplicity=1.1, target=0.5, tolerance=0.05, correlation=Correlation.NEGATIVE, lower_bound=0.0, upper_bound=None, history_length=100)
classmethod
¶
Create a ParameterSchedulerState with sensible defaults for ~50 % acceptance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_systems
|
int
|
Number of independent simulation systems. |
1
|
initial_value
|
float
|
Starting parameter value (e.g. step size). |
0.1
|
multiplicity
|
float
|
Multiplicative adjustment factor applied each scheduling cycle; must be > 1. Smaller values (e.g. 1.1) give finer adaptation; larger values (e.g. 2.0) give faster adaptation. |
1.1
|
target
|
float
|
Target acceptance rate in |
0.5
|
tolerance
|
float
|
Half-width of the dead-band around |
0.05
|
correlation
|
Correlation
|
Whether the parameter correlates positively or negatively with acceptance. Step sizes use Correlation.NEGATIVE (larger step → lower acceptance). |
NEGATIVE
|
lower_bound
|
float
|
Minimum allowed parameter value (inclusive). Set to
|
0.0
|
upper_bound
|
float | None
|
Maximum allowed parameter value (inclusive), or
|
None
|
history_length
|
int
|
Number of recent MC moves recorded in the circular acceptance-history buffer. The scheduler updates the parameter once per complete buffer cycle. |
100
|
Returns:
| Type | Description |
|---|---|
ParameterSchedulerState
|
Initialised ParameterSchedulerState. |
Source code in src/kups/core/parameter_scheduler.py
acceptance_target_schedule(input, current)
¶
Adjust parameter values to achieve target acceptance rate.
Implements multiplicative adjustment based on acceptance history: tracks acceptance over a rolling window, compares average to target, and adjusts multiplicatively based on correlation direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Array
|
Boolean/float array of shape |
required |
current
|
ParameterSchedulerState
|
Current scheduler state containing value and history. |
required |
Returns:
| Type | Description |
|---|---|
ParameterSchedulerState
|
Updated scheduler state with adjusted value and updated history. |