Agents
Configs and factory:
banditry.agents.factory
Declarative agent configuration and the build_agent factory.
This module is the main entry point of banditry: pick a config dataclass
(OFUGPConfig for GP-UCB / optimism-in-the-face-of-uncertainty agents,
TSConfig for Thompson-sampling agents), fill in its fields, and pass it to
build_agent together with a DesignSpace to obtain a ready-to-use agent that
drives the suggest -> evaluate -> observe loop.
Sampler behaviour for Thompson-sampling agents is controlled through
TSConfig.sampler_config; the defaults live in DEFAULT_NUTS_CONFIG and
DEFAULT_LANGEVIN_CONFIG and can be copied and overridden key by key.
DEFAULT_NUTS_CONFIG = {'num_samples': 16, 'warmup_steps': 64, 'target_accept_prob': 0.6, 'prior_std': 0.5, 'obs_noise_prior_loc': -3.0, 'obs_noise_prior_scale': 0.5, 'max_obs_noise': 1.0, 'max_tree_depth': 6, 'disable_progbar': False}
module-attribute
Default TSConfig.sampler_config for sampler="nuts".
The dict is splatted into the NUTSSampler constructor (NUTSSampler(**sampler_config)), so any
constructor keyword argument is a valid key. Keys set here:
num_samples(16): posterior draws kept after warmup; one draw is then selected uniformly at random as the sampled value function.warmup_steps(64): NUTS adaptation iterations, discarded before sampling.target_accept_prob(0.6): target acceptance probability for NUTS step-size adaptation.prior_std(0.5): standard deviation of the zero-mean Gaussian prior placed on every network weight.obs_noise_prior_loc(-3.0): location of the prior over the observation-noise std, interpreted in log-noise space (clamped to[log(min_obs_noise), log(max_obs_noise)]).obs_noise_prior_scale(0.5): scale of that prior in the unconstrained (pre-sigmoid) parameterisation of the noise.max_obs_noise(1.0): upper bound of the observation-noise std (the noise is a sigmoid-squashed parameter living in[min_obs_noise, max_obs_noise]).max_tree_depth(6): maximum doubling depth of the NUTS trajectory tree.disable_progbar(False): show Pyro's MCMC progress bar (the constructor default hides it).
Other accepted keys include adapt_step_size, adapt_mass_matrix, use_multinomial_sampling,
init_obs_noise, min_obs_noise, jit_compile, ignore_jit_warnings, and generator.
DEFAULT_LANGEVIN_CONFIG = {'batch_size': 512, 'num_epochs': 128, 'burn_in': 64, 'temperature': 0.2, 'step_size': welling_teh_schedule(a=0.005, b=1.0, gamma=0.55, lr_floor=0.001), 'max_obs_noise': 10.0, 'precondition': True}
module-attribute
Default TSConfig.sampler_config for sampler="langevin".
The dict is splatted into the LangevinSampler constructor (LangevinSampler(**sampler_config)), so
any constructor keyword argument is a valid key. Keys set here:
batch_size(512): SGLD minibatch size (capped at the dataset size).num_epochs(128): passes over the data; the total number of updates is at leastburn_in + 1epochs andmin_batchesupdates, whichever is larger.burn_in(64): epochs discarded before a post-burn-in state is reservoir-sampled uniformly as the posterior draw.temperature(0.2): SGLD noise temperature;1.0targets the exact posterior, smaller values sample a colder (sharper) posterior.step_size: constant float or callable schedule(t, n_burn_in) -> lr; here a Welling-Teh polynomial decaya * (b + t) ** -gammathat is frozen after burn-in and floored atlr_floor.max_obs_noise(10.0): upper clamp of the learned observation-noise std.precondition(True): apply RMSProp-style diagonal preconditioning to the SGLD updates.
Other accepted keys include prior_precision, precond_alpha, precond_eps, min_batches,
init_obs_noise, min_obs_noise, and generator.
AgentConfig(rand_sample=4)
dataclass
Base configuration shared by every agent built by build_agent.
Concrete agents are configured through the subclasses OFUGPConfig and
TSConfig; passing a plain AgentConfig to build_agent raises
TypeError.
rand_sample = 4
class-attribute
instance-attribute
Number of quasi-random (scrambled Sobol) warmup suggestions served before the agent switches to
model-based suggestions. Values below 2 are floored to 2 by the agent. Default: 4.
OFUGPConfig(rand_sample=4, surrogate='svgp', frequentist=False, rkhs_norm=None, noise_std_proxy=None, model_config_overrides=dict())
dataclass
Bases: AgentConfig
Configuration for the GP-UCB / optimism-in-the-face-of-uncertainty agent (OFUGPAgent).
Although noise_std_proxy defaults to None (to keep the dataclass
keyword-friendly), it is effectively required: build_agent forwards it to
OFUGPAgent, whose constructor raises ValueError when it is None.
surrogate = 'svgp'
class-attribute
instance-attribute
Surrogate model family: "gp" (exact Gaussian process; accurate but cubic in the number of
observations) or "svgp" (sparse variational GP; inducing-point approximation that scales to larger
datasets). Must be a ModelEnum member name. Default: "svgp".
frequentist = False
class-attribute
instance-attribute
If True, use the frequentist Chowdhury-Gopalan (2017) confidence width beta_t (requires
rkhs_norm) instead of the default Bayesian GP-UCB width. Default: False.
rkhs_norm = None
class-attribute
instance-attribute
Bound B on the RKHS norm of the reward function, used by the frequentist beta_t. Required
when frequentist=True (the agent raises ValueError at suggestion time otherwise); ignored in the
Bayesian setting. Default: None.
noise_std_proxy = None
class-attribute
instance-attribute
Sub-Gaussian / GP observation-noise scale R. Effectively required: building an OFU-GP agent
raises ValueError if this is left as None. Used by the frequentist beta_t and by the realised
information gain accumulated on every observe. Default: None.
model_config_overrides = field(default_factory=dict)
class-attribute
instance-attribute
Overrides merged on top of the per-surrogate default model config (see ModelEnum.model_config)
and passed through to the surrogate constructor. Default: {}.
TSConfig(rand_sample=4, sampler='nuts', feel_good=False, fg_lambda=1.0, fg_bound=1.0, model_config=dict(), sampler_config=None, should_warm_start=True, latent_dimension=None)
dataclass
Bases: AgentConfig
Configuration for the Thompson-sampling agent (TSAgent).
sampler = 'nuts'
class-attribute
instance-attribute
Posterior-sampling oracle for the value-function weights: "nuts" (Pyro NUTS; requires the
optional banditry[nuts] extra) or "langevin" (SGLD; no extra dependencies).
Default: "nuts".
feel_good = False
class-attribute
instance-attribute
If True, enable Feel-Good Thompson sampling (Zhang, 2021): the Gaussian likelihood is reweighted
with an exploration-boosting term built from fg_lambda and fg_bound. Default: False.
fg_lambda = 1.0
class-attribute
instance-attribute
Strength lambda of the Feel-Good reweighting term (only used when feel_good=True); 0
disables the term. Default: 1.0.
fg_bound = 1.0
class-attribute
instance-attribute
Upper truncation of the Feel-Good optimistic-value term (the cap b in min(b, f*)); must be
non-negative. Only used when feel_good=True. Default: 1.0.
model_config = field(default_factory=dict)
class-attribute
instance-attribute
Keyword arguments forwarded to the neural ValueFunction surrogate (e.g. num_uniqs,
emb_sizes, a custom feature extractor fe). num_uniqs is filled in automatically for spaces
with categorical parameters. Default: {}.
sampler_config = None
class-attribute
instance-attribute
Keyword arguments splatted into the sampler constructor (NUTSSampler(**sampler_config) or
LangevinSampler(**sampler_config)), so any constructor kwarg is a valid key. None (default)
selects DEFAULT_NUTS_CONFIG or DEFAULT_LANGEVIN_CONFIG according to sampler. An explicit dict
replaces the default rather than being merged into it, so copy the default and override keys.
should_warm_start = True
class-attribute
instance-attribute
If True (default), initialise each round's MCMC run from the previous round's sampled model
instead of a freshly initialised network.
latent_dimension = None
class-attribute
instance-attribute
Latent dimension of the sampled parameter vector, recorded for labelling/diagnostics. None
(default) resolves to TSAgent.num_samplable_params() at build time.
build_agent(config, space)
Build a ready-to-use agent from a declarative config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AgentConfig
|
An |
required |
space
|
DesignSpace
|
The design space the agent optimises over. |
required |
Returns:
| Type | Description |
|---|---|
AbstractAgent
|
A fully constructed |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
KeyError
|
If |
ImportError
|
If |
Example
Build an OFU-GP agent on a two-parameter space and run one round:
import numpy as np
from banditry import DesignSpace, OFUGPConfig, build_agent
space = DesignSpace.parse([
{"name": "x0", "type": "num", "lb": -1, "ub": 1},
{"name": "x1", "type": "num", "lb": -1, "ub": 1},
])
agent = build_agent(OFUGPConfig(rand_sample=4, surrogate="gp", noise_std_proxy=1.0), space)
rec = agent.suggest(1) # DataFrame of suggestions
y = ((rec["x0"] - 0.3) ** 2 + (rec["x1"] + 0.2) ** 2).to_numpy()
agent.observe(rec, y) # agents minimise y
Source code in src/banditry/agents/factory.py
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
The agent contract:
banditry.agents.agent.AbstractAgent(space, rand_sample=None)
Bases: ABC
Base class for bandit agents driving a suggest -> evaluate -> observe loop.
Usage contract:
- Call
suggestto obtain a batch of candidate configurations (a DataFrame with one column per parameter of the design space), evaluate them externally, then feed the results back withobserve. Repeat. - The library minimises the observed values
y; negate rewards if you need maximisation. - The first
rand_samplesuggestions are quasi-random (scrambled Sobol) warmup draws; once at leastrand_sampleobservations have been recorded, suggestions come from the subclass's model (get_model+pick_action). fix_inputturns the loop into a contextual bandit: any subset of parameters can be pinned to observed context values each round, and the remaining parameters are optimised conditionally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
DesignSpace
|
The design space to optimise over. |
required |
rand_sample
|
int | None
|
Sobol warmup budget. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
space |
The design space being optimised. |
|
X |
DataFrame of all observed inputs, one column per parameter. |
|
y |
|
|
rand_sample |
Resolved warmup budget (see above). |
|
support_parallel_opt |
Whether the agent supports |
|
support_constraint |
Whether constrained optimisation is supported. |
|
support_multi_objective |
Whether multi-objective observations are supported. |
|
support_combinatorial |
Whether categorical/integer parameters are supported. |
|
support_contextual |
Whether |
Source code in src/banditry/agents/agent.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
observe(X, y)
Record evaluated suggestions in the agent's history.
Rows whose y is non-finite (NaN or infinite) are dropped; the
remaining rows are appended to X and y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Evaluated inputs, one column per parameter (as returned by |
required |
y
|
ndarray
|
Observed objective values, one per row of |
required |
Source code in src/banditry/agents/agent.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
quasi_sample(n, fix_input=None)
Draw quasi-random samples from the design space.
Samples come from a scrambled Sobol sequence in the transformed space and are mapped back to the original parameter domain; numeric parameters that are discrete after transformation are rounded. Used for warmup rounds and to pad incomplete suggestion batches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of samples to draw. |
required |
fix_input
|
dict[str, Any] | None
|
Optional mapping of parameter name to pinned value; the corresponding columns are overwritten after sampling. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with |
DataFrame
|
original (untransformed) domain. |
Source code in src/banditry/agents/agent.py
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 | |
get_best_id(fix_input=None)
Return the positional index of the best (lowest-y) observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fix_input
|
dict[str, Any] | None
|
Optional context filter. When given, only observations whose pinned columns match the given values are considered (fully numeric columns are compared with a tight absolute tolerance, other columns by equality). If no row matches, the method falls back to the global argmin. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Positional index into |
Source code in src/banditry/agents/agent.py
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 | |
check_unique(rec)
Flag which rows of rec are new.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rec
|
DataFrame
|
Candidate suggestions to check. |
required |
Returns:
| Type | Description |
|---|---|
list[bool]
|
One boolean per row of |
list[bool]
|
neither a past observation nor an earlier row of |
Source code in src/banditry/agents/agent.py
159 160 161 162 163 164 165 166 167 168 169 | |
prepare_data()
Transform the observation history into model-ready tensors.
Returns:
| Type | Description |
|---|---|
|
Tuple |
|
|
categorical features, and a float tensor copy of the observed values. |
Source code in src/banditry/agents/agent.py
186 187 188 189 190 191 192 193 194 195 | |
get_model(Xc, Xe, y)
abstractmethod
Build the decision model from transformed data.
Subclasses must fit (or posterior-sample) their surrogate here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Xc
|
Transformed numeric features. |
required | |
Xe
|
Transformed categorical features. |
required | |
y
|
Observed values as a float tensor. |
required |
Returns:
| Type | Description |
|---|---|
|
A model consumable by |
Source code in src/banditry/agents/agent.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
pick_action(model, fix_input, n_suggestions=1)
abstractmethod
Choose the next suggestions given a fitted or sampled model.
Subclasses must optimise their acquisition here, honouring fix_input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The model returned by |
required | |
fix_input
|
Mapping of parameter name to pinned context value (may be empty). |
required | |
n_suggestions
|
Number of suggestions to return. |
1
|
Returns:
| Type | Description |
|---|---|
|
DataFrame of |
Source code in src/banditry/agents/agent.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
suggest(n_suggestions=1, fix_input=None)
Propose the next configurations to evaluate.
While fewer than rand_sample observations have been recorded, this
returns quasi-random Sobol samples; afterwards it fits or samples the
model (get_model) and optimises the acquisition (pick_action).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_suggestions
|
int
|
Number of configurations to return. |
1
|
fix_input
|
dict[str, Any] | None
|
Optional context — parameter values to pin this round (contextual bandit). |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with |
Source code in src/banditry/agents/agent.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
n_plays()
Return the number of observations recorded so far.
Source code in src/banditry/agents/agent.py
254 255 256 | |
Agent implementations:
banditry.agents.ofugpagent
GP-UCB / optimism-in-the-face-of-uncertainty agent and its surrogate registry.
ModelEnum
Bases: Enum
GP surrogate registry for OFUGPAgent.
Members map surrogate names to classes: gp is an exact Gaussian
process (accurate, but cubic cost in the number of observations) and
svgp is a sparse variational GP (inducing-point approximation that
scales to larger datasets). model_config builds the per-surrogate
default configuration.
model_config(space, configs_to_override=None)
Build the default constructor config for this surrogate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
DesignSpace
|
Design space (used to derive categorical cardinalities). |
required |
configs_to_override
|
Optional overrides merged on top of the defaults. |
None
|
Returns:
| Type | Description |
|---|---|
|
Keyword-argument dict for the surrogate class constructor. For |
|
|
|
|
|
|
|
|
|
|
|
|
Source code in src/banditry/agents/ofugpagent.py
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 | |
OFUGPAgent(space, noise_std_proxy, surrogate=ModelEnum.svgp, rand_sample=None, acq_cls=LCB, model_config=None, frequentist=False, delta=0.01, kappa_fn=None, rkhs_norm=None)
Bases: AbstractAgent
Optimism-in-the-face-of-uncertainty (GP-UCB) agent.
Fits a GP surrogate to the observations and suggests the minimiser of a
lower-confidence-bound acquisition mu - kappa * sigma (or of the MACE
multi-objective ensemble), optimised with an evolutionary optimiser over
the design space, with context parameters pinned via fix_input.
The confidence multiplier kappa is Bayesian by default; with
frequentist=True it becomes the Chowdhury-Gopalan (2017, "On
Kernelized Multi-armed Bandits") beta_t, which requires the RKHS-norm
bound B (rkhs_norm) and the sub-Gaussian noise scale R
(noise_std_proxy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
DesignSpace
|
The design space to optimise over. |
required |
noise_std_proxy
|
float
|
Sub-Gaussian / GP observation-noise scale |
required |
surrogate
|
|
svgp
|
|
rand_sample
|
Sobol warmup budget; see |
None
|
|
acq_cls
|
Acquisition class — |
LCB
|
|
model_config
|
Overrides merged into the surrogate's default config
(see |
None
|
|
frequentist
|
bool
|
Use the Chowdhury-Gopalan |
False
|
delta
|
Confidence level |
0.01
|
|
kappa_fn
|
Callable[[OFUGPAgent, int], float] | None
|
Optional callable |
None
|
rkhs_norm
|
RKHS-norm bound |
None
|
Source code in src/banditry/agents/ofugpagent.py
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 | |
get_model(X, Xe, y)
Instantiate the configured GP surrogate and fit it to the data.
Source code in src/banditry/agents/ofugpagent.py
144 145 146 147 148 149 150 151 152 153 | |
kappa(n_suggestions)
Confidence multiplier for the LCB acquisition mu - kappa * sigma.
If a kappa_fn override was supplied, it is delegated to. Otherwise,
with t = max(1, n_plays() // n_suggestions) rounds played and input
dimension d:
- Bayesian (default):
beta_t = (2 + d/2) * ln(t) + ln(pi^2 / delta)andsqrt(beta_t)is returned. - Frequentist (
frequentist=True): the Chowdhury-Gopalan widthbeta_t = B + 4 * R * sqrt(gamma_t + 1 + ln(1/delta)), wheregamma_tis the realised information gain accumulated acrossobservecalls; returned as is (already on the sqrt scale).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_suggestions
|
Batch size of the current round (scales the round counter). |
required |
Returns:
| Type | Description |
|---|---|
|
The multiplier applied to the predictive standard deviation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/banditry/agents/ofugpagent.py
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 | |
pick_action(model, fix_input, n_suggestions=1)
Optimise the acquisition and select n_suggestions candidates.
Runs an evolutionary optimiser seeded at the incumbent, pads with
quasi-random samples if needed, and — for batches larger than 2 —
reserves slots for the most uncertain and the best-predicted
candidates. The selected candidates' predictive variances are cached
for the information-gain update in observe.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Source code in src/banditry/agents/ofugpagent.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
observe(X, y)
Record observations and update the realised information gain.
Uses the predictive variances cached by pick_action when available
(otherwise refits the GP on the past data, falling back to the prior
variance on failure) to accumulate 0.5 * sum(log(1 + var / R^2)),
then delegates to AbstractAgent.observe.
Source code in src/banditry/agents/ofugpagent.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
banditry.agents.tsagent.TSAgent(space, rand_sample=None, model_config=None, sampler_cls=LangevinSampler, sampler_config=None, nll=None, should_warm_start=False, latent_dimension=None)
Bases: AbstractAgent
Thompson-sampling agent with a neural value function.
Each round, the weights of a neural ValueFunction are sampled from
their posterior by an MCMC sampling oracle (LangevinSampler / SGLD, or
NUTSSampler / Pyro NUTS), and the sampled network is minimised over
the design space with an evolutionary optimiser (context parameters pinned
via fix_input) — i.e. the agent plays the argmin of one posterior draw.
Optional Feel-Good Thompson sampling (Zhang, 2021, "Feel-Good Thompson
Sampling for Contextual Bandits and Reinforcement Learning") reweights the
likelihood with an exploration-boosting term; enable it by passing
nll=FeelGoodNLL(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
DesignSpace
|
The design space to optimise over. |
required |
rand_sample
|
Sobol warmup budget; see |
None
|
|
model_config
|
dict | None
|
Keyword arguments for the |
None
|
sampler_cls
|
type[Sampler]
|
Sampling-oracle class (default: |
LangevinSampler
|
sampler_config
|
dict | None
|
Keyword arguments splatted into |
None
|
nll
|
NLL | None
|
Optional |
None
|
should_warm_start
|
bool
|
If |
False
|
latent_dimension
|
float | None
|
Latent dimension of the sampled parameter vector,
recorded for labelling/diagnostics; |
None
|
Source code in src/banditry/agents/tsagent.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
get_model(Xc, Xe, y, nll=None)
Draw one posterior sample of the value function.
Starts from the previous round's sampled model when warm-starting is
enabled (and available), otherwise from a freshly initialised
ValueFunction, and runs the sampling oracle on the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Xc
|
Transformed numeric features. |
required | |
Xe
|
Transformed categorical features. |
required | |
y
|
Observed values as a float tensor. |
required | |
nll
|
Optional bound NLL callable overriding the Gaussian likelihood. |
None
|
Returns:
| Type | Description |
|---|---|
ValueFunction
|
The sampled |
Source code in src/banditry/agents/tsagent.py
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 | |
suggest(n_suggestions=1, fix_input=None)
Propose the next configurations to evaluate (see AbstractAgent.suggest).
Identical to the base implementation, except that the nll factory,
when present, is bound to the current context (fix_input) and the
observation history before posterior sampling.
Source code in src/banditry/agents/tsagent.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
pick_action(model, fix_input, n_suggestions=1)
Minimise the sampled value function over the design space.
Runs an evolutionary optimiser seeded at the incumbent, keeps the
final population, filters out already-observed rows, pads with
quasi-random samples if needed, and returns the top n_suggestions
rows.
Source code in src/banditry/agents/tsagent.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
num_samplable_params()
Count the ValueFunction parameters with requires_grad=True.
This is the exact set both LangevinSampler and NUTSSampler
iterate over. It is determined by architecture alone (network builder
+ feature extractor + scalers), so a throwaway ValueFunction
instance suffices to read it off. Cached after the first call.
Returns:
| Type | Description |
|---|---|
int
|
Total number of samplable scalar parameters. |
Source code in src/banditry/agents/tsagent.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |